def test_dynamic_perception_graph_instantiation(): ball = ObjectPerception("ball", _BALL_SCHEMA.geon.copy()) table = ObjectPerception("table", axes=_TABLE_SCHEMA.axes.copy()) first_frame = DevelopmentalPrimitivePerceptionFrame( perceived_objects=[ball, table], relations=[ above(ball, table), Relation(IN_REGION, ball, Region(table, distance=EXTERIOR_BUT_IN_CONTACT)), Relation(IN_REGION, table, Region(ball, distance=EXTERIOR_BUT_IN_CONTACT)), ], ) second_frame = DevelopmentalPrimitivePerceptionFrame( perceived_objects=[ball, table], relations=[Relation(IN_REGION, ball, Region(table, distance=DISTAL))], ) perception_graph = PerceptionGraph.from_dynamic_perceptual_representation( PerceptualRepresentation(frames=[first_frame, second_frame])) assert perception_graph.dynamic # Ensure we don't attempt to handle more than two frames yet. with pytest.raises(ValueError): PerceptionGraph.from_dynamic_perceptual_representation( PerceptualRepresentation( frames=[first_frame, second_frame, second_frame]))
def test_trivial_dynamic_situation_with_schemaless_object(language_mode): dad_situation_object = SituationObject.instantiate_ontology_node( ontology_node=DAD, ontology=GAILA_PHASE_1_ONTOLOGY) situation = HighLevelSemanticsSituation( ontology=GAILA_PHASE_1_ONTOLOGY, salient_objects=[dad_situation_object]) perception_generator = HighLevelSemanticsSituationToDevelopmentalPrimitivePerceptionGenerator( GAILA_PHASE_1_ONTOLOGY) # We explicitly exclude ground in perception generation # this generates a static perception... perception = perception_generator.generate_perception( situation, chooser=RandomChooser.for_seed(0), include_ground=False) # so we need to construct a dynamic one by hand from two identical scenes dynamic_perception = PerceptualRepresentation( frames=[perception.frames[0], perception.frames[0]]) perception_graph = PerceptionGraph.from_dynamic_perceptual_representation( dynamic_perception) perception_semantic_alignment = PerceptionSemanticAlignment.create_unaligned( perception_graph) (_, description_to_matched_semantic_node ) = LANGUAGE_MODE_TO_OBJECT_RECOGNIZER[language_mode].match_objects( perception_semantic_alignment) assert len(description_to_matched_semantic_node) == 1 assert (language_mode == LanguageMode.ENGLISH and ("Dad", ) in description_to_matched_semantic_node) or ( language_mode == LanguageMode.CHINESE and ("ba4 ba4", ) in description_to_matched_semantic_node)
def _extract_perception_graph( self, perception: PerceptualRepresentation[DevelopmentalPrimitivePerceptionFrame] ) -> PerceptionGraph: if perception.is_dynamic(): return PerceptionGraph.from_dynamic_perceptual_representation(perception) else: return PerceptionGraph.from_frame(perception.frames[0])
def test_recognize_in_transfer_of_possession(language_mode): dad = object_variable("person_0", DAD) baby = object_variable("person_1", BABY) chair = object_variable("give_object_0", CHAIR) giving_template = Phase1SituationTemplate( "dad-transfer-of-possession", salient_object_variables=[dad, baby, chair], actions=[ Action( GIVE, argument_roles_to_fillers=[(AGENT, dad), (GOAL, baby), (THEME, chair)], ) ], syntax_hints=[PREFER_DITRANSITIVE], ) (_, _, perception) = first( phase1_instances( "foo", sampled( giving_template, max_to_sample=1, chooser=PHASE1_CHOOSER_FACTORY(), ontology=GAILA_PHASE_1_ONTOLOGY, block_multiple_of_the_same_type=True, ), ).instances()) perception_graph = PerceptionGraph.from_dynamic_perceptual_representation( perception) perception_semantic_alignment = PerceptionSemanticAlignment.create_unaligned( perception_graph) (_, description_to_matched_semantic_node ) = LANGUAGE_MODE_TO_OBJECT_RECOGNIZER[language_mode].match_objects( perception_semantic_alignment) assert len(description_to_matched_semantic_node) == 4 assert (language_mode == LanguageMode.ENGLISH and ("Dad", ) in description_to_matched_semantic_node) or ( language_mode == LanguageMode.CHINESE and ("ba4 ba4", ) in description_to_matched_semantic_node)
def _extract_perception_graph( self, perception: PerceptualRepresentation[ DevelopmentalPrimitivePerceptionFrame] ) -> PerceptionGraph: return PerceptionGraph.from_dynamic_perceptual_representation( perception)