I am using python pattern to get the singular form of English nouns.
In [1]: from pattern.en import singularize
In [2]: singularize('patterns')
Out[2]: 'pattern'
In [3]: singularize('gases')
Out[3]: 'gase'
I am solving the problem in the second example by defining
def my_singularize(strn):
'''
Return the singular of a noun. Add special cases to correct pattern generic rules.
'''
exceptionDict = {'gases':'gas','spectra':'spectrum','cross':'cross','nuclei':'nucleus'}
try:
return exceptionDict[strn]
except:
return singularize(strn)
Is there a better way to do this, e.g. add to the rules of pattern, or make the exceptionDict
somehow internal to pattern?