Skip to content

Commit

Permalink
Merge 7a956e8 into 473d084
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Sep 27, 2018
2 parents 473d084 + 7a956e8 commit 12c57fb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
15 changes: 15 additions & 0 deletions inflect.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ def make_pl_si_lists(lst, plending, siendingsize, dojoinstem=True):
pl_sb_postfix_adj = {
'general': [r'(?!major|lieutenant|brigadier|adjutant|.*star)\S+'],
'martial': ['court'],
'force': ['pound']
}

for k in list(pl_sb_postfix_adj.keys()):
Expand Down Expand Up @@ -1894,6 +1895,20 @@ def _plnoun(self, word, count=None):
lowersplit[:numword - 1] +
[self._plnoun(lowersplit[numword - 1], 2)] + lowersplit[numword:])

# only pluralize denominators in units
mo = search(r'(?P<denominator>.+)( (%s) .+)' % '|'.join(['per', 'a']), lowerword)
if mo:
index = len(mo.group('denominator'))
return '{}{}'.format(self._plnoun(word[:index]),
word[index:])

# handle units given in degrees (only accept if there is no more than one word following)
# degree Celsius => degrees Celsius but degree fahrenheit hour => degree fahrenheit hours
if len(lowersplit) >= 2 and lowersplit[-2] in ['degree']:
return ' '.join(
[self._plnoun(lowersplit[0])] + lowersplit[1:]
)

lowersplit = lowerword.split('-')
if len(lowersplit) >= 3:
for numword in range(1, len(lowersplit) - 1):
Expand Down
64 changes: 53 additions & 11 deletions tests/test_compounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,61 @@

import inflect

p = inflect.engine()

class TestCompounds(object):
def setup(self):
self.p = inflect.engine()

def test_compound_1(self):
eq_(self.p.singular_noun('hello-out-there'), 'hello-out-there')
def test_compound_1():
eq_(p.singular_noun('hello-out-there'), 'hello-out-there')

def test_compound_2(self):
eq_(self.p.singular_noun('hello out there'), 'hello out there')

def test_compound_3(self):
eq_(self.p.singular_noun('continue-to-operate'), 'continue-to-operate')
def test_compound_2():
eq_(p.singular_noun('hello out there'), 'hello out there')

def test_compound_4(self):
eq_(self.p.singular_noun('case of diapers'), 'case of diapers')

def test_compound_3():
eq_(p.singular_noun('continue-to-operate'), 'continue-to-operate')


def test_compound_4():
eq_(p.singular_noun('case of diapers'), 'case of diapers')


def test_unit_handling_degree():
test_cases = {
'degree celsius': 'degrees celsius',
# 'degree Celsius': 'degrees Celsius',
'degree fahrenheit': 'degrees fahrenheit',
'degree rankine': 'degrees rankine',
'degree fahrenheit second': 'degree fahrenheit seconds'
}
for singular, plural in test_cases.items():
eq_(p.plural(singular), plural)


def test_unit_handling_fractional():
test_cases = {
'pound per square inch': 'pounds per square inch',
'metre per second': 'metres per second',
'kilometre per hour': 'kilometres per hour',
'cubic metre per second': 'cubic metres per second',
'dollar a year': 'dollars a year',
# Correct pluralization of denominator
'foot per square second': 'feet per square second',
'mother-in-law per lifetime': 'mothers-in-law per lifetime',
'pound-force per square inch': 'pounds-force per square inch',
}
for singular, plural in test_cases.items():
eq_(p.plural(singular), plural)


def test_unit_handling_combined():
test_cases = {
# Heat transfer coefficient unit
'watt per square meter degree celsius': 'watts per square meter degree celsius',
'degree celsius per hour': 'degrees celsius per hour',
'degree fahrenheit hour square foot per btuit inch': 'degree fahrenheit hour square feet per btuit inch',
# 'degree Celsius per hour': 'degrees Celsius per hour',
# 'degree Fahrenheit hour square foot per BtuIT inch': 'degree Fahrenheit hour square feet per BtuIT inch'
}
for singular, plural in test_cases.items():
eq_(p.plural(singular), plural)

0 comments on commit 12c57fb

Please sign in to comment.