Skip to content

Commit

Permalink
Merge pull request #291 from tue-robotics/fix/knowledge-for-spr
Browse files Browse the repository at this point in the history
Fix/knowledge for spr
  • Loading branch information
LoyVanBeek committed May 30, 2017
2 parents 30a11e0 + 15d47b8 commit 1e1ce68
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 58 deletions.
45 changes: 41 additions & 4 deletions challenge_spr/src/challenge_spr_states/riddle_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def answer(robot, res, crowd_data):
answer = 'In the crowd are %d girls' % crowd_data['girls']

# Location of placements or beacons
if action['action'] == 'a_find':
if action['action'] == 'find_placement':
entity = action['entity']
locations = [l for l in common_knowledge.locations if l['name'] == entity]
if len(locations) == 1:
Expand All @@ -76,7 +76,7 @@ def answer(robot, res, crowd_data):
answer = 'I dont know that object'

# Count placements or beacons in the room
if action['action'] == 'a_count':
if action['action'] == 'count_placement':
entity = action['entity']
locations = [l for l in common_knowledge.locations if l['name'] == entity]
if len(locations) == 1:
Expand All @@ -89,7 +89,7 @@ def answer(robot, res, crowd_data):
answer = 'I dont know that object'

# Find objects
if action['action'] == 'o_find':
if action['action'] == 'find_object':
entity = action['entity']
locations = [l for l in common_knowledge.objects if l['name'] == entity]
if len(locations) == 1:
Expand All @@ -102,7 +102,7 @@ def answer(robot, res, crowd_data):
answer = 'I dont know that object'

# Find category
if action['action'] == 'c_find':
if action['action'] == 'find_category':
entity = action['entity']
loc, area_name = common_knowledge.get_object_category_location(entity)
answer = 'You can find the %s on the %s' % (entity, loc)
Expand All @@ -118,6 +118,43 @@ def answer(robot, res, crowd_data):
else:
answer = 'I dont know that object'

# Return objects color
if action['action'] == 'return_color':
entity = action['entity']
locations = [l for l in common_knowledge.objects if l['name'] == entity]
if len(locations) == 1:
col = locations[0]['color']
answer = 'The color of %s is %s' % (entity, col)

else:
answer = 'I dont know that object'

# Compare objects categories
if action['action'] == 'compare_category':
entity_a = action['entity_a']
entity_b = action['entity_b']
locations_a = [l for l in common_knowledge.objects if l['name'] == entity_a]
locations_b = [l for l in common_knowledge.objects if l['name'] == entity_b]
if len(locations_a) == 1 & len(locations_b) == 1:
cat_a = locations_a[0]['category']
cat_b = locations_b[0]['category']
if cat_a == cat_b:
answer = 'Both objects belong to the same category %s' % (cat_a)
else:
answer = 'These objects belong to different categories'
else:
answer = 'I dont know these objects'

# Count how many objects belong to category
if action['action'] == 'count_object':
entity = action['entity']
objects_count = [l for l in common_knowledge.objects if l['category'] == entity]
if len(objects_count) > 0:
count = len(objects_count)
answer = 'The number of objects in category %s is %i' % (entity, count)
else:
answer = 'I dont know this category'

rospy.loginfo("Question was: '%s'?"%res.sentence)
robot.speech.speak("The answer is %s"%answer)
return 'answered'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
grammar += '''
SEARCH -> where is | in WHATWHICH room is
Q["action" : "a_find", "entity" : Y] -> SEARCH the PLACEMENTS_AND_BEACONS[Y]
Q["action" : "a_count", "entity" : Y, "location" : R] -> how many PLACEMENTS_AND_BEACONS[Y] are in the ROOMS[R]
Q["action" : "find_placement", "entity" : Y] -> SEARCH the PLACEMENTS_AND_BEACONS[Y]
Q["action" : "count_placement", "entity" : Y, "location" : R] -> how many PLACEMENTS_AND_BEACONS[Y] are in the ROOMS[R]
'''

##############################################################################
Expand All @@ -139,20 +139,18 @@
grammar += '''
ADJR -> smaller | bigger
Q["action" : "o_find", "entity" : O] -> where can i find DET OBJECT_NAMES[O]
Q["action" : "c_find", "entity" : C] -> where can i find DET OBJECT_CATEGORIES[C]
Q["action" : "find_object", "entity" : O] -> where can i find DET OBJECT_NAMES[O]
Q["action" : "find_category", "entity" : C] -> where can i find DET OBJECT_CATEGORIES[C]
Q["action" : "return_category", "entity" : O] -> to WHATWHICH category belong the OBJECT_NAMES[O]
Q["action" : "return_color", "entity" : O] -> whats the color of the OBJECT_NAMES[O]
Q["action" : "compare_category", "entity_a" : O, "entity_b" : A] -> do the OBJECT_NAMES[O] and OBJECT_NAMES[A] belong to the same category
Q["action" : "count_object", "entity" : C] -> how many OBJECT_CATEGORIES[C] there are
NQ["action" : "o_count", "entity" : C] -> how many OBJECT_CATEGORIES[C] there are
NQ["action" : "find_color", "entity" : O] -> whats the colour of the OBJECT_NAMES[O]
NQ["action" : "compare_category", "entity_a" : O, "entity_b" : A] -> do the OBJECT_NAMES[O] and OBJECT_NAMES[A] belong to the same category
NQ["action" : "o_count", "entity" : C, "location" : Y] -> how many OBJECT_CATEGORIES[C] are in the PLACEMENTS_AND_BEACONS[Y]
NQ["action" : "o_count", "entity" : O, "location" : Y] -> how many OBJECT_NAMES[O] are in the PLACEMENTS_AND_BEACONS[Y]
NQ["action" : "count_object", "entity" : C, "location" : Y] -> how many OBJECT_CATEGORIES[C] are in the PLACEMENTS_AND_BEACONS[Y]
NQ["action" : "count_object", "entity" : O, "location" : Y] -> how many OBJECT_NAMES[O] are in the PLACEMENTS_AND_BEACONS[Y]
NQ["action" : "category_at_loc", "location" : Y] -> what objects are stored in the PLACEMENTS_AND_BEACONS[Y]
NQ["action" : "compare", "entity_a" : O, "entity_b" : A] -> between the OBJECT_NAMES[O] and OBJECT_NAMES[A] WHATWHICH one is ADJR
NQ["action" : "compare", "entity_a" : O, "entity_b" : A] -> between the OBJECT_NAMES[O] and OBJECT_NAMES[A] which one is ADJR
'''

##############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,57 @@
rooms = location_rooms + ["workshop"]

objects = [
{'category': 'food', 'name': 'apple' },
{'category': 'food', 'name': 'bread' },
{'category': 'food', 'name': 'cereals' },
{'category': 'food', 'name': 'cornflakes' },
{'category': 'food', 'name': 'crackers' },
{'category': 'food', 'name': 'lemon' },
{'category': 'food', 'name': 'noodles' },
{'category': 'food', 'name': 'paprika' },
{'category': 'food', 'name': 'peas' },
{'category': 'food', 'name': 'pepper' },
{'category': 'food', 'name': 'potato' },
{'category': 'food', 'name': 'potato_soup' },
{'category': 'food', 'name': 'salt' },
{'category': 'food', 'name': 'tomato_pasta' },
{'category': 'container', 'name': 'bag' },
{'category': 'container', 'name': 'basket' },
{'category': 'container', 'name': 'coffecup' },
{'category': 'container', 'name': 'plate' },
{'category': 'container', 'name': 'red_bowl' },
{'category': 'container', 'name': 'white_bowl' },
{'category': 'drink', 'name': 'banana_milk' },
{'category': 'drink', 'name': 'cappucino' },
{'category': 'drink', 'name': 'coke' },
{'category': 'drink', 'name': 'orange_drink' },
{'category': 'drink', 'name': 'water' },
{'category': 'snack', 'name': 'chocolate_cookies' },
{'category': 'snack', 'name': 'egg' },
{'category': 'snack', 'name': 'party_cracker' },
{'category': 'snack', 'name': 'pringles' },
{'category': 'cleaning_stuff', 'name': 'cloth' },
{'category': 'cleaning_stuff', 'name': 'paper' },
{'category': 'cleaning_stuff', 'name': 'sponge' },
{'category': 'cleaning_stuff', 'name': 'towel' },
{'category': 'cutlery', 'name': 'fork' },
{'category': 'cutlery', 'name': 'spoon' },
{'category': 'cutlery', 'name': 'knife' }
{'category': 'food', 'name': 'apple', 'color': 'red'},
{'category': 'food', 'name': 'bread', 'color': 'brown'},
{'category': 'food', 'name': 'cereals', 'color': 'green'},
{'category': 'food', 'name': 'cornflakes', 'color': 'yellow'},
{'category': 'food', 'name': 'crackers', 'color': 'red'},
{'category': 'food', 'name': 'lemon', 'color': 'yellow'},
{'category': 'food', 'name': 'noodles', 'color': 'yellow'},
{'category': 'food', 'name': 'paprika', 'color': 'red'},
{'category': 'food', 'name': 'peas', 'color': 'green'},
{'category': 'food', 'name': 'pepper', 'color': 'red'},
{'category': 'food', 'name': 'potato', 'color': 'brown'},
{'category': 'food', 'name': 'potato_soup', 'color': 'yellowish'},
{'category': 'food', 'name': 'salt', 'color': 'white'},
{'category': 'food', 'name': 'tomato_pasta', 'color': 'red'},
{'category': 'container', 'name': 'bag', 'color': 'brown'},
{'category': 'container', 'name': 'basket', 'color': 'black'},
{'category': 'container', 'name': 'coffecup', 'color': 'white'},
{'category': 'container', 'name': 'plate', 'color': 'white'},
{'category': 'container', 'name': 'red_bowl', 'color': 'red'},
{'category': 'container', 'name': 'white_bowl', 'color': 'white'},
{'category': 'drink', 'name': 'banana_milk', 'color': 'yellow'},
{'category': 'drink', 'name': 'cappucino', 'color': 'creamy'},
{'category': 'drink', 'name': 'coke', 'color': 'black'},
{'category': 'drink', 'name': 'orange_drink', 'color': 'orange'},
{'category': 'drink', 'name': 'water', 'color': 'transparent'},
{'category': 'snack', 'name': 'chocolate_cookies', 'color': 'brownish'},
{'category': 'snack', 'name': 'egg', 'color': 'white'},
{'category': 'snack', 'name': 'party_cracker', 'color': 'yellow'},
{'category': 'snack', 'name': 'pringles', 'color': 'yellow'},
{'category': 'cleaning_stuff', 'name': 'cloth', 'color': 'blue'},
{'category': 'cleaning_stuff', 'name': 'paper', 'color': 'white'},
{'category': 'cleaning_stuff', 'name': 'sponge', 'color': 'yellow'},
{'category': 'cleaning_stuff', 'name': 'towel', 'color': 'pink'},
{'category': 'cutlery', 'name': 'fork', 'color': 'green'},
{'category': 'cutlery', 'name': 'spoon', 'color': 'blue'},
{'category': 'cutlery', 'name': 'knife', 'color': 'pink'}
]

object_names = list(set([ o["name"] for o in objects ]))
object_categories = list(set([ o["category"] for o in objects ]))
object_color = list(set([ o["color"] for o in objects ]))
# object_groups = list(set([ o["group"] for o in objects ]))
# object_known_objects = list(set([ o["name"] for o in objects ]))

category_locations = {
"food": {"bookcase": "shelf3"},
"drink": {"cabinet": "on_top_of"},
"tool": {"workbench": "on_top_of"},
"decoration": {"dinner_table": "on_top_of"},
"leisure": {"bar": "on_top_of"},
"bowl": {"dinner_table": "on_top_of"},
"tray": {"dinner_table": "on_top_of"}
"container": {"flight_case": "in"},
"drink": {"dinner_table": "on_top_of"},
"snack": {"bookcase": "on_top_of"},
"cleaning_stuff": {"cabinet": "on_top_of"},
"cutlery": {"bar": "on_top_of"}
}

inspect_areas = {
Expand Down Expand Up @@ -214,6 +214,11 @@ def get_object_category(obj):
return o["category"]
return None

def get_object_color(obj):
for o in objects:
if o["name"] == obj:
return o["color"]
return None

# Returns (location, area_name)
def get_object_category_location(obj_cat):
Expand Down

0 comments on commit 1e1ce68

Please sign in to comment.