Repository: isi-vista/adam

Issue:
Using 'you' in language representation
linked to #156 
Note that this is for the subject pronoun "you", not the object pronoun.

Comments:

Patch:
diff --git a/adam/language_specific/english/english_language_generator.py b/adam/language_specific/english/english_language_generator.py
index 97003586..b02f6d14 100644
--- a/adam/language_specific/english/english_language_generator.py
+++ b/adam/language_specific/english/english_language_generator.py
@@ -14,11 +14,19 @@ from adam.language.dependency import (
     DependencyTreeToken,
     LinearizedDependencyTree,
 )
-from adam.language.dependency.universal_dependencies import (ADJECTIVAL_MODIFIER, ADPOSITION,
-                                                             CASE_MARKING, DETERMINER,
-                                                             DETERMINER_ROLE, NOMINAL_SUBJECT,
-                                                             NUMERAL, NUMERIC_MODIFIER, OBJECT,
-                                                             OBLIQUE_NOMINAL, PROPER_NOUN)
+from adam.language.dependency.universal_dependencies import (
+    ADJECTIVAL_MODIFIER,
+    ADPOSITION,
+    CASE_MARKING,
+    DETERMINER,
+    DETERMINER_ROLE,
+    NOMINAL_SUBJECT,
+    NUMERAL,
+    NUMERIC_MODIFIER,
+    OBJECT,
+    OBLIQUE_NOMINAL,
+    PROPER_NOUN,
+)
 from adam.language.language_generator import LanguageGenerator
 from adam.language.lexicon import LexiconEntry
 from adam.language.ontology_dictionary import OntologyLexicon
@@ -30,7 +38,16 @@ 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, COLOR, GOAL, IS_SPEAKER, LEARNER, PATIENT, THEME
+from adam.ontology.phase1_ontology import (
+    AGENT,
+    GOAL,
+    LEARNER,
+    PATIENT,
+    THEME,
+    IS_SPEAKER,
+    IS_ADDRESSEE,
+)
+from adam.ontology.phase1_ontology import COLOR
 from adam.ontology.phase1_spatial_relations import EXTERIOR_BUT_IN_CONTACT, INTERIOR
 from adam.random_utils import SequenceChooser
 from adam.situation import SituationAction, SituationObject
@@ -154,9 +171,11 @@ class SimpleRuleBasedEnglishLanguageGenerator(
             lexicon_entry = self._unique_lexicon_entry(
                 _object.ontology_node  # pylint:disable=protected-access
             )
-            # Check if the object is the speaker
+            # Check if the situation object is the speaker
             if IS_SPEAKER in _object.properties:
                 word_form = "I"
+            elif IS_ADDRESSEE in _object.properties:
+                word_form = "you"
             elif count > 1 and lexicon_entry.plural_form:
                 word_form = lexicon_entry.plural_form
             else:
@@ -211,11 +230,12 @@ class SimpleRuleBasedEnglishLanguageGenerator(
                 raise RuntimeError(
                     "Currently only situations with 0 or 1 actions are supported"
                 )
-            elif (
-                IS_SPEAKER
+            elif any(
+                property_
                 in only(
                     only(self.situation.actions).argument_roles_to_fillers[AGENT]
                 ).properties
+                for property_ in [IS_SPEAKER, IS_ADDRESSEE]
             ):
                 word_form = lexicon_entry.base_form
             elif lexicon_entry.verb_form_3SG_PRS:
diff --git a/adam/ontology/phase1_ontology.py b/adam/ontology/phase1_ontology.py
index e3ab7182..1384a28a 100644
--- a/adam/ontology/phase1_ontology.py
+++ b/adam/ontology/phase1_ontology.py
@@ -124,6 +124,14 @@ It only makes sense to apply this to sub-types of PERSON,
 but this is not currently enforced.
 """
 subtype(IS_SPEAKER, PERCEIVABLE_PROPERTY)
+IS_ADDRESSEE = OntologyNode("is-addressee", [BINARY])
+"""
+Indicates that the marked object is the one who is addressed.
+This will not be present for all situations.
+It only makes sense to apply this to sub-types of PERSON,
+but this is not currently enforced. E.g. 'You put the ball on the table.'
+"""
+subtype(IS_ADDRESSEE, PERCEIVABLE_PROPERTY)
 
 # Properties not perceived by the learner, but useful for situation generation
 


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 879ec84b..d6aadd76 100644
--- a/tests/language_specific/english/test_english_language_generator.py
+++ b/tests/language_specific/english/test_english_language_generator.py
@@ -23,6 +23,7 @@ from adam.ontology.phase1_ontology import (
     GOAL,
     IS_SPEAKER,
     GREEN,
+    IS_ADDRESSEE,
 )
 from adam.ontology.phase1_spatial_relations import (
     INTERIOR,
@@ -159,6 +160,41 @@ def test_mom_put_a_ball_on_a_table_using_i():
     ).as_token_sequence() == ("I", "put", "a", "ball", "on", "a", "table")
 
 
+def test_mom_put_a_ball_on_a_table_using_you():
+    mom = SituationObject(ontology_node=MOM, properties=[IS_ADDRESSEE])
+    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() == ("you", "put", "a", "ball", "on", "a", "table")
+
+
 def test_dad_put_a_cookie_in_a_box():
     dad = SituationObject(DAD)
     cookie = SituationObject(COOKIE)
@@ -208,6 +244,32 @@ def test_dad_put_a_cookie_in_a_box_using_i():
         _SIMPLE_GENERATOR.generate_language(situation, FixedIndexChooser(0))
     ).as_token_sequence() == ("I", "put", "a", "cookie", "in", "a", "box")
 
+
+def test_dad_put_a_cookie_in_a_box_using_you():
+    dad = SituationObject(DAD, properties=[IS_ADDRESSEE])
+    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() == ("you", "put", "a", "cookie", "in", "a", "box")
+
+
 def test_green_ball():
     ball = SituationObject(BALL, [GREEN])
     situation = HighLevelSemanticsSituation(