Skip to content

Commit

Permalink
Merge pull request #188 from paul2048/main
Browse files Browse the repository at this point in the history
Handle "pair of x" when x in `pl_sb_uninflected_complete`
  • Loading branch information
jaraco authored Aug 13, 2023
2 parents d63dd3a + 41cd8d6 commit 7bae6d0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
38 changes: 31 additions & 7 deletions inflect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2679,6 +2679,8 @@ def _plnoun( # noqa: C901
word = Words(word)

if word.last.lower() in pl_sb_uninflected_complete:
if len(word.split_) >= 3:
return self._handle_long_compounds(word, count=2) or word
return word

if word in pl_sb_uninflected_caps:
Expand Down Expand Up @@ -2707,13 +2709,9 @@ def _plnoun( # noqa: C901
)

if len(word.split_) >= 3:
for numword in range(1, len(word.split_) - 1):
if word.split_[numword] in pl_prep_list_da:
return " ".join(
word.split_[: numword - 1]
+ [self._plnoun(word.split_[numword - 1], 2)]
+ word.split_[numword:]
)
handled_words = self._handle_long_compounds(word, count=2)
if handled_words is not None:
return handled_words

# only pluralize denominators in units
mo = DENOMINATOR.search(word.lowered)
Expand Down Expand Up @@ -2972,6 +2970,30 @@ def _handle_prepositional_phrase(cls, phrase, transform, sep):
parts[: pivot - 1] + [sep.join([transformed, parts[pivot], ''])]
) + " ".join(parts[(pivot + 1) :])

def _handle_long_compounds( # noqa: C901
self, word: Words, count: int
) -> Union[str, None]:
"""
Handles the plural and singular for compound `Words`s that
have three or more words, based on the given count.
>>> engine()._handle_long_compounds(Words("pair of scissors"), 2)
'pairs of scissors'
>>> engine()._handle_long_compounds(Words("men beyond hills"), 1)
'man beyond hills'
"""
if len(word.split_) < 3:
raise ValueError("Connot handle `Words`s shorter than 3 words")

function = self._sinoun if count == 1 else self._plnoun
for numword in range(1, len(word.split_) - 1):
if word.split_[numword] in pl_prep_list_da:
return " ".join(
word.split_[: numword - 1]
+ [function(word.split_[numword - 1], count)]
+ word.split_[numword:]
)

@staticmethod
def _find_pivot(words, candidates):
pivots = (
Expand Down Expand Up @@ -3165,6 +3187,8 @@ def _sinoun( # noqa: C901
words = Words(word)

if words.last.lower() in pl_sb_uninflected_complete:
if len(words.split_) >= 3:
return self._handle_long_compounds(words, count=1) or word
return word

if word in pl_sb_uninflected_caps:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/188.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Now handle 'pair of x' in pl_sb_uninflected_complete
2 changes: 2 additions & 0 deletions tests/inflections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@
scarf -> scarves
schema -> schemas|schemata
scissors -> scissors
pair of scissors -> pairs of scissors
pair of slippers -> pairs of slippers
Scotsman -> Scotsmen
sea-bass -> sea-bass
seaman -> seamen
Expand Down

0 comments on commit 7bae6d0

Please sign in to comment.