Repository: isi-vista/adam

Issue:
FALL curriculum with prepositions
_in, on, beside, behind, in front of_

Comments:

Patch:
diff --git a/adam/curriculum/verbs_with_dynamic_prepositions_curriculum.py b/adam/curriculum/verbs_with_dynamic_prepositions_curriculum.py
index dbbfc836..e32decb5 100644
--- a/adam/curriculum/verbs_with_dynamic_prepositions_curriculum.py
+++ b/adam/curriculum/verbs_with_dynamic_prepositions_curriculum.py
@@ -25,6 +25,7 @@ from adam.ontology import THING
 from adam.ontology.during import DuringAction
 from adam.ontology.phase1_ontology import (
     AGENT,
+    FALL,
     GOAL,
     GAILA_PHASE_1_ONTOLOGY,
     HOLLOW,
@@ -99,10 +100,9 @@ def _push_to_template(
                 during=DuringAction(continuously=[on(theme, surface)]),
             )
         ],
-        constraining_relations=[
-            bigger_than(surface, agent),
-            bigger_than(surface, goal_reference),
-        ],
+        constraining_relations=flatten_relations(
+            [bigger_than(surface, agent), bigger_than(surface, goal_reference)]
+        ),
     )
 
 
@@ -129,11 +129,13 @@ def _push_in_template(
                 during=DuringAction(continuously=[on(theme, surface)]),
             )
         ],
-        constraining_relations=[
-            bigger_than(surface, agent),
-            bigger_than(surface, goal_reference),
-            bigger_than(goal_reference, theme),
-        ],
+        constraining_relations=flatten_relations(
+            [
+                bigger_than(surface, agent),
+                bigger_than(surface, goal_reference),
+                bigger_than(goal_reference, theme),
+            ]
+        ),
     )
 
 
@@ -168,11 +170,13 @@ def _push_under_template(
                 during=DuringAction(continuously=[on(theme, surface)]),
             )
         ],
-        constraining_relations=[
-            bigger_than(surface, agent),
-            bigger_than(surface, goal_reference),
-            bigger_than(goal_reference, theme),
-        ],
+        constraining_relations=flatten_relations(
+            [
+                bigger_than(surface, agent),
+                bigger_than(surface, goal_reference),
+                bigger_than(goal_reference, theme),
+            ]
+        ),
     )
 
 
@@ -212,10 +216,9 @@ def _push_beside_template(
                 during=DuringAction(continuously=[on(theme, surface)]),
             )
         ],
-        constraining_relations=[
-            bigger_than(surface, agent),
-            bigger_than(surface, goal_reference),
-        ],
+        constraining_relations=flatten_relations(
+            [bigger_than(surface, agent), bigger_than(surface, goal_reference)]
+        ),
     )
 
 
@@ -254,10 +257,9 @@ def _push_in_front_of_behind_template(
                 during=DuringAction(continuously=[on(theme, surface)]),
             )
         ],
-        constraining_relations=[
-            bigger_than(surface, agent),
-            bigger_than(surface, goal_reference),
-        ],
+        constraining_relations=flatten_relations(
+            [bigger_than(surface, agent), bigger_than(surface, goal_reference)]
+        ),
     )
 
 
@@ -301,7 +303,7 @@ def _go_in_template(
                 ],
             )
         ],
-        constraining_relations=[bigger_than(goal_object, agent)],
+        constraining_relations=flatten_relations(bigger_than(goal_object, agent)),
     )
 
 
@@ -523,7 +525,9 @@ def _sit_on_template(
                 auxiliary_variable_bindings=[(SIT_THING_SAT_ON, seat)],
             )
         ],
-        constraining_relations=[bigger_than(surface, seat), bigger_than(seat, agent)],
+        constraining_relations=flatten_relations(
+            [bigger_than(surface, seat), bigger_than(seat, agent)]
+        ),
         syntax_hints=syntax_hints,
     )
 
@@ -549,7 +553,9 @@ def _sit_in_template(
                 auxiliary_variable_bindings=[(SIT_THING_SAT_ON, seat)],
             )
         ],
-        constraining_relations=[bigger_than(surface, seat), bigger_than(seat, agent)],
+        constraining_relations=flatten_relations(
+            [bigger_than(surface, seat), bigger_than(seat, agent)]
+        ),
         syntax_hints=syntax_hints,
     )
 
@@ -660,7 +666,9 @@ def _x_roll_y_in_z_template(
                 auxiliary_variable_bindings=[(ROLL_SURFACE_AUXILIARY, surface)],
             )
         ],
-        constraining_relations=[bigger_than([agent, goal_reference], theme)],
+        constraining_relations=flatten_relations(
+            [bigger_than([agent, goal_reference], theme)]
+        ),
         after_action_relations=flatten_relations(inside(theme, goal_reference)),
         gazed_objects=[theme],
     )
@@ -690,7 +698,7 @@ def _x_roll_y_beside_z_template(
                 auxiliary_variable_bindings=[(ROLL_SURFACE_AUXILIARY, surface)],
             )
         ],
-        constraining_relations=[bigger_than(agent, theme)],
+        constraining_relations=flatten_relations([bigger_than(agent, theme)]),
         after_action_relations=flatten_relations(
             near(theme, goal_reference, direction=direction)
         ),
@@ -725,7 +733,7 @@ def _x_roll_y_behind_in_front_z_template(
                 auxiliary_variable_bindings=[(ROLL_SURFACE_AUXILIARY, surface)],
             )
         ],
-        constraining_relations=[bigger_than(agent, theme)],
+        constraining_relations=flatten_relations([bigger_than(agent, theme)]),
         after_action_relations=flatten_relations(
             far(theme, goal_reference, direction=direction)
             if is_distal
@@ -756,7 +764,7 @@ def _x_rolls_y_over_under_z_template(
                 auxiliary_variable_bindings=[(ROLL_SURFACE_AUXILIARY, surface)],
             )
         ],
-        constraining_relations=[bigger_than(agent, theme)],
+        constraining_relations=flatten_relations([bigger_than(agent, theme)]),
         after_action_relations=flatten_relations(
             above(theme, goal_reference) if is_over else above(goal_reference, theme)
         ),
@@ -764,6 +772,95 @@ def _x_rolls_y_over_under_z_template(
     )
 
 
+# FALL templates
+
+
+def _fall_on_template(
+    theme: TemplateObjectVariable,
+    goal_reference: TemplateObjectVariable,
+    background: ImmutableSet[TemplateObjectVariable],
+    *,
+    syntax_hints: ImmutableSet[str],
+) -> Phase1SituationTemplate:
+    return Phase1SituationTemplate(
+        f"{theme.handle}-falls-(down)-on-{goal_reference.handle}",
+        salient_object_variables=[theme, goal_reference],
+        background_object_variables=background,
+        actions=[Action(FALL, argument_roles_to_fillers=[(THEME, theme)])],
+        after_action_relations=flatten_relations(on(theme, goal_reference)),
+        constraining_relations=flatten_relations(bigger_than(goal_reference, theme)),
+        syntax_hints=syntax_hints,
+    )
+
+
+def _fall_in_template(
+    theme: TemplateObjectVariable,
+    goal_reference: TemplateObjectVariable,
+    background: ImmutableSet[TemplateObjectVariable],
+    *,
+    syntax_hints: ImmutableSet[str],
+) -> Phase1SituationTemplate:
+    return Phase1SituationTemplate(
+        f"{theme.handle}-falls-(down)-in-{goal_reference.handle}",
+        salient_object_variables=[theme, goal_reference],
+        background_object_variables=background,
+        actions=[Action(FALL, argument_roles_to_fillers=[(THEME, theme)])],
+        after_action_relations=flatten_relations(inside(theme, goal_reference)),
+        constraining_relations=flatten_relations(bigger_than(goal_reference, theme)),
+        syntax_hints=syntax_hints,
+    )
+
+
+def _fall_beside_template(
+    theme: TemplateObjectVariable,
+    goal_reference: TemplateObjectVariable,
+    background: ImmutableSet[TemplateObjectVariable],
+    *,
+    syntax_hints: ImmutableSet[str],
+    is_right: bool,
+) -> Phase1SituationTemplate:
+    direction = Direction(
+        positive=is_right,
+        relative_to_axis=HorizontalAxisOfObject(goal_reference, index=0),
+    )
+    return Phase1SituationTemplate(
+        f"{theme.handle}-falls-(down)-beside-{goal_reference.handle}",
+        salient_object_variables=[theme, goal_reference],
+        background_object_variables=background,
+        actions=[Action(FALL, argument_roles_to_fillers=[(THEME, theme)])],
+        after_action_relations=flatten_relations(
+            near(theme, goal_reference, direction=direction)
+        ),
+        syntax_hints=syntax_hints,
+    )
+
+
+def _fall_in_front_of_behind_template(
+    theme: TemplateObjectVariable,
+    goal_reference: TemplateObjectVariable,
+    background: ImmutableSet[TemplateObjectVariable],
+    *,
+    syntax_hints: ImmutableSet[str],
+    is_distal: bool,
+    is_in_front: bool,
+) -> Phase1SituationTemplate:
+    direction = Direction(
+        positive=is_in_front, relative_to_axis=FacingAddresseeAxis(goal_reference)
+    )
+    return Phase1SituationTemplate(
+        f"{theme.handle}-falls-(down)-in-front-of-behind-{goal_reference.handle}",
+        salient_object_variables=[theme, goal_reference],
+        background_object_variables=background,
+        actions=[Action(FALL, argument_roles_to_fillers=[(THEME, theme)])],
+        after_action_relations=flatten_relations(
+            far(theme, goal_reference, direction=direction)
+            if is_distal
+            else near(theme, goal_reference, direction=direction)
+        ),
+        syntax_hints=syntax_hints,
+    )
+
+
 def _make_push_with_prepositions(
     num_samples: int = 5, *, noise_objects: int = 0
 ) -> Phase1InstanceGroup:
@@ -1216,6 +1313,94 @@ def _make_roll_with_prepositions(num_samples: int = 5, *, noise_objects: int = 0
     )
 
 
+def _make_fall_with_prepositions(
+    num_samples: int = 5, *, noise_objects: int = 0
+) -> Phase1InstanceGroup:
+    theme = standard_object("theme", THING)
+    goal_reference = standard_object("goal_reference", THING)
+    goal_on = standard_object(
+        "goal_on", THING, required_properties=[CAN_HAVE_THINGS_RESTING_ON_THEM]
+    )
+    goal_in = standard_object("goal_in", THING, required_properties=[HOLLOW])
+    background = immutableset(
+        standard_object(f"noise_object_{x}") for x in range(noise_objects)
+    )
+    syntax_hints_options = ([], [USE_ADVERBIAL_PATH_MODIFIER])  # type: ignore
+    return phase1_instances(
+        "Fall + PP",
+        chain(
+            # on
+            flatten(
+                [
+                    sampled(
+                        _fall_on_template(
+                            theme, goal_on, background, syntax_hints=syntax_hints
+                        ),
+                        ontology=GAILA_PHASE_1_ONTOLOGY,
+                        chooser=PHASE1_CHOOSER,
+                        max_to_sample=num_samples,
+                    )
+                    for syntax_hints in syntax_hints_options
+                ]
+            ),
+            # in
+            flatten(
+                [
+                    sampled(
+                        _fall_in_template(
+                            theme, goal_in, background, syntax_hints=syntax_hints
+                        ),
+                        ontology=GAILA_PHASE_1_ONTOLOGY,
+                        chooser=PHASE1_CHOOSER,
+                        max_to_sample=num_samples,
+                    )
+                    for syntax_hints in syntax_hints_options
+                ]
+            ),
+            # beside
+            flatten(
+                [
+                    sampled(
+                        _fall_beside_template(
+                            theme,
+                            goal_reference,
+                            background,
+                            syntax_hints=syntax_hints,
+                            is_right=is_right,
+                        ),
+                        ontology=GAILA_PHASE_1_ONTOLOGY,
+                        chooser=PHASE1_CHOOSER,
+                        max_to_sample=num_samples,
+                    )
+                    for syntax_hints in syntax_hints_options
+                    for is_right in BOOL_SET
+                ]
+            ),
+            # in front of, behind
+            flatten(
+                [
+                    sampled(
+                        _fall_in_front_of_behind_template(
+                            theme,
+                            goal_reference,
+                            background,
+                            syntax_hints=syntax_hints,
+                            is_distal=is_distal,
+                            is_in_front=is_in_front,
+                        ),
+                        ontology=GAILA_PHASE_1_ONTOLOGY,
+                        chooser=PHASE1_CHOOSER,
+                        max_to_sample=num_samples,
+                    )
+                    for syntax_hints in syntax_hints_options
+                    for is_distal in BOOL_SET
+                    for is_in_front in BOOL_SET
+                ]
+            ),
+        ),
+    )
+
+
 def make_verb_with_dynamic_prepositions_curriculum(
     num_samples: int = 5, *, num_noise_objects: int = 0
 ):
@@ -1224,4 +1409,5 @@ def make_verb_with_dynamic_prepositions_curriculum(
         _make_go_with_prepositions(num_samples, noise_objects=num_noise_objects),
         _make_sit_with_prepositions(num_samples, noise_objects=num_noise_objects),
         _make_roll_with_prepositions(num_samples, noise_objects=num_noise_objects),
+        _make_fall_with_prepositions(num_samples, noise_objects=num_noise_objects),
     ]


Test patch:
diff --git a/tests/curriculum/verbs_with_dynamic_prepositions_curriculum_test.py b/tests/curriculum/verbs_with_dynamic_prepositions_curriculum_test.py
index 89b2f94e..ecc7f63d 100644
--- a/tests/curriculum/verbs_with_dynamic_prepositions_curriculum_test.py
+++ b/tests/curriculum/verbs_with_dynamic_prepositions_curriculum_test.py
@@ -3,6 +3,7 @@ from adam.curriculum.verbs_with_dynamic_prepositions_curriculum import (
     _make_go_with_prepositions,
     _make_roll_with_prepositions,
     _make_sit_with_prepositions,
+    _make_fall_with_prepositions,
 )
 from tests.curriculum.phase1_curriculum_test import curriculum_test
 
@@ -21,3 +22,7 @@ def test_make_roll():
 
 def test_make_sit():
     curriculum_test(_make_sit_with_prepositions())
+
+
+def test_make_fall():
+    curriculum_test(_make_fall_with_prepositions())