Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
modelgen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
modelgen
Commits
6e90f2f1
Commit
6e90f2f1
authored
12 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added English inflector.
parent
44d57774
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
singplur.py
+78
-0
78 additions, 0 deletions
singplur.py
tests/test_singplur.py
+29
-0
29 additions, 0 deletions
tests/test_singplur.py
with
107 additions
and
0 deletions
singplur.py
0 → 100644
+
78
−
0
View file @
6e90f2f1
import
re
SINGULARS
=
(
(
r
'
ives
'
,
'
ife
'
),
(
r
'
ves
'
,
'
f
'
),
(
r
'
zes
'
,
''
),
(
r
'
men
'
,
'
man
'
),
(
r
'
matrices
'
,
'
matrix
'
),
(
r
'
([aeiou])ys
'
,
'
\\
1y
'
),
(
r
'
([^aeiou])ies
'
,
'
\\
1y
'
),
(
r
'
([^aeiou])ices$
'
,
'
\\
1ice
'
),
(
r
'
ices
'
,
'
ex
'
),
(
r
'
([sxz]|[cs]h)es$
'
,
'
\\
1
'
),
(
r
'
eet
'
,
'
oot
'
),
(
r
'
ies
'
,
'
y
'
),
(
r
'
i
'
,
'
us
'
),
(
r
'
s
'
,
''
),
)
PLURALS
=
(
(
r
'
man$
'
,
'
men
'
),
(
r
'
([aeiou]y)
'
,
'
\\
1s
'
),
(
r
'
([^aeiou])y
'
,
'
\\
1ies
'
),
(
r
'
([sxz]|[cs]h)
'
,
'
\\
1es
'
),
(
r
'
(cello|disco|hairdo|logo|patio|photo|piano|radio|chef|cliff|ref|roof)
'
,
'
\\
1s
'
),
(
r
'
o
'
,
'
oes
'
),
(
r
'
fe
'
,
'
ves
'
),
(
r
'
eaf
'
,
'
eaves
'
),
(
r
'
[ei]x
'
,
'
ices
'
),
(
r
'
us
'
,
'
i
'
),
(
r
''
,
'
s
'
),
)
EXCEPTIONS_SINGULAR
=
{
'
person
'
:
'
people
'
,
'
child
'
:
'
children
'
,
'
ox
'
:
'
oxen
'
,
'
foot
'
:
'
feet
'
,
'
tooth
'
:
'
teeth
'
,
'
goose
'
:
'
geese
'
,
'
mouse
'
:
'
mice
'
,
'
louse
'
:
'
lice
'
,
'
man
'
:
'
men
'
,
'
woman
'
:
'
women
'
,
'
goose
'
:
'
geese
'
,
}
EXCEPTIONS_PLURAL
=
dict
([
p
[::
-
1
]
for
p
in
EXCEPTIONS_SINGULAR
.
iteritems
()])
SAME
=
(
'
equipment
'
,
'
information
'
,
'
rice
'
,
'
money
'
,
'
species
'
,
'
series
'
,
'
fish
'
,
'
sheep
'
,
'
deer
'
,
'
tuna
'
,
'
salmon
'
,
'
trout
'
)
def
apply_rules
(
word
,
rules
):
word
=
word
.
strip
()
if
word
in
SAME
:
return
word
for
pattern
,
replacement
in
rules
:
word
,
n
=
re
.
subn
(
pattern
+
'
$
'
,
replacement
,
word
)
if
n
:
break
return
word
def
singularize
(
word
):
if
word
in
EXCEPTIONS_PLURAL
:
return
EXCEPTIONS_PLURAL
[
word
]
return
apply_rules
(
word
,
SINGULARS
)
def
pluralize
(
word
):
if
word
in
EXCEPTIONS_SINGULAR
:
return
EXCEPTIONS_SINGULAR
[
word
]
return
apply_rules
(
word
,
PLURALS
)
This diff is collapsed.
Click to expand it.
tests/test_singplur.py
0 → 100644
+
29
−
0
View file @
6e90f2f1
from
unittest
import
TestCase
from
singplur
import
singularize
,
pluralize
class
SingplurTest
(
TestCase
):
pairs
=
(
(
'
branch
'
,
'
branches
'
),
(
'
payment
'
,
'
payments
'
),
(
'
order
'
,
'
orders
'
),
(
'
party
'
,
'
parties
'
),
(
'
knife
'
,
'
knives
'
),
(
'
roof
'
,
'
roofs
'
),
(
'
leaf
'
,
'
leaves
'
),
(
'
box
'
,
'
boxes
'
),
(
'
sheep
'
,
'
sheep
'
),
(
'
salmon
'
,
'
salmon
'
),
(
'
person
'
,
'
people
'
),
(
'
shoe
'
,
'
shoes
'
),
(
'
foot
'
,
'
feet
'
),
(
'
dice
'
,
'
dices
'
),
)
def
test_singularize
(
self
):
for
singular
,
plural
in
self
.
pairs
:
self
.
assertEqual
(
singularize
(
plural
),
singular
)
def
test_pluralize
(
self
):
for
singular
,
plural
in
self
.
pairs
:
self
.
assertEqual
(
pluralize
(
singular
),
plural
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment