(Morphodict) Replace space/- in identifiers with _

This commit is contained in:
Inari Listenmaa
2021-06-04 13:27:26 +08:00
parent d2d841e949
commit 9275d5e720

View File

@@ -163,14 +163,18 @@ mkMorphoDict env =
_ | length (nub (map tail fls)) == length fls -> shrinkMore (map tail fls) _ | length (nub (map tail fls)) == length fls -> shrinkMore (map tail fls)
_ -> fls _ -> fls
-- >>> mkFun ["hello", "world", "hello friends", "hello-all"]
mkFun = showCId . mkCId . concat . intersperse "_" -- "hello_world_hello_friends_hello_all"
mkFun :: [String] -> String -- if word contains space or hyphen, replace with underscore
mkFun = showCId . mkCId . concat . intersperse "_" . concatMap (words . removeHyphen)
where
removeHyphen [] = []
removeHyphen ['-'] = ['-'] -- If hyphen is the last character, it's usually meaningful, leave it
removeHyphen ('-':cs) = ' ' : removeHyphen cs
removeHyphen (c:cs) = c : removeHyphen cs
quote s = "\"" ++ s ++ "\"" quote s = "\"" ++ s ++ "\""
{- ---- let us ignore this {- ---- let us ignore this
findCompounds :: [RuleData] -> [RuleData] findCompounds :: [RuleData] -> [RuleData]
findCompounds = getCompounds . sortOn cat_orthrevforms findCompounds = getCompounds . sortOn cat_orthrevforms