def test_person_and_ball_color():
    person = situation_object(PERSON)
    ball = situation_object(BALL, properties=[RED])

    person_and_ball_situation = HighLevelSemanticsSituation(
        ontology=GAILA_PHASE_1_ONTOLOGY, salient_objects=[person, ball]
    )

    person_and_ball_perception = _PERCEPTION_GENERATOR.generate_perception(
        person_and_ball_situation, chooser=RandomChooser.for_seed(0)
    )

    assert len(person_and_ball_perception.frames) == 1
    frame = person_and_ball_perception.frames[0]

    assert (
        prop_assertion is PropertyPerception
        for prop_assertion in frame.property_assertions
    )

    person_perception = perception_with_handle(frame, "**person_0")
    ball_perception = perception_with_handle(frame, "**ball_0")
    assert HasBinaryProperty(person_perception, ANIMATE) in frame.property_assertions
    assert HasBinaryProperty(person_perception, SELF_MOVING) in frame.property_assertions
    assert HasBinaryProperty(ball_perception, INANIMATE) in frame.property_assertions
    assert any(
        isinstance(property_, HasColor) and property_.perceived_object == ball_perception
        for property_ in frame.property_assertions
    )
def test_gaze_specified():
    cookie = situation_object(COOKIE)
    table = situation_object(TABLE)
    dad = situation_object(DAD)
    situation = HighLevelSemanticsSituation(
        ontology=GAILA_PHASE_1_ONTOLOGY,
        salient_objects=[cookie, table, dad],
        actions=[
            Action(EAT,
                   argument_roles_to_fillers=[(AGENT, dad), (PATIENT, cookie)])
        ],
        gazed_objects=[cookie],
    )
    perception = _PERCEPTION_GENERATOR.generate_perception(
        situation, chooser=RandomChooser.for_seed(0))
    frame = perception.frames[0]
    cookie_perception = perception_with_handle(frame, "**cookie_0")
    dad_perception = perception_with_handle(frame, "**Dad_0")
    table_perception = perception_with_handle(frame, "**table_0")
    # only the cookie is gazed at, because the user said so.
    assert HasBinaryProperty(cookie_perception,
                             GAZED_AT) in frame.property_assertions
    assert HasBinaryProperty(dad_perception,
                             GAZED_AT) not in frame.property_assertions
    assert HasBinaryProperty(table_perception,
                             GAZED_AT) not in frame.property_assertions
def test_person_and_ball():
    person = situation_object(PERSON)
    ball = situation_object(BALL)

    person_and_ball_situation = HighLevelSemanticsSituation(
        ontology=GAILA_PHASE_1_ONTOLOGY, salient_objects=[person, ball]
    )

    person_and_ball_perception = _PERCEPTION_GENERATOR.generate_perception(
        person_and_ball_situation, chooser=RandomChooser.for_seed(0)
    )

    perceived_objects = person_and_ball_perception.frames[0].perceived_objects
    object_handles = set(obj.debug_handle for obj in perceived_objects)
    assert len(person_and_ball_perception.frames) == 1
    assert object_handles == {
        "**ball_0",
        "**person_0",
        "**head_0",
        "**torso_0",
        "**arm_0",
        "**armsegment_0",
        "**armsegment_1",
        "**hand_0",
        "**arm_1",
        "**armsegment_2",
        "**armsegment_3",
        "**hand_1",
        "**(animal) leg_0",
        "**leg-segment_0",
        "**leg-segment_1",
        "**foot_0",
        "**(animal) leg_1",
        "**leg-segment_2",
        "**leg-segment_3",
        "**foot_1",
        "the ground",
    }

    assert person_and_ball_perception.frames[0].relations

    person_perception = perception_with_handle(
        person_and_ball_perception.frames[0], "**person_0"
    )
    ball_perception = perception_with_handle(
        person_and_ball_perception.frames[0], "**ball_0"
    )

    assert set(person_and_ball_perception.frames[0].property_assertions).issuperset(
        {
            HasBinaryProperty(person_perception, ANIMATE),
            HasBinaryProperty(person_perception, SELF_MOVING),
            HasBinaryProperty(ball_perception, INANIMATE),
        }
    )
示例#4
0
def test_recognized_particular():
    # create a simple situation consisting of only Mom and Dad
    mom = ObjectPerception("mom", axes=_PERSON_SCHEMA.axes.copy())
    dad = ObjectPerception("dad", axes=_PERSON_SCHEMA.axes.copy())

    PerceptualRepresentation.single_frame(
        DevelopmentalPrimitivePerceptionFrame(
            perceived_objects=[mom, dad],
            property_assertions=[
                HasBinaryProperty(mom, SENTIENT),
                HasBinaryProperty(dad, SENTIENT),
                HasBinaryProperty(mom, IS_MOM),
                HasBinaryProperty(dad, IS_DAD),
            ],
        ))
def test_subobject_perception_has_appropriate_properties():
    """
    Intended to test that an object's subobjects have their properties assigned to them properly
    """
    learner_perception = _PERCEPTION_GENERATOR.generate_perception(
        HighLevelSemanticsSituation(ontology=GAILA_PHASE_1_ONTOLOGY,
                                    salient_objects=[situation_object(TABLE)]),
        chooser=RandomChooser.for_seed(0),
    )
    frame = learner_perception.frames[0]
    property_assertions = frame.property_assertions

    leg_perceptions = [
        perception_with_handle(frame, "**(furniture) leg_0"),
        perception_with_handle(frame, "**(furniture) leg_1"),
        perception_with_handle(frame, "**(furniture) leg_2"),
        perception_with_handle(frame, "**(furniture) leg_3"),
    ]
    assert all(
        HasBinaryProperty(leg_perception, INANIMATE) in property_assertions
        for leg_perception in leg_perceptions)
def test_person_put_ball_on_table():
    person = situation_object(ontology_node=PERSON)
    ball = situation_object(ontology_node=BALL)
    table = situation_object(ontology_node=TABLE)
    situation = HighLevelSemanticsSituation(
        ontology=GAILA_PHASE_1_ONTOLOGY,
        salient_objects=[person, ball, table],
        actions=[
            # What is the best way of representing the destination in the high-level semantics?
            # Here we represent it as indicating a relation which should be true.
            Action(
                PUT,
                (
                    (AGENT, person),
                    (THEME, ball),
                    (
                        GOAL,
                        Region(
                            reference_object=table,
                            distance=EXTERIOR_BUT_IN_CONTACT,
                            direction=GRAVITATIONAL_UP,
                        ),
                    ),
                ),
            )
        ],
    )

    perception = _PERCEPTION_GENERATOR.generate_perception(
        situation, chooser=RandomChooser.for_seed(0)
    )
    assert len(perception.frames) == 2
    first_frame = perception.frames[0]
    person_perception = perception_with_handle(first_frame, "**person_0")
    ball_perception = perception_with_handle(first_frame, "**ball_0")
    table_perception = perception_with_handle(first_frame, "**table_0")
    hand_perception = perception_with_handle(first_frame, "**hand_0")
    assert (
        HasBinaryProperty(person_perception, ANIMATE) in first_frame.property_assertions
    )
    assert (
        HasBinaryProperty(person_perception, SELF_MOVING)
        in first_frame.property_assertions
    )
    assert (
        HasBinaryProperty(ball_perception, INANIMATE) in first_frame.property_assertions
    )
    assert (
        HasBinaryProperty(table_perception, INANIMATE) in first_frame.property_assertions
    )

    first_frame_relations = first_frame.relations
    second_frame_relations = perception.frames[1].relations

    # assert we generate at least some relations in each frame
    assert first_frame_relations
    assert second_frame_relations

    assert (
        Relation(SMALLER_THAN, ball_perception, person_perception)
        in first_frame_relations
    )
    # Disabled because of https://github.com/isi-vista/adam/issues/673
    # assert Relation(PART_OF, hand_perception, person_perception) in first_frame_relations
    assert (
        Relation(
            IN_REGION,
            ball_perception,
            Region(reference_object=hand_perception, distance=EXTERIOR_BUT_IN_CONTACT),
        )
        in first_frame_relations
    )

    # continuing relations:
    assert (
        Relation(SMALLER_THAN, ball_perception, person_perception)
        in second_frame_relations
    )

    # new relations:
    ball_on_table_relation = Relation(
        IN_REGION,
        ball_perception,
        Region(
            table_perception, distance=EXTERIOR_BUT_IN_CONTACT, direction=GRAVITATIONAL_UP
        ),
    )
    assert ball_on_table_relation in second_frame_relations

    # removed relations:
    assert (
        Relation(
            IN_REGION,
            ball_perception,
            Region(reference_object=hand_perception, distance=EXTERIOR_BUT_IN_CONTACT),
        )
        not in second_frame_relations
    )

    # proto-role properties
    assert (
        HasBinaryProperty(person_perception, VOLITIONALLY_INVOLVED)
        in first_frame.property_assertions
    )
    assert (
        HasBinaryProperty(person_perception, CAUSES_CHANGE)
        in first_frame.property_assertions
    )
    assert (
        HasBinaryProperty(ball_perception, UNDERGOES_CHANGE)
        in first_frame.property_assertions
    )
    assert (
        HasBinaryProperty(table_perception, STATIONARY) in first_frame.property_assertions
    )