Repository: isi-vista/adam

Issue:
Using "I" in language representation
Linked to #154 

Comments:

Patch:
diff --git a/adam/language_specific/english/english_language_generator.py b/adam/language_specific/english/english_language_generator.py
index 70849d56..ae26a21d 100644
--- a/adam/language_specific/english/english_language_generator.py
+++ b/adam/language_specific/english/english_language_generator.py
@@ -37,7 +37,7 @@ from adam.language_specific.english.english_syntax import (
     SIMPLE_ENGLISH_DEPENDENCY_TREE_LINEARIZER,
 )
 from adam.ontology import OntologyNode, Region
-from adam.ontology.phase1_ontology import AGENT, GOAL, LEARNER, PATIENT, THEME
+from adam.ontology.phase1_ontology import AGENT, GOAL, LEARNER, PATIENT, THEME, IS_SPEAKER
 from adam.ontology.phase1_spatial_relations import EXTERIOR_BUT_IN_CONTACT, INTERIOR
 from adam.random_utils import SequenceChooser
 from adam.situation import SituationAction, SituationNode, SituationObject
@@ -161,7 +161,10 @@ class SimpleRuleBasedEnglishLanguageGenerator(
             lexicon_entry = self._unique_lexicon_entry(
                 _object.ontology_node  # pylint:disable=protected-access
             )
-            if count > 1 and lexicon_entry.plural_form:
+            # Check if the object is the speaker
+            if IS_SPEAKER in _object.properties:
+                word_form = "I"
+            elif count > 1 and lexicon_entry.plural_form:
                 word_form = lexicon_entry.plural_form
             else:
                 word_form = lexicon_entry.base_form
@@ -200,14 +203,26 @@ class SimpleRuleBasedEnglishLanguageGenerator(
             lexicon_entry = self._unique_lexicon_entry(action.action_type)
             # TODO: we don't currently handle verbal morphology.
             # https://github.com/isi-vista/adam/issues/60
-            if lexicon_entry.verb_form_3SG_PRS:
-                verb_dependency_node = DependencyTreeToken(
-                    lexicon_entry.verb_form_3SG_PRS, lexicon_entry.part_of_speech
+            if len(self.situation.actions) > 1:
+                raise RuntimeError(
+                    "Currently only situations with 0 or 1 actions are supported"
                 )
+            elif (
+                IS_SPEAKER
+                in only(
+                    only(self.situation.actions).argument_roles_to_fillers[AGENT]
+                ).properties
+            ):
+                word_form = lexicon_entry.base_form
+            elif lexicon_entry.verb_form_3SG_PRS:
+                word_form = lexicon_entry.verb_form_3SG_PRS
             else:
                 raise RuntimeError(
                     f"Verb has no 3SG present tense form: {lexicon_entry.base_form}"
                 )
+            verb_dependency_node = DependencyTreeToken(
+                word_form, lexicon_entry.part_of_speech
+            )
             self.dependency_graph.add_node(verb_dependency_node)
 
             for (argument_role, filler) in action.argument_roles_to_fillers.items():


Test patch:
diff --git a/tests/language_specific/english/test_english_language_generator.py b/tests/language_specific/english/test_english_language_generator.py
index 08e58758..2c81e02c 100644
--- a/tests/language_specific/english/test_english_language_generator.py
+++ b/tests/language_specific/english/test_english_language_generator.py
@@ -21,8 +21,13 @@ from adam.ontology.phase1_ontology import (
     DAD,
     PUT,
     GOAL,
+    IS_SPEAKER,
+)
+from adam.ontology.phase1_spatial_relations import (
+    INTERIOR,
+    EXTERIOR_BUT_IN_CONTACT,
+    Direction,
 )
-from adam.ontology.phase1_spatial_relations import INTERIOR
 from adam.random_utils import FixedIndexChooser
 from adam.situation import SituationAction, SituationObject
 from adam.situation.high_level_semantics_situation import HighLevelSemanticsSituation
@@ -118,6 +123,41 @@ def test_mom_put_a_ball_on_a_table():
     ).as_token_sequence() == ("Mom", "puts", "a", "ball", "on", "a", "table")
 
 
+def test_mom_put_a_ball_on_a_table_using_i():
+    mom = SituationObject(ontology_node=MOM, properties=[IS_SPEAKER])
+    ball = SituationObject(ontology_node=BALL)
+    table = SituationObject(ontology_node=TABLE)
+    situation = HighLevelSemanticsSituation(
+        ontology=GAILA_PHASE_1_ONTOLOGY,
+        objects=[mom, ball, table],
+        relations=[],
+        actions=[
+            SituationAction(
+                PUT,
+                (
+                    (AGENT, mom),
+                    (THEME, ball),
+                    (
+                        GOAL,
+                        Region(
+                            reference_object=table,
+                            distance=EXTERIOR_BUT_IN_CONTACT,
+                            direction=Direction(
+                                positive=True,
+                                relative_to_axis="Vertical axis of table "
+                                "relative to earth",
+                            ),
+                        ),
+                    ),
+                ),
+            )
+        ],
+    )
+    assert only(
+        _SIMPLE_GENERATOR.generate_language(situation, FixedIndexChooser(0))
+    ).as_token_sequence() == ("I", "put", "a", "ball", "on", "a", "table")
+
+
 def test_dad_put_a_cookie_in_a_box():
     dad = SituationObject(DAD)
     cookie = SituationObject(COOKIE)
@@ -141,3 +181,28 @@ def test_dad_put_a_cookie_in_a_box():
     assert only(
         _SIMPLE_GENERATOR.generate_language(situation, FixedIndexChooser(0))
     ).as_token_sequence() == ("Dad", "puts", "a", "cookie", "in", "a", "box")
+
+
+def test_dad_put_a_cookie_in_a_box_using_i():
+    dad = SituationObject(DAD, properties=[IS_SPEAKER])
+    cookie = SituationObject(COOKIE)
+    box = SituationObject(BOX)
+    situation = HighLevelSemanticsSituation(
+        ontology=GAILA_PHASE_1_ONTOLOGY,
+        objects=[dad, cookie, box],
+        relations=[],
+        actions=[
+            SituationAction(
+                PUT,
+                (
+                    (AGENT, dad),
+                    (THEME, cookie),
+                    (GOAL, Region(reference_object=box, distance=INTERIOR)),
+                ),
+            )
+        ],
+    )
+
+    assert only(
+        _SIMPLE_GENERATOR.generate_language(situation, FixedIndexChooser(0))
+    ).as_token_sequence() == ("I", "put", "a", "cookie", "in", "a", "box")