module Language.English.Plural where
import Data.Map (Map)
import Text.Regex.TDFA
import qualified Data.Map as M
plural :: String -> String
plural xs = do
let ys = M.filterWithKey (\k _ -> xs =~ k :: Bool) pluralKnowledge
case M.minViewWithKey ys of
Just ((k, a), _) ->
do
let (before, match, _) = xs =~ k :: (String, String, String)
if a =~ "^\\\\&" :: Bool
then do
let (_, _, s) = a =~ "^\\\\&" :: (String,String,String)
before ++ match ++ s
else before ++ a
Nothing -> xs
tryPlural :: Int -> String -> String
tryPlural n s
| n `elem` [0, 1] = s
| otherwise = plural s
pluralKnowledge :: Map String String
pluralKnowledge =
M.fromAscList
[("ss$", "sses")
,("zz$", "zzes")
,("sh$", "shes")
,("tch$", "tches")
,("eaf$", "eaves")
,("ief$", "ieves")
,("roof$", "roofs")
,("oof$", "ooves")
,("ife$", "ives")
,("lf$", "lves")
,("[aeiou]y$", "\\&s")
,("ndum$", "nda")
,("um$", "a")
,("^die$", "dice")
,("dogma$", "dogmas")
,("lemma$", "lemmas")
,("schema$", "schemas")
,("ia$", "ium")
,("ma$", "mata")
,("na$", "nae")
,("ta$", "tum")
,("Atlas$", "Atlantes")
,("atlas$", "atlases")
,("Harry$", "Harrys")
,("aircraft$", "aircraft")
,("alga$", "algae")
,("alumna$", "alumnae")
,("alumnus$", "alumni")
,("ameoba$", "ameobae")
,("automaton$", "automata")
,("bacillus$", "bacilli")
,("banjo$", "banjos")
,("beau$", "beaux")
,("cactus$", "cacti")
,("cannon$", "cannon")
,("canto$", "cantos")
,("cargo$", "cargos")
,("cattle$", "cattle")
,("child$", "children")
,("cod$", "cod")
,("corpus$", "corpora")
,("dwarf$", "dwarves")
,("cs$", "csen")
,("foot$", "feet")
,("formula$", "formulae")
,("graffito$", "graffiti")
,("rion$", "ria")
,("deer$", "deer")
,("focus$", "foci")
,("genus$", "genera")
,("goose$", "geese")
,("hedron$", "hedra")
,("hippopotamus$", "hippopotami")
,("insigne$", "insignia")
,("life$", "lives")
,("louse$", "lice")
,("mackerel$", "mackerel")
,("man$", "men")
,("matrix$", "matrices")
,("moose$", "moose")
,("motto$", "mottos")
,("mouse$", "mice")
,("nucleus$", "nuclei")
,("octopus$", "octopi")
,("offspring", "offspring")
,("opus$", "opera")
,("\\box$", "oxen")
,("panino$", "panini")
,("paparazzo$", "paparazzi")
,("phalanx$", "phalanges")
,("phenomenon$", "phenomena")
,("people$", "people")
,("perch$", "perch")
,("piano$", "pianos")
,("police$", "police")
,("portico$", "porticos")
,("quarto$", "quartos")
,("radius$", "radii")
,("rhinoceros$", "rhinoceri")
,("sheep$", "sheep")
,("solo$", "solos")
,("syllabus$", "syllabi")
,("terminus$", "termini")
,("ulus$", "uli")
,("trout$", "trout")
,("tooth$", "teeth")
,("uterus$", "uteri")
,("virtuoso", "virtuosi")
,("viscus$", "viscera")
,("is$", "es")
,("us$", "uses")
,("io$", "ios")
,("oo$", "oos")
,("o$", "oes")
,("y$", "ies")
,("[ei]x$", "ices")
,("x$", "xes")
,("[^s]$", "\\&s")]