Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Feb 1, 2022
2 parents a70d5e2 + 6733e57 commit 27bfdbd
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 37 deletions.
41 changes: 22 additions & 19 deletions CHANGES.rst
Expand Up @@ -93,13 +93,13 @@ v2.0.0
on regular expressions. This also adds support for keyword arguments and
built-in constants when calling functions in the string.
Unfortunately, this is not backwards compatible in some cases:
* Strings should now be wrapped in single or double quotes
p.inflect("singular_noun(to them)") should now be p.inflect("singular_noun('to them')")
* Empty second argument to a function will now be parsed as None instead of ''.
p.inflect("num(%d,) eggs" % 2) now prints "2 eggs" instead of " eggs"
Since None, True and False are now supported, they can be passed explicitly:
p.inflect("num(%d, False) eggs" % 2) will print " eggs"
p.inflect("num(%d, True) eggs" % 2) will print "2 eggs"
* Strings should now be wrapped in single or double quotes
p.inflect("singular_noun(to them)") should now be p.inflect("singular_noun('to them')")
* Empty second argument to a function will now be parsed as None instead of ''.
p.inflect("num(%d,) eggs" % 2) now prints "2 eggs" instead of " eggs"
Since None, True and False are now supported, they can be passed explicitly:
p.inflect("num(%d, False) eggs" % 2) will print " eggs"
p.inflect("num(%d, True) eggs" % 2) will print "2 eggs"

v1.0.2
======
Expand Down Expand Up @@ -127,7 +127,7 @@ v0.3.1
v0.3.0
======

* Moved hosting to `jazzband <https://github.com/jazzband/inflect>`_.
* Moved hosting to the `jazzband project on GitHub <https://github.com/jazzband/inflect>`_.

v0.2.5
======
Expand All @@ -146,7 +146,7 @@ v0.2.4
v0.2.3
======

* fix a/an for dishonor, Honolulu, mpeg, onetime, Ugandan, Ukranian,
* fix a/an for dishonor, Honolulu, mpeg, onetime, Ugandan, Ukrainian,
Unabomber, unanimous, US
* merge in 'subspecies' fix by UltraNurd
* add arboretum to classical plurals
Expand All @@ -172,33 +172,40 @@ v0.2.0
======

* add gender() to select the gender of singular pronouns
* replace short named methods with longer methods. shorted method now print a message and raise DecrecationWarning

* replace short named methods with longer methods. shorted method now print a message and rasie DecrecationWarning
pl -> plural

plnoun -> plural_noun

plverb -> plural_verb

pladj -> plural_adjective

sinoun -> singular_noun

prespart -> present_participle

numwords -> number_to_words

plequal -> compare

plnounequal -> compare_nouns

plverbequal -> compare_verbs
pladjequal -> compare_adjs
wordlist -> join

pladjequal -> compare_adjs

wordlist -> join
* change classical() to only accept keyword args: only one way to do it

* fix bug in numwords where hundreds was giving the wrong number when group=3


v0.1.8
======

* add line to setup showing that this provides 'inflect' so that
inflect_dj can require it

inflect_dj can require it
* add the rest of the tests from the Perl version


Expand All @@ -212,13 +219,9 @@ v0.1.6
======

* add method sinoun() to generate the singular of a plural noun. Phew!

* add changes from new Perl version: 1.892

* start adding tests from Perl version

* add test to check sinoun(plnoun(word)) == word
Can now use word lists to check these methods without needing to have
a list of plurals. ;-)

* fix die -> dice
46 changes: 34 additions & 12 deletions inflect.py
Expand Up @@ -50,7 +50,7 @@

import ast
import re
from typing import Dict, Union, Optional, Iterable, List, Match, Tuple, Callable
from typing import Dict, Union, Optional, Iterable, List, Match, Tuple, Callable, Sequence


class UnknownClassicalModeError(Exception):
Expand Down Expand Up @@ -204,7 +204,6 @@ def make_pl_si_lists(
"jerry": "jerries",
"mary": "maries",
"talouse": "talouses",
"blouse": "blouses",
"rom": "roma",
"carmen": "carmina",
}
Expand Down Expand Up @@ -846,6 +845,19 @@ def make_pl_si_lists(
pl_sb_U_man_mans_caps_bysize,
) = make_pl_si_lists(pl_sb_U_man_mans_caps_list, "s", None, dojoinstem=False)

# UNCONDITIONAL "..louse" -> "..lice"
pl_sb_U_louse_lice_list = (
"booklouse",
"grapelouse",
"louse",
"woodlouse"
)

(
si_sb_U_louse_lice_list,
si_sb_U_louse_lice_bysize,
pl_sb_U_louse_lice_bysize,
) = make_pl_si_lists(pl_sb_U_louse_lice_list, "lice", 5, dojoinstem=False)

pl_sb_uninflected_s_complete = [
# PAIRS OR GROUPS SUBSUMED TO A SINGULAR...
Expand Down Expand Up @@ -1414,6 +1426,7 @@ def make_pl_si_lists(
"quiches",
"stomachaches",
"toothaches",
"tranches",
)

si_sb_xes_xe = ("annexes", "axes", "deluxes", "pickaxes")
Expand Down Expand Up @@ -1849,6 +1862,7 @@ def get_si_pron(thecase, word, gender):
12: "th",
13: "th",
}
nth_suff = set(nth.values())

ordinal = dict(
ty="tieth",
Expand Down Expand Up @@ -2072,7 +2086,7 @@ def defadj(self, singular: str, plural: str) -> int:

def defa(self, pattern: str) -> int:
"""
Define the indefinate article as 'a' for words matching pattern.
Define the indefinite article as 'a' for words matching pattern.
"""
self.checkpat(pattern)
Expand All @@ -2081,7 +2095,7 @@ def defa(self, pattern: str) -> int:

def defan(self, pattern: str) -> int:
"""
Define the indefinate article as 'an' for words matching pattern.
Define the indefinite article as 'an' for words matching pattern.
"""
self.checkpat(pattern)
Expand Down Expand Up @@ -2133,7 +2147,7 @@ def classical(self, **kwargs):
By default all classical modes are off except names.
unknown value in args or key in kwargs rasies
unknown value in args or key in kwargs raises
exception: UnknownClasicalModeError
"""
Expand Down Expand Up @@ -2687,7 +2701,7 @@ def _plnoun( # noqa: C901
# HANDLE PRONOUNS

for k, v in pl_pron_acc_keys_bysize.items():
if word.lower[-k:] in v: # ends with accusivate pronoun
if word.lower[-k:] in v: # ends with accusative pronoun
for pk, pv in pl_prep_bysize.items():
if word.lower[:pk] in pv: # starts with a prep
if word.lower.split() == [word.lower[:pk], word.lower[-k:]]:
Expand Down Expand Up @@ -2746,7 +2760,10 @@ def _plnoun( # noqa: C901
if word.lower[-5:] == "mouse":
return f"{word[:-5]}mice"
if word.lower[-5:] == "louse":
return f"{word[:-5]}lice"
v = pl_sb_U_louse_lice_bysize.get(len(word))
if v and word.lower in v:
return f"{word[:-5]}lice"
return f"{word}s"
if word.lower[-5:] == "goose":
return f"{word[:-5]}geese"
if word.lower[-5:] == "tooth":
Expand Down Expand Up @@ -3123,7 +3140,7 @@ def _sinoun( # noqa: C901
# HANDLE PRONOUNS

for k, v in si_pron_acc_keys_bysize.items():
if words.lower[-k:] in v: # ends with accusivate pronoun
if words.lower[-k:] in v: # ends with accusative pronoun
for pk, pv in pl_prep_bysize.items():
if words.lower[:pk] in pv: # starts with a prep
if words.lower.split() == [words.lower[:pk], words.lower[-k:]]:
Expand Down Expand Up @@ -3183,7 +3200,9 @@ def _sinoun( # noqa: C901
if words.lower[-4:] == "mice":
return word[:-4] + "mouse"
if words.lower[-4:] == "lice":
return word[:-4] + "louse"
v = si_sb_U_louse_lice_bysize.get(len(word))
if v and words.lower in v:
return word[:-4] + "louse"
if words.lower[-5:] == "geese":
return word[:-5] + "goose"
if words.lower[-5:] == "teeth":
Expand Down Expand Up @@ -3707,7 +3726,10 @@ def number_to_words( # noqa: C901
else:
sign = ""

myord = num[-2:] in ("st", "nd", "rd", "th")
if num in nth_suff:
num = zero

myord = num[-2:] in nth_suff
if myord:
num = num[:-2]
finalpoint = False
Expand Down Expand Up @@ -3774,7 +3796,7 @@ def number_to_words( # noqa: C901
if finalpoint:
numchunks.append(decimal)

# wantlist: Perl list context. can explictly specify in Python
# wantlist: Perl list context. can explicitly specify in Python
if wantlist:
if sign:
numchunks = [sign] + numchunks
Expand Down Expand Up @@ -3803,7 +3825,7 @@ def number_to_words( # noqa: C901

def join(
self,
words: Optional[List[str]],
words: Optional[Sequence[str]],
sep: Optional[str] = None,
sep_spaced: bool = True,
final_sep: Optional[str] = None,
Expand Down
3 changes: 3 additions & 0 deletions tests/inflections.txt
Expand Up @@ -2,6 +2,7 @@
TODO:sing a -> some # INDEFINITE ARTICLE
TODO: A.C.R.O.N.Y.M. -> A.C.R.O.N.Y.M.s
abscissa -> abscissas|abscissae
accomplice -> accomplices
Achinese -> Achinese
acropolis -> acropolises
adieu -> adieus|adieux
Expand Down Expand Up @@ -679,6 +680,7 @@
sinus -> sinuses|sinus
size -> sizes
sizes -> size #VERB FORM
slice -> slices
smallpox -> smallpox
Smith -> Smiths
TODO:siverb snowshoes -> snowshoe
Expand Down Expand Up @@ -779,6 +781,7 @@
trapezium -> trapeziums|trapezia
trauma -> traumas|traumata
travois -> travois
tranche -> tranches
trellis -> trellises
TODO:siverb tries -> try
trilby -> trilbys
Expand Down
2 changes: 1 addition & 1 deletion tests/test_an.py
Expand Up @@ -14,7 +14,7 @@ def test_an():
assert p.an("mpeg") == "an mpeg"
assert p.an("onetime holiday") == "a onetime holiday"
assert p.an("Ugandan person") == "a Ugandan person"
assert p.an("Ukranian person") == "a Ukranian person"
assert p.an("Ukrainian person") == "a Ukrainian person"
assert p.an("Unabomber") == "a Unabomber"
assert p.an("unanimous decision") == "a unanimous decision"
assert p.an("US farmer") == "a US farmer"
Expand Down
6 changes: 6 additions & 0 deletions tests/test_numwords.py
Expand Up @@ -391,3 +391,9 @@ def go(p, i):

# eq_ !eval { p.number_to_words(42, and=>); 1; };
# eq_ $@ =~ 'odd number of';


def test_issue_131():
p = inflect.engine()
for nth_word in inflect.nth_suff:
assert p.number_to_words(nth_word) == "zero"
10 changes: 5 additions & 5 deletions tests/test_pwd.py
Expand Up @@ -627,7 +627,7 @@ def test__plnoun(self):
p._sinoun(plur), sing, msg='p._sinoun("{}") != "{}"'.format(plur, sing)
)

# words where forming singular is ambiguious or not attempted
# words where forming singular is ambiguous or not attempted
for sing, plur in (
("son of a gun", "sons of guns"),
("son-of-a-gun", "sons-of-guns"),
Expand Down Expand Up @@ -687,7 +687,7 @@ def test__plnoun(self):

# p.classical(0)
# p.classical('names')
# clasical now back to the default mode
# classical now back to the default mode

def test_classical_pl(self):
p = inflect.engine()
Expand Down Expand Up @@ -1121,15 +1121,15 @@ def test_wordlist(self):
)
self.assertEqual(
wordlist(("apple", "banana", "carrot"), conj="&"), "apple, banana, & carrot"
) # TODO: want space here. Done, report updtream
) # TODO: want space here. Done, report upstream
self.assertEqual(
wordlist(("apple", "banana", "carrot"), conj="&", conj_spaced=False),
"apple, banana,&carrot",
) # TODO: want space here. Done, report updtream
) # TODO: want space here. Done, report upstream
self.assertEqual(
wordlist(("apple", "banana", "carrot"), conj=" &", conj_spaced=False),
"apple, banana, &carrot",
) # TODO: want space here. Done, report updtream
) # TODO: want space here. Done, report upstream

def test_print(self):
inflect.STDOUT_ON = True
Expand Down

0 comments on commit 27bfdbd

Please sign in to comment.