Skip to content

Commit

Permalink
Merge pull request #36 from vamc19/tupl_set
Browse files Browse the repository at this point in the history
Regexp in inflect should catch closing ')' in tuples and sets
  • Loading branch information
jaraco committed Sep 23, 2018
2 parents 3cc7b26 + cb38630 commit 66f7da7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
20 changes: 10 additions & 10 deletions inflect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,42 +1477,42 @@ def inflect(self, text):
total = -1
while total:
(section, total) = subn(
r"(?x)\bplural \( ([^),]*) (, ([^)]*) )? \) ",
r"(?x)\bplural \( ([^),]*) (, ([^)]*\)*) )? \) ",
self.plmo, section)
(section, count) = subn(
r"(?x)\bplural_noun \( ([^),]*) (, ([^)]*) )? \) ",
r"(?x)\bplural_noun \( ([^),]*) (, ([^)]*\)*) )? \) ",
self.plnounmo, section)
total += count
(section, count) = subn(
r"(?x)\bplural_verb \( ([^),]*) (, ([^)]*) )? \) ",
r"(?x)\bplural_verb \( ([^),]*) (, ([^)]*\)*) )? \) ",
self.plverbmo, section)
total += count
(section, count) = subn(
r"(?x)\bplural_adj \( ([^),]*) (, ([^)]*) )? \) ",
r"(?x)\bplural_adj \( ([^),]*) (, ([^)]*\)*) )? \) ",
self.pladjmo, section)
total += count
(section, count) = subn(
r"(?x)\bsingular_noun \( ([^),]*) (, ([^)]*) )? \) ",
r"(?x)\bsingular_noun \( ([^),]*) (, ([^)]*\)*) )? \) ",
self.sinounmo, section)
total += count
(section, count) = subn(
r"(?x)\ban? \( ([^),]*) (, ([^)]*) )? \) ",
r"(?x)\ban? \( ([^),]*) (, ([^)]*\)*) )? \) ",
self.amo, section)
total += count
(section, count) = subn(
r"(?x)\bno \( ([^),]*) (, ([^)]*) )? \) ",
r"(?x)\bno \( ([^),]*) (, ([^)]*\)*) )? \) ",
self.nomo, section)
total += count
(section, count) = subn(
r"(?x)\bordinal \( ([^)]*) \) ",
r"(?x)\bordinal \( ([^)]*\)*) \) ",
self.ordinalmo, section)
total += count
(section, count) = subn(
r"(?x)\bnumber_to_words \( ([^)]*) \) ",
r"(?x)\bnumber_to_words \( ([^)]*\)*) \) ",
self.numwordsmo, section)
total += count
(section, count) = subn(
r"(?x)\bpresent_participle \( ([^)]*) \) ",
r"(?x)\bpresent_participle \( ([^)]*\)*) \) ",
self.prespartmo, section)
total += count

Expand Down
11 changes: 11 additions & 0 deletions tests/test_inflections.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ def test_prespart():
eq_(p.present_participle("skis"), "skiing")


def test_inflect_on_tuples():
p = inflect.engine()
eq_(p.inflect("plural(egg, ('a', 'b', 'c')"), "eggs")
eq_(p.inflect("plural_noun(egg, ('a', 'b', 'c'))"), "eggs")
eq_(p.inflect("plural_adj(a, ('a', 'b', 'c'))"), "some")
eq_(p.inflect("plural_verb(was, ('a', 'b', 'c'))"), "were")
eq_(p.inflect("singular_noun(eggs, ('a', 'b', 'c'))"), "eggs")
eq_(p.inflect("an(error, ('a', 'b', 'c'))"), " ('a', 'b', 'c') error")
eq_(p.inflect("number_to_words((10, 20))"), 'one thousand and twenty')


def get_data():
filename = os.path.join(os.path.dirname(__file__), 'inflections.txt')
with io.open(filename) as strm:
Expand Down

0 comments on commit 66f7da7

Please sign in to comment.