Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle units containing 'degree' and 'per' correctly #56

Merged
merged 5 commits into from Oct 21, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions inflect.py
Expand Up @@ -1894,6 +1894,18 @@ def _plnoun(self, word, count=None):
lowersplit[:numword - 1] +
[self._plnoun(lowersplit[numword - 1], 2)] + lowersplit[numword:])

# Handle units given in degrees
if len(lowersplit) >= 2 and lowersplit[0] in ['degree']:
return ' '.join(
[self._plnoun(lowersplit[0])] + lowersplit[1:]
)
# 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(lowerword[:index]),
lowerword[index:])

lowersplit = lowerword.split('-')
if len(lowersplit) >= 3:
for numword in range(1, len(lowersplit) - 1):
Expand Down
59 changes: 48 additions & 11 deletions tests/test_compounds.py
Expand Up @@ -2,19 +2,56 @@

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 fahrenheit': 'degrees fahrenheit',
'degree rankine': 'degrees rankine'
}
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',
'pound-force per square inch': 'pound-forces per square inch',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad example, I think the real plural is something like "pounds-force per square inch"!

Copy link
Contributor Author

@nielstron nielstron Sep 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I think this is correct:
"pound-force (plural pound-forces)" from Wiktionary

I do agree though that at first sight this does not sound correct...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the Oxford English Dictionary:

image

None of the other 10 dictionaries I checked show a plural form at all.

Google Books has 66 results for "pounds force per inch".

But only two results for "pound forces per inch".

The plural form on Wiktionary was added when the en-noun template was simply added, without taking care of the special-case plural:

{{en-noun|head=[[pound]]-[[force]]}}

https://en.wiktionary.org/w/index.php?title=pound-force&diff=13830692&oldid=13487437

I've fixed Wiktionary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metric is so much easier :)

Copy link
Contributor Author

@nielstron nielstron Sep 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, fixed pluralization of 'pound-force' (and 'pound-weight' I hope) too

'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'
}
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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big C in "Celsius"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs #55 then to be merged into master to work.

}
for singular, plural in test_cases.items():
eq_(p.plural(singular), plural)