From b5fa5726d9d6ce339230c6ee74a042adb1d0c805 Mon Sep 17 00:00:00 2001 From: InspectorCaracal <51038201+InspectorCaracal@users.noreply.github.com> Date: Sun, 9 Oct 2022 16:19:35 -0600 Subject: [PATCH 1/3] Expand pronoun tests plural handling use source as defaults and always apply gender --- evennia/utils/verb_conjugation/pronouns.py | 259 ++++++++++++++------- evennia/utils/verb_conjugation/tests.py | 76 ++++-- 2 files changed, 243 insertions(+), 92 deletions(-) diff --git a/evennia/utils/verb_conjugation/pronouns.py b/evennia/utils/verb_conjugation/pronouns.py index c676216c97..29cbf9df5f 100644 --- a/evennia/utils/verb_conjugation/pronouns.py +++ b/evennia/utils/verb_conjugation/pronouns.py @@ -59,7 +59,10 @@ PRONOUN_MAPPING = { "neutral": "mine", "plural": "ours", }, - "reflexive pronoun": {"neutral": "myself", "plural": "ourselves"}, + "reflexive pronoun": { + "neutral": "myself", + "plural": "ourselves" + } }, "2nd person": { "subject pronoun": { @@ -77,16 +80,26 @@ PRONOUN_MAPPING = { "reflexive pronoun": { "neutral": "yourself", "plural": "yourselves", - }, + } }, "3rd person": { - "subject pronoun": {"male": "he", "female": "she", "neutral": "it", "plural": "they"}, - "object pronoun": {"male": "him", "female": "her", "neutral": "it", "plural": "them"}, + "subject pronoun": { + "male": "he", + "female": "she", + "neutral": "it", + "plural": "they" + }, + "object pronoun": { + "male": "him", + "female": "her", + "neutral": "it", + "plural": "them" + }, "possessive adjective": { "male": "his", "female": "her", "neutral": "its", - "plural": "their", + "plural": "their" }, "possessive pronoun": { "male": "his", @@ -100,68 +113,173 @@ PRONOUN_MAPPING = { "neutral": "itself", "plural": "themselves", }, - }, + } } PRONOUN_TABLE = { - "I": ("1st person", ("neutral", "male", "female"), "subject pronoun"), - "me": ("1st person", ("neutral", "male", "female"), "object pronoun"), - "my": ("1st person", ("neutral", "male", "female"), "possessive adjective"), - "mine": ("1st person", ("neutral", "male", "female"), "possessive pronoun"), - "myself": ("1st person", ("neutral", "male", "female"), "reflexive pronoun"), - "we": ("1st person", "plural", "subject pronoun"), - "us": ("1st person", "plural", "object pronoun"), - "our": ("1st person", "plural", "possessive adjective"), - "ours": ("1st person", "plural", "possessive pronoun"), - "ourselves": ("1st person", "plural", "reflexive pronoun"), + "I": ( + "1st person", + ("neutral", "male", "female", "plural"), + "subject pronoun" + ), + "me": ( + "1st person", + ("neutral", "male", "female", "plural"), + "object pronoun" + ), + "my": ( + "1st person", + ("neutral", "male", "female", "plural"), + "possessive adjective" + ), + "mine": ( + "1st person", + ("neutral", "male", "female", "plural"), + "possessive pronoun" + ), + "myself": ( + "1st person", + ("neutral", "male", "female", "plural"), + "reflexive pronoun" + ), + + "we": ( + "1st person", + "plural", + "subject pronoun" + ), + "us": ( + "1st person", + "plural", + "object pronoun" + ), + "our": ( + "1st person", + "plural", + "possessive adjective" + ), + "ours": ( + "1st person", + "plural", + "possessive pronoun" + ), + "ourselves": ( + "1st person", + "plural", + "reflexive pronoun" + ), "you": ( - "2nd person", - ("neutral", "male", "female", "plural"), - ("subject pronoun", "object pronoun"), - ), - "your": ("2nd person", ("neutral", "male", "female", "plural"), "possessive adjective"), - "yours": ("2nd person", ("neutral", "male", "female", "plural"), "possessive pronoun"), - "yourself": ("2nd person", ("neutral", "male", "female"), "reflexive pronoun"), - "yourselves": ("2nd person", "plural", "reflexive pronoun"), - "he": ("3rd person", "male", "subject pronoun"), - "him": ("3rd person", "male", "object pronoun"), - "his": ( - "3rd person", - "male", - ("possessive pronoun", "possessive adjective"), - ), - "himself": ("3rd person", "male", "reflexive pronoun"), - "she": ("3rd person", "female", "subject pronoun"), + "2nd person", + ("neutral", "male", "female", "plural"), + ("subject pronoun", "object pronoun") + ), + "your": ( + "2nd person", + ("neutral", "male", "female", "plural"), + "possessive adjective" + ), + "yours": ( + "2nd person", + ("neutral", "male", "female", "plural"), + "possessive pronoun" + ), + "yourself": ( + "2nd person", + ("neutral", "male", "female"), + "reflexive pronoun" + ), + "yourselves": ( + "2nd person", + "plural", + "reflexive pronoun" + ), + "he": ( + "3rd person", + "male", + "subject pronoun" + ), + "him": ( + "3rd person", + "male", + "object pronoun" + ), + "his":( + "3rd person", + "male", + ("possessive pronoun","possessive adjective"), + ), + "himself": ( + "3rd person", + "male", + "reflexive pronoun" + ), + "she": ( + "3rd person", + "female", + "subject pronoun" + ), "her": ( - "3rd person", - "female", - ("object pronoun", "possessive adjective"), - ), - "hers": ("3rd person", "female", "possessive pronoun"), - "herself": ("3rd person", "female", "reflexive pronoun"), + "3rd person", + "female", + ("object pronoun", "possessive adjective"), + ), + "hers": ( + "3rd person", + "female", + "possessive pronoun" + ), + "herself": ( + "3rd person", + "female", + "reflexive pronoun" + ), "it": ( - "3rd person", - "neutral", - ("subject pronoun", "object pronoun"), - ), + "3rd person", + "neutral", + ("subject pronoun", "object pronoun"), + ), "its": ( - "3rd person", - "neutral", - ("possessive pronoun", "possessive adjective"), - ), - "itself": ("3rd person", "neutral", "reflexive pronoun"), - "they": ("3rd person", "plural", "subject pronoun"), - "them": ("3rd person", "plural", "object pronoun"), - "their": ("3rd person", "plural", "possessive adjective"), - "theirs": ("3rd person", "plural", "possessive pronoun"), - "themselves": ("3rd person", "plural", "reflexive pronoun"), + "3rd person", + "neutral", + ("possessive pronoun", "possessive adjective"), + ), + "itself": ( + "3rd person", + "neutral", + "reflexive pronoun" + ), + "they": ( + "3rd person", + "plural", + "subject pronoun" + ), + "them": ( + "3rd person", + "plural", + "object pronoun" + ), + "their": ( + "3rd person", + "plural", + "possessive adjective" + ), + "theirs": ( + "3rd person", + "plural", + "possessive pronoun" + ), + "themselves": ( + "3rd person", + "plural", + "reflexive pronoun" + ), } # define the default viewpoint conversions VIEWPOINT_CONVERSION = { "1st person": "3rd person", "2nd person": "3rd person", - "3rd person": ("1st person", "2nd person"), + "3rd person": ("2nd person", "1st person"), } ALIASES = { @@ -186,14 +304,10 @@ ALIASES = { def pronoun_to_viewpoints( - pronoun, - options=None, - pronoun_type=DEFAULT_PRONOUN_TYPE, - gender=DEFAULT_GENDER, - viewpoint=DEFAULT_VIEWPOINT, + pronoun, options=None, pronoun_type=None, gender=None, viewpoint=None ): """ - Access function for determining the forms of a pronount from different viewpoints. + Access function for determining the forms of a pronoun from different viewpoints. Args: pronoun (str): A valid English pronoun, such as 'you', 'his', 'themselves' etc. @@ -244,14 +358,14 @@ def pronoun_to_viewpoints( # get the default data for the input pronoun source_viewpoint, source_gender, source_type = PRONOUN_TABLE[pronoun_lower] - # differentiators + # use the source pronoun's attributes as defaults if pronoun_type not in PRONOUN_TYPES: - pronoun_type = DEFAULT_PRONOUN_TYPE + pronoun_type = source_type[0] if is_iter(source_type) else source_type if viewpoint not in VIEWPOINTS: - viewpoint = DEFAULT_VIEWPOINT + viewpoint = source_viewpoint if gender not in GENDERS: - gender = DEFAULT_GENDER - + gender = source_gender[0] if is_iter(source_gender) else source_gender + if options: # option string/list will override the kwargs differentiators given if isinstance(options, str): @@ -279,19 +393,8 @@ def pronoun_to_viewpoints( else: viewpoint = target_viewpoint - # special handling for the royal "we" - if is_iter(source_gender): - gender_opts = list(source_gender) - else: - gender_opts = [source_gender] - if viewpoint == "1st person": - # make sure plural is always an option when converting to 1st person - # it doesn't matter if it's in the list twice, so don't bother checking - gender_opts.append("plural") - # if the gender is still not in the extended options, fall back to source pronoun's default - gender = gender if gender in gender_opts else gender_opts[0] - - # step down into the mapping + # by this point, gender will be a valid option from GENDERS and type/viewpoint will be validated + # step down into the mapping to get the converted pronoun viewpoint_map = PRONOUN_MAPPING[viewpoint] pronouns = viewpoint_map.get(pronoun_type, viewpoint_map[DEFAULT_PRONOUN_TYPE]) mapped_pronoun = pronouns.get(gender, pronouns[DEFAULT_GENDER]) diff --git a/evennia/utils/verb_conjugation/tests.py b/evennia/utils/verb_conjugation/tests.py index c2d16be5f8..5a5ddf14b6 100644 --- a/evennia/utils/verb_conjugation/tests.py +++ b/evennia/utils/verb_conjugation/tests.py @@ -3,9 +3,8 @@ Unit tests for verb conjugation. """ -from django.test import TestCase from parameterized import parameterized - +from django.test import TestCase from . import conjugate, pronouns @@ -272,33 +271,55 @@ class TestVerbConjugate(TestCase): class TestPronounMapping(TestCase): """ Test pronoun viewpoint mapping - """ + @parameterized.expand( + [ + ("you", "you", "it"), # default 3rd is "neutral" + ("I", "I", "it"), + ("Me", "Me", "It"), + ("ours", "ours", "theirs"), + ("yourself", "yourself", "itself"), + ("yourselves", "yourselves", "themselves"), + ("he", "you", "he"), # assume 2nd person + ("her", "you", "her"), + ("their", "your", "their"), + ("itself", "yourself", "itself"), + ("herself", "yourself", "herself"), + ("themselves", "yourselves", "themselves"), + ] + ) + def test_default_mapping( + self, pronoun, expected_1st_or_2nd_person, expected_3rd_person + ): + """ + Test the pronoun mapper. + + """ + received_1st_or_2nd_person, received_3rd_person = pronouns.pronoun_to_viewpoints( + pronoun + ) + + self.assertEqual(expected_1st_or_2nd_person, received_1st_or_2nd_person) + self.assertEqual(expected_3rd_person, received_3rd_person) + @parameterized.expand( [ ("you", "m", "you", "he"), ("you", "f op", "you", "her"), - ("I", "", "I", "it"), - ("I", "p", "I", "it"), # plural is invalid + ("you", "p op", "you", "them"), ("I", "m", "I", "he"), ("Me", "n", "Me", "It"), ("your", "p", "your", "their"), - ("ours", "", "ours", "theirs"), - ("yourself", "", "yourself", "itself"), ("yourself", "m", "yourself", "himself"), ("yourself", "f", "yourself", "herself"), - ("yourself", "p", "yourself", "itself"), # plural is invalid ("yourselves", "", "yourselves", "themselves"), - ("he", "", "you", "he"), # assume 2nd person ("he", "1", "I", "he"), - ("he", "1 p", "we", "he"), + ("he", "1 p", "we", "he"), # royal we + ("we", "m", "we", "he"), # royal we, other way ("her", "p", "you", "her"), ("her", "pa", "your", "her"), - ("their", "pa", "your", "their"), - ("itself", "", "yourself", "itself"), - ("themselves", "", "yourselves", "themselves"), - ("herself", "", "yourself", "herself"), + ("their", "ma", "your", "their"), ] ) def test_mapping_with_options( @@ -313,3 +334,30 @@ class TestPronounMapping(TestCase): ) self.assertEqual(expected_1st_or_2nd_person, received_1st_or_2nd_person) self.assertEqual(expected_3rd_person, received_3rd_person) + + @parameterized.expand( + [ + ("you", "p", "you", "they"), + ("I", "p", "I", "they"), + ("Me", "p", "Me", "Them"), + ("your", "p", "your", "their"), + ("they", "1 p", "we", "they"), + ("they", "", "you", "they"), + ("yourself", "p", "yourself", "themselves"), + ("myself", "p", "myself", "themselves"), + ] + ) + def test_colloquial_plurals( + self, pronoun, options, expected_1st_or_2nd_person, expected_3rd_person + ): + """ + The use of this module by the funcparser expects a default person-pronoun + of the neutral "they", which is categorized here by the plural. + + """ + received_1st_or_2nd_person, received_3rd_person = pronouns.pronoun_to_viewpoints( + pronoun, options + ) + + self.assertEqual(expected_1st_or_2nd_person, received_1st_or_2nd_person) + self.assertEqual(expected_3rd_person, received_3rd_person) From 344c2dfc3b74df2bca44a39e3ee4d5eedb8cf76f Mon Sep 17 00:00:00 2001 From: InspectorCaracal Date: Wed, 16 Nov 2022 14:45:06 -0700 Subject: [PATCH 2/3] correct $pron test --- evennia/utils/tests/test_funcparser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evennia/utils/tests/test_funcparser.py b/evennia/utils/tests/test_funcparser.py index 84bb197800..03c17fc437 100644 --- a/evennia/utils/tests/test_funcparser.py +++ b/evennia/utils/tests/test_funcparser.py @@ -477,7 +477,7 @@ class TestDefaultCallables(TestCase): ("male", "Char1 smiles at himself"), ("female", "Char1 smiles at herself"), ("neutral", "Char1 smiles at itself"), - ("plural", "Char1 smiles at itself"), + ("plural", "Char1 smiles at themselves"), ] ) def test_pronoun_gender(self, gender, expected): From c0fdd5a5dbf498fd7d3aa3bca592588360fd99d8 Mon Sep 17 00:00:00 2001 From: InspectorCaracal Date: Thu, 17 Nov 2022 19:36:07 -0700 Subject: [PATCH 3/3] ran black --- evennia/utils/verb_conjugation/pronouns.py | 230 +++++---------------- evennia/utils/verb_conjugation/tests.py | 14 +- 2 files changed, 60 insertions(+), 184 deletions(-) diff --git a/evennia/utils/verb_conjugation/pronouns.py b/evennia/utils/verb_conjugation/pronouns.py index 29cbf9df5f..f7a293fda1 100644 --- a/evennia/utils/verb_conjugation/pronouns.py +++ b/evennia/utils/verb_conjugation/pronouns.py @@ -59,10 +59,7 @@ PRONOUN_MAPPING = { "neutral": "mine", "plural": "ours", }, - "reflexive pronoun": { - "neutral": "myself", - "plural": "ourselves" - } + "reflexive pronoun": {"neutral": "myself", "plural": "ourselves"}, }, "2nd person": { "subject pronoun": { @@ -80,26 +77,16 @@ PRONOUN_MAPPING = { "reflexive pronoun": { "neutral": "yourself", "plural": "yourselves", - } + }, }, "3rd person": { - "subject pronoun": { - "male": "he", - "female": "she", - "neutral": "it", - "plural": "they" - }, - "object pronoun": { - "male": "him", - "female": "her", - "neutral": "it", - "plural": "them" - }, + "subject pronoun": {"male": "he", "female": "she", "neutral": "it", "plural": "they"}, + "object pronoun": {"male": "him", "female": "her", "neutral": "it", "plural": "them"}, "possessive adjective": { "male": "his", "female": "her", "neutral": "its", - "plural": "their" + "plural": "their", }, "possessive pronoun": { "male": "his", @@ -113,166 +100,61 @@ PRONOUN_MAPPING = { "neutral": "itself", "plural": "themselves", }, - } + }, } PRONOUN_TABLE = { - "I": ( - "1st person", - ("neutral", "male", "female", "plural"), - "subject pronoun" - ), - "me": ( - "1st person", - ("neutral", "male", "female", "plural"), - "object pronoun" - ), - "my": ( - "1st person", - ("neutral", "male", "female", "plural"), - "possessive adjective" - ), - "mine": ( - "1st person", - ("neutral", "male", "female", "plural"), - "possessive pronoun" - ), - "myself": ( - "1st person", - ("neutral", "male", "female", "plural"), - "reflexive pronoun" - ), - - "we": ( - "1st person", - "plural", - "subject pronoun" - ), - "us": ( - "1st person", - "plural", - "object pronoun" - ), - "our": ( - "1st person", - "plural", - "possessive adjective" - ), - "ours": ( - "1st person", - "plural", - "possessive pronoun" - ), - "ourselves": ( - "1st person", - "plural", - "reflexive pronoun" - ), + "I": ("1st person", ("neutral", "male", "female", "plural"), "subject pronoun"), + "me": ("1st person", ("neutral", "male", "female", "plural"), "object pronoun"), + "my": ("1st person", ("neutral", "male", "female", "plural"), "possessive adjective"), + "mine": ("1st person", ("neutral", "male", "female", "plural"), "possessive pronoun"), + "myself": ("1st person", ("neutral", "male", "female", "plural"), "reflexive pronoun"), + "we": ("1st person", "plural", "subject pronoun"), + "us": ("1st person", "plural", "object pronoun"), + "our": ("1st person", "plural", "possessive adjective"), + "ours": ("1st person", "plural", "possessive pronoun"), + "ourselves": ("1st person", "plural", "reflexive pronoun"), "you": ( - "2nd person", - ("neutral", "male", "female", "plural"), - ("subject pronoun", "object pronoun") - ), - "your": ( - "2nd person", - ("neutral", "male", "female", "plural"), - "possessive adjective" - ), - "yours": ( - "2nd person", - ("neutral", "male", "female", "plural"), - "possessive pronoun" - ), - "yourself": ( - "2nd person", - ("neutral", "male", "female"), - "reflexive pronoun" - ), - "yourselves": ( - "2nd person", - "plural", - "reflexive pronoun" - ), - "he": ( - "3rd person", - "male", - "subject pronoun" - ), - "him": ( - "3rd person", - "male", - "object pronoun" - ), - "his":( - "3rd person", - "male", - ("possessive pronoun","possessive adjective"), - ), - "himself": ( - "3rd person", - "male", - "reflexive pronoun" - ), - "she": ( - "3rd person", - "female", - "subject pronoun" - ), + "2nd person", + ("neutral", "male", "female", "plural"), + ("subject pronoun", "object pronoun"), + ), + "your": ("2nd person", ("neutral", "male", "female", "plural"), "possessive adjective"), + "yours": ("2nd person", ("neutral", "male", "female", "plural"), "possessive pronoun"), + "yourself": ("2nd person", ("neutral", "male", "female"), "reflexive pronoun"), + "yourselves": ("2nd person", "plural", "reflexive pronoun"), + "he": ("3rd person", "male", "subject pronoun"), + "him": ("3rd person", "male", "object pronoun"), + "his": ( + "3rd person", + "male", + ("possessive pronoun", "possessive adjective"), + ), + "himself": ("3rd person", "male", "reflexive pronoun"), + "she": ("3rd person", "female", "subject pronoun"), "her": ( - "3rd person", - "female", - ("object pronoun", "possessive adjective"), - ), - "hers": ( - "3rd person", - "female", - "possessive pronoun" - ), - "herself": ( - "3rd person", - "female", - "reflexive pronoun" - ), + "3rd person", + "female", + ("object pronoun", "possessive adjective"), + ), + "hers": ("3rd person", "female", "possessive pronoun"), + "herself": ("3rd person", "female", "reflexive pronoun"), "it": ( - "3rd person", - "neutral", - ("subject pronoun", "object pronoun"), - ), + "3rd person", + "neutral", + ("subject pronoun", "object pronoun"), + ), "its": ( - "3rd person", - "neutral", - ("possessive pronoun", "possessive adjective"), - ), - "itself": ( - "3rd person", - "neutral", - "reflexive pronoun" - ), - "they": ( - "3rd person", - "plural", - "subject pronoun" - ), - "them": ( - "3rd person", - "plural", - "object pronoun" - ), - "their": ( - "3rd person", - "plural", - "possessive adjective" - ), - "theirs": ( - "3rd person", - "plural", - "possessive pronoun" - ), - "themselves": ( - "3rd person", - "plural", - "reflexive pronoun" - ), + "3rd person", + "neutral", + ("possessive pronoun", "possessive adjective"), + ), + "itself": ("3rd person", "neutral", "reflexive pronoun"), + "they": ("3rd person", "plural", "subject pronoun"), + "them": ("3rd person", "plural", "object pronoun"), + "their": ("3rd person", "plural", "possessive adjective"), + "theirs": ("3rd person", "plural", "possessive pronoun"), + "themselves": ("3rd person", "plural", "reflexive pronoun"), } # define the default viewpoint conversions @@ -303,9 +185,7 @@ ALIASES = { } -def pronoun_to_viewpoints( - pronoun, options=None, pronoun_type=None, gender=None, viewpoint=None -): +def pronoun_to_viewpoints(pronoun, options=None, pronoun_type=None, gender=None, viewpoint=None): """ Access function for determining the forms of a pronoun from different viewpoints. @@ -365,7 +245,7 @@ def pronoun_to_viewpoints( viewpoint = source_viewpoint if gender not in GENDERS: gender = source_gender[0] if is_iter(source_gender) else source_gender - + if options: # option string/list will override the kwargs differentiators given if isinstance(options, str): diff --git a/evennia/utils/verb_conjugation/tests.py b/evennia/utils/verb_conjugation/tests.py index 5a5ddf14b6..747d90c15c 100644 --- a/evennia/utils/verb_conjugation/tests.py +++ b/evennia/utils/verb_conjugation/tests.py @@ -275,7 +275,7 @@ class TestPronounMapping(TestCase): @parameterized.expand( [ - ("you", "you", "it"), # default 3rd is "neutral" + ("you", "you", "it"), # default 3rd is "neutral" ("I", "I", "it"), ("Me", "Me", "It"), ("ours", "ours", "theirs"), @@ -289,16 +289,12 @@ class TestPronounMapping(TestCase): ("themselves", "yourselves", "themselves"), ] ) - def test_default_mapping( - self, pronoun, expected_1st_or_2nd_person, expected_3rd_person - ): + def test_default_mapping(self, pronoun, expected_1st_or_2nd_person, expected_3rd_person): """ Test the pronoun mapper. """ - received_1st_or_2nd_person, received_3rd_person = pronouns.pronoun_to_viewpoints( - pronoun - ) + received_1st_or_2nd_person, received_3rd_person = pronouns.pronoun_to_viewpoints(pronoun) self.assertEqual(expected_1st_or_2nd_person, received_1st_or_2nd_person) self.assertEqual(expected_3rd_person, received_3rd_person) @@ -315,8 +311,8 @@ class TestPronounMapping(TestCase): ("yourself", "f", "yourself", "herself"), ("yourselves", "", "yourselves", "themselves"), ("he", "1", "I", "he"), - ("he", "1 p", "we", "he"), # royal we - ("we", "m", "we", "he"), # royal we, other way + ("he", "1 p", "we", "he"), # royal we + ("we", "m", "we", "he"), # royal we, other way ("her", "p", "you", "her"), ("her", "pa", "your", "her"), ("their", "ma", "your", "their"),