Returns the plural of a given word. For example: stad => steden. The custom dictionary is for user-defined replacements.
(word, pos=NOUN, custom={})
| 69 | } |
| 70 | |
| 71 | def pluralize(word, pos=NOUN, custom={}): |
| 72 | """ Returns the plural of a given word. |
| 73 | For example: stad => steden. |
| 74 | The custom dictionary is for user-defined replacements. |
| 75 | """ |
| 76 | if word in custom.keys(): |
| 77 | return custom[word] |
| 78 | w = word.lower() |
| 79 | if pos == NOUN: |
| 80 | if w in plural_irregular_en: # dag => dagen |
| 81 | return w + "en" |
| 82 | if w in plural_irregular_een: # fee => feeën |
| 83 | return w + u"ën" |
| 84 | if w in plural_irregular_eren: # blad => bladeren |
| 85 | return w + "eren" |
| 86 | if w in plural_irregular_deren: # been => beenderen |
| 87 | return w + "deren" |
| 88 | if w in plural_irregular: |
| 89 | return plural_irregular[w] |
| 90 | # Words ending in -icus get -ici: academicus => academici |
| 91 | if w.endswith("icus"): |
| 92 | return w[:-2] + "i" |
| 93 | # Words ending in -s usually get -sen: les => lessen. |
| 94 | if w.endswith(("es", "as", "nis", "ris", "vis")): |
| 95 | return w + "sen" |
| 96 | # Words ending in -s usually get -zen: huis => huizen. |
| 97 | if w.endswith("s") and not w.endswith(("us", "ts", "mens")): |
| 98 | return w[:-1] + "zen" |
| 99 | # Words ending in -f usually get -ven: brief => brieven. |
| 100 | if w.endswith("f"): |
| 101 | return w[:-1] + "ven" |
| 102 | # Words ending in -um get -ums: museum => museums. |
| 103 | if w.endswith("um"): |
| 104 | return w + "s" |
| 105 | # Words ending in unstressed -ee or -ie get -ën: bacterie => bacteriën |
| 106 | if w.endswith("ie"): |
| 107 | return w + "s" |
| 108 | if w.endswith(("ee","ie")): |
| 109 | return w[:-1] + u"ën" |
| 110 | # Words ending in -heid get -heden: mogelijkheid => mogelijkheden |
| 111 | if w.endswith("heid"): |
| 112 | return w[:-4] + "heden" |
| 113 | # Words ending in -e -el -em -en -er -ie get -s: broer => broers. |
| 114 | if w.endswith((u"é", "e", "el", "em", "en", "er", "eu", "ie", "ue", "ui", "eau", "ah")): |
| 115 | return w + "s" |
| 116 | # Words ending in a vowel get 's: auto => auto's. |
| 117 | if w.endswith(VOWELS) or w.endswith("y") and not w.endswith("e"): |
| 118 | return w + "'s" |
| 119 | # Words ending in -or always get -en: motor => motoren. |
| 120 | if w.endswith("or"): |
| 121 | return w + "en" |
| 122 | # Words ending in -ij get -en: boerderij => boerderijen. |
| 123 | if w.endswith("ij"): |
| 124 | return w + "en" |
| 125 | # Words ending in two consonants get -en: hand => handen. |
| 126 | if len(w) > 1 and not is_vowel(w[-1]) and not is_vowel(w[-2]): |
| 127 | return w + "en" |
| 128 | # Words ending in one consonant with a short sound: fles => flessen. |