in agent/decision_modules/examiner.py [0:0]
def take_control(self):
"""
1) Detect candidate Entities from current location.
2) Examine entities to get detailed descriptions
3) Extract nested entities from detailed descriptions
"""
obs = yield
curr_loc = kg.player_location
undescribed_entities = self.get_descriptionless_entities()
if undescribed_entities:
entity = undescribed_entities[0]
action = gv.Examine(entity.name)
response = yield action
entity.description = response
p_valid = self._valid_detector.action_valid(action, response)
dbg("[EXM] p={:.2f} {} --> {}".format(p_valid, action, clean(response)))
curr_loc.add_action_record(action, 1., response)
else:
entity_name = self._to_examine[curr_loc].pop()
action = gv.Examine(entity_name)
response = yield action
p_valid = self._valid_detector.action_valid(action, first_sentence(response))
success = (p_valid > self._validation_threshold)
self.record(success)
dbg("[EXM]({}) p={:.2f} {} --> {}".format(
"val" if success else "inv", p_valid, action, clean(response)))
curr_loc.add_action_record(action, p_valid, response)
if success:
entity = curr_loc.get_entity_by_description(response)
if entity is None:
entity = Entity(entity_name, curr_loc, description=response)
# TODO: incorrect for entities discovered inside other entities
curr_loc.add_entity(entity)
else:
dbg("[EXM](val) Discovered alternate name "\
"\'{}\' for \'{}\'".format(entity_name, entity.name))
entity.add_name(entity_name)
if success:
entity = curr_loc.get_entity_by_description(response)
inv_entity = kg.inventory.get_entity_by_description(response)
if entity is None and inv_entity is None:
entity = Entity(entity_name, curr_loc, description=response)
# TODO: incorrect for entities discovered inside other entities
curr_loc.add_entity(entity)
else:
if entity:
dbg("[EXM](val) Discovered alternate name " \
"\'{}\' for \'{}\'".format(entity_name, entity.name))
entity.add_name(entity_name)
if inv_entity:
dbg("[EXM](val) Discovered alternate name " \
"\'{}\' for inventory item \'{}\'".format(entity_name, inv_entity.name))
inv_entity.add_name(entity_name)