Expand pronoun tests
plural handling use source as defaults and always apply gender
This commit is contained in:
parent
81bc51fa72
commit
b5fa5726d9
2 changed files with 243 additions and 92 deletions
|
|
@ -59,7 +59,10 @@ PRONOUN_MAPPING = {
|
||||||
"neutral": "mine",
|
"neutral": "mine",
|
||||||
"plural": "ours",
|
"plural": "ours",
|
||||||
},
|
},
|
||||||
"reflexive pronoun": {"neutral": "myself", "plural": "ourselves"},
|
"reflexive pronoun": {
|
||||||
|
"neutral": "myself",
|
||||||
|
"plural": "ourselves"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"2nd person": {
|
"2nd person": {
|
||||||
"subject pronoun": {
|
"subject pronoun": {
|
||||||
|
|
@ -77,16 +80,26 @@ PRONOUN_MAPPING = {
|
||||||
"reflexive pronoun": {
|
"reflexive pronoun": {
|
||||||
"neutral": "yourself",
|
"neutral": "yourself",
|
||||||
"plural": "yourselves",
|
"plural": "yourselves",
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
"3rd person": {
|
"3rd person": {
|
||||||
"subject pronoun": {"male": "he", "female": "she", "neutral": "it", "plural": "they"},
|
"subject pronoun": {
|
||||||
"object pronoun": {"male": "him", "female": "her", "neutral": "it", "plural": "them"},
|
"male": "he",
|
||||||
|
"female": "she",
|
||||||
|
"neutral": "it",
|
||||||
|
"plural": "they"
|
||||||
|
},
|
||||||
|
"object pronoun": {
|
||||||
|
"male": "him",
|
||||||
|
"female": "her",
|
||||||
|
"neutral": "it",
|
||||||
|
"plural": "them"
|
||||||
|
},
|
||||||
"possessive adjective": {
|
"possessive adjective": {
|
||||||
"male": "his",
|
"male": "his",
|
||||||
"female": "her",
|
"female": "her",
|
||||||
"neutral": "its",
|
"neutral": "its",
|
||||||
"plural": "their",
|
"plural": "their"
|
||||||
},
|
},
|
||||||
"possessive pronoun": {
|
"possessive pronoun": {
|
||||||
"male": "his",
|
"male": "his",
|
||||||
|
|
@ -100,68 +113,173 @@ PRONOUN_MAPPING = {
|
||||||
"neutral": "itself",
|
"neutral": "itself",
|
||||||
"plural": "themselves",
|
"plural": "themselves",
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PRONOUN_TABLE = {
|
PRONOUN_TABLE = {
|
||||||
"I": ("1st person", ("neutral", "male", "female"), "subject pronoun"),
|
"I": (
|
||||||
"me": ("1st person", ("neutral", "male", "female"), "object pronoun"),
|
"1st person",
|
||||||
"my": ("1st person", ("neutral", "male", "female"), "possessive adjective"),
|
("neutral", "male", "female", "plural"),
|
||||||
"mine": ("1st person", ("neutral", "male", "female"), "possessive pronoun"),
|
"subject pronoun"
|
||||||
"myself": ("1st person", ("neutral", "male", "female"), "reflexive pronoun"),
|
),
|
||||||
"we": ("1st person", "plural", "subject pronoun"),
|
"me": (
|
||||||
"us": ("1st person", "plural", "object pronoun"),
|
"1st person",
|
||||||
"our": ("1st person", "plural", "possessive adjective"),
|
("neutral", "male", "female", "plural"),
|
||||||
"ours": ("1st person", "plural", "possessive pronoun"),
|
"object pronoun"
|
||||||
"ourselves": ("1st person", "plural", "reflexive 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": (
|
"you": (
|
||||||
"2nd person",
|
"2nd person",
|
||||||
("neutral", "male", "female", "plural"),
|
("neutral", "male", "female", "plural"),
|
||||||
("subject pronoun", "object pronoun"),
|
("subject pronoun", "object pronoun")
|
||||||
),
|
),
|
||||||
"your": ("2nd person", ("neutral", "male", "female", "plural"), "possessive adjective"),
|
"your": (
|
||||||
"yours": ("2nd person", ("neutral", "male", "female", "plural"), "possessive pronoun"),
|
"2nd person",
|
||||||
"yourself": ("2nd person", ("neutral", "male", "female"), "reflexive pronoun"),
|
("neutral", "male", "female", "plural"),
|
||||||
"yourselves": ("2nd person", "plural", "reflexive pronoun"),
|
"possessive adjective"
|
||||||
"he": ("3rd person", "male", "subject pronoun"),
|
),
|
||||||
"him": ("3rd person", "male", "object pronoun"),
|
"yours": (
|
||||||
"his": (
|
"2nd person",
|
||||||
"3rd person",
|
("neutral", "male", "female", "plural"),
|
||||||
"male",
|
"possessive pronoun"
|
||||||
("possessive pronoun", "possessive adjective"),
|
),
|
||||||
),
|
"yourself": (
|
||||||
"himself": ("3rd person", "male", "reflexive pronoun"),
|
"2nd person",
|
||||||
"she": ("3rd person", "female", "subject pronoun"),
|
("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": (
|
"her": (
|
||||||
"3rd person",
|
"3rd person",
|
||||||
"female",
|
"female",
|
||||||
("object pronoun", "possessive adjective"),
|
("object pronoun", "possessive adjective"),
|
||||||
),
|
),
|
||||||
"hers": ("3rd person", "female", "possessive pronoun"),
|
"hers": (
|
||||||
"herself": ("3rd person", "female", "reflexive pronoun"),
|
"3rd person",
|
||||||
|
"female",
|
||||||
|
"possessive pronoun"
|
||||||
|
),
|
||||||
|
"herself": (
|
||||||
|
"3rd person",
|
||||||
|
"female",
|
||||||
|
"reflexive pronoun"
|
||||||
|
),
|
||||||
"it": (
|
"it": (
|
||||||
"3rd person",
|
"3rd person",
|
||||||
"neutral",
|
"neutral",
|
||||||
("subject pronoun", "object pronoun"),
|
("subject pronoun", "object pronoun"),
|
||||||
),
|
),
|
||||||
"its": (
|
"its": (
|
||||||
"3rd person",
|
"3rd person",
|
||||||
"neutral",
|
"neutral",
|
||||||
("possessive pronoun", "possessive adjective"),
|
("possessive pronoun", "possessive adjective"),
|
||||||
),
|
),
|
||||||
"itself": ("3rd person", "neutral", "reflexive pronoun"),
|
"itself": (
|
||||||
"they": ("3rd person", "plural", "subject pronoun"),
|
"3rd person",
|
||||||
"them": ("3rd person", "plural", "object pronoun"),
|
"neutral",
|
||||||
"their": ("3rd person", "plural", "possessive adjective"),
|
"reflexive pronoun"
|
||||||
"theirs": ("3rd person", "plural", "possessive pronoun"),
|
),
|
||||||
"themselves": ("3rd person", "plural", "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
|
# define the default viewpoint conversions
|
||||||
VIEWPOINT_CONVERSION = {
|
VIEWPOINT_CONVERSION = {
|
||||||
"1st person": "3rd person",
|
"1st person": "3rd person",
|
||||||
"2nd person": "3rd person",
|
"2nd person": "3rd person",
|
||||||
"3rd person": ("1st person", "2nd person"),
|
"3rd person": ("2nd person", "1st person"),
|
||||||
}
|
}
|
||||||
|
|
||||||
ALIASES = {
|
ALIASES = {
|
||||||
|
|
@ -186,14 +304,10 @@ ALIASES = {
|
||||||
|
|
||||||
|
|
||||||
def pronoun_to_viewpoints(
|
def pronoun_to_viewpoints(
|
||||||
pronoun,
|
pronoun, options=None, pronoun_type=None, gender=None, viewpoint=None
|
||||||
options=None,
|
|
||||||
pronoun_type=DEFAULT_PRONOUN_TYPE,
|
|
||||||
gender=DEFAULT_GENDER,
|
|
||||||
viewpoint=DEFAULT_VIEWPOINT,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
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:
|
Args:
|
||||||
pronoun (str): A valid English pronoun, such as 'you', 'his', 'themselves' etc.
|
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
|
# get the default data for the input pronoun
|
||||||
source_viewpoint, source_gender, source_type = PRONOUN_TABLE[pronoun_lower]
|
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:
|
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:
|
if viewpoint not in VIEWPOINTS:
|
||||||
viewpoint = DEFAULT_VIEWPOINT
|
viewpoint = source_viewpoint
|
||||||
if gender not in GENDERS:
|
if gender not in GENDERS:
|
||||||
gender = DEFAULT_GENDER
|
gender = source_gender[0] if is_iter(source_gender) else source_gender
|
||||||
|
|
||||||
if options:
|
if options:
|
||||||
# option string/list will override the kwargs differentiators given
|
# option string/list will override the kwargs differentiators given
|
||||||
if isinstance(options, str):
|
if isinstance(options, str):
|
||||||
|
|
@ -279,19 +393,8 @@ def pronoun_to_viewpoints(
|
||||||
else:
|
else:
|
||||||
viewpoint = target_viewpoint
|
viewpoint = target_viewpoint
|
||||||
|
|
||||||
# special handling for the royal "we"
|
# by this point, gender will be a valid option from GENDERS and type/viewpoint will be validated
|
||||||
if is_iter(source_gender):
|
# step down into the mapping to get the converted pronoun
|
||||||
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
|
|
||||||
viewpoint_map = PRONOUN_MAPPING[viewpoint]
|
viewpoint_map = PRONOUN_MAPPING[viewpoint]
|
||||||
pronouns = viewpoint_map.get(pronoun_type, viewpoint_map[DEFAULT_PRONOUN_TYPE])
|
pronouns = viewpoint_map.get(pronoun_type, viewpoint_map[DEFAULT_PRONOUN_TYPE])
|
||||||
mapped_pronoun = pronouns.get(gender, pronouns[DEFAULT_GENDER])
|
mapped_pronoun = pronouns.get(gender, pronouns[DEFAULT_GENDER])
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,8 @@ Unit tests for verb conjugation.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.test import TestCase
|
|
||||||
from parameterized import parameterized
|
from parameterized import parameterized
|
||||||
|
from django.test import TestCase
|
||||||
from . import conjugate, pronouns
|
from . import conjugate, pronouns
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -272,33 +271,55 @@ class TestVerbConjugate(TestCase):
|
||||||
class TestPronounMapping(TestCase):
|
class TestPronounMapping(TestCase):
|
||||||
"""
|
"""
|
||||||
Test pronoun viewpoint mapping
|
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(
|
@parameterized.expand(
|
||||||
[
|
[
|
||||||
("you", "m", "you", "he"),
|
("you", "m", "you", "he"),
|
||||||
("you", "f op", "you", "her"),
|
("you", "f op", "you", "her"),
|
||||||
("I", "", "I", "it"),
|
("you", "p op", "you", "them"),
|
||||||
("I", "p", "I", "it"), # plural is invalid
|
|
||||||
("I", "m", "I", "he"),
|
("I", "m", "I", "he"),
|
||||||
("Me", "n", "Me", "It"),
|
("Me", "n", "Me", "It"),
|
||||||
("your", "p", "your", "their"),
|
("your", "p", "your", "their"),
|
||||||
("ours", "", "ours", "theirs"),
|
|
||||||
("yourself", "", "yourself", "itself"),
|
|
||||||
("yourself", "m", "yourself", "himself"),
|
("yourself", "m", "yourself", "himself"),
|
||||||
("yourself", "f", "yourself", "herself"),
|
("yourself", "f", "yourself", "herself"),
|
||||||
("yourself", "p", "yourself", "itself"), # plural is invalid
|
|
||||||
("yourselves", "", "yourselves", "themselves"),
|
("yourselves", "", "yourselves", "themselves"),
|
||||||
("he", "", "you", "he"), # assume 2nd person
|
|
||||||
("he", "1", "I", "he"),
|
("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", "p", "you", "her"),
|
||||||
("her", "pa", "your", "her"),
|
("her", "pa", "your", "her"),
|
||||||
("their", "pa", "your", "their"),
|
("their", "ma", "your", "their"),
|
||||||
("itself", "", "yourself", "itself"),
|
|
||||||
("themselves", "", "yourselves", "themselves"),
|
|
||||||
("herself", "", "yourself", "herself"),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_mapping_with_options(
|
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_1st_or_2nd_person, received_1st_or_2nd_person)
|
||||||
self.assertEqual(expected_3rd_person, received_3rd_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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue