MCPcopy Index your code
hub / github.com/clips/pattern / singularize

Function singularize

pattern/text/en/inflect.py:590–624  ·  view source on GitHub ↗

Returns the singular of a given word.

(word, pos=NOUN, custom={})

Source from the content-addressed store, hash-verified

588}
589
590def singularize(word, pos=NOUN, custom={}):
591 """ Returns the singular of a given word.
592 """
593 if word in custom.keys():
594 return custom[word]
595 # Recurse compound words (e.g. mothers-in-law).
596 if "-" in word:
597 w = word.split("-")
598 if len(w) > 1 and w[1] in plural_prepositions:
599 return singularize(w[0], pos, custom)+"-"+"-".join(w[1:])
600 # dogs' => dog's
601 if word.endswith("'"):
602 return singularize(word[:-1]) + "'s"
603 w = word.lower()
604 for x in singular_uninflected:
605 if x.endswith(w):
606 return word
607 for x in singular_uncountable:
608 if x.endswith(w):
609 return word
610 for x in singular_ie:
611 if w.endswith(x+"s"):
612 return w
613 for x in singular_irregular.keys():
614 if w.endswith(x):
615 return re.sub('(?i)'+x+'$', singular_irregular[x], word)
616 for suffix, inflection in singular_rules:
617 m = suffix.search(word)
618 g = m and m.groups() or []
619 if m:
620 for k in range(len(g)):
621 if g[k] is None:
622 inflection = inflection.replace('\\' + str(k + 1), '')
623 return suffix.sub(inflection, word)
624 return word
625
626#### VERB CONJUGATION ##############################################################################
627

Callers 2

find_lemmataFunction · 0.90
01-inflect.pyFile · 0.90

Calls 5

lenFunction · 0.85
strFunction · 0.85
keysMethod · 0.45
splitMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…