Returns the singular of a given word. The inflection is based on probability rather than gender and role.
(word, pos=NOUN, gender=MALE, role=SUBJECT, custom={})
| 304 | ] |
| 305 | |
| 306 | def singularize(word, pos=NOUN, gender=MALE, role=SUBJECT, custom={}): |
| 307 | """ Returns the singular of a given word. |
| 308 | The inflection is based on probability rather than gender and role. |
| 309 | """ |
| 310 | w = word.lower().capitalize() |
| 311 | if pos == NOUN: |
| 312 | for a, b in singular_inflections: |
| 313 | if w.endswith(a): |
| 314 | return w[:-len(a)] + b |
| 315 | # Default rule: strip known plural suffixes (baseline = 51%). |
| 316 | for suffix in ("nen", "en", "n", "e", "er", "s"): |
| 317 | if w.endswith(suffix): |
| 318 | return w[:-len(suffix)] |
| 319 | return w |
| 320 | return w |
| 321 | |
| 322 | #### VERB CONJUGATION ############################################################################## |
| 323 | # The verb table was trained on CELEX and contains the top 2000 most frequent verbs. |
no test coverage detected
searching dependent graphs…