forked from GitHub/gf-rgl
Pinyin files using diacritics instead of numbers
This commit is contained in:
@@ -12,12 +12,12 @@ main = do
|
||||
pinyinFile = "pinyin.txt"
|
||||
|
||||
resModules = [mo | mo <-
|
||||
["DictEng","Extra","Lexicon", "Numeral", "Paradigms","Res", "Structural","Symbol"]
|
||||
["Extra","Lexicon", "Numeral", "Paradigms","Res", "Structural","Symbol"]
|
||||
]
|
||||
|
||||
mkPinyin ma mo = do
|
||||
s <- readFile mo
|
||||
writeFile (mo ++ "-cmn") (useMapGF ma s)
|
||||
s <- readFile ("../" ++ mo ++ "Chi.gf")
|
||||
writeFile ("tmp/" ++ mo ++ "Chi.gf") (useMapGF ma s)
|
||||
|
||||
|
||||
--import Pinyin (c2pMap, useMapGF, mkList)
|
||||
@@ -46,7 +46,38 @@ useMapGF m s = case s of
|
||||
where
|
||||
convert cs = case cs of
|
||||
'"':s -> '"' : useMapGF m s
|
||||
c :s -> maybe [c] (head . words) (Map.lookup [c] m) ++ convert s
|
||||
c :s -> maybe [c] (tone2tone . head . words) (Map.lookup [c] m) ++ convert s
|
||||
_ -> cs
|
||||
|
||||
c2pMap ws = Map.fromList [(c,unwords ps) | (_,(c,ps)) <- ws]
|
||||
|
||||
-- from numeric tones to diacritics
|
||||
tone2tone :: String -> String
|
||||
tone2tone = combine . change . analyse where
|
||||
analyse :: String -> [String] -- four parts: ch,a,ng,1
|
||||
analyse s = case reverse s of
|
||||
i:'r': v:x | elem i "1234" -> [reverse x,[v],"r", [i]]
|
||||
i:'n': v:x | elem i "1234" -> [reverse x,[v],"n", [i]]
|
||||
i:'g':'n':v:x | elem i "1234" -> [reverse x,[v],"ng",[i]]
|
||||
i: v:x | elem i "1234" -> [reverse x,[v],"", [i]]
|
||||
'r': v:x -> [reverse x,[v],"r", []]
|
||||
'n': v:x -> [reverse x,[v],"n", []]
|
||||
'g':'n': v:x -> [reverse x,[v],"ng",[]]
|
||||
v :x -> [reverse x,[v],"", []]
|
||||
_ -> error $ "illegal pinyin: " ++ s
|
||||
|
||||
change ss@[x,[v],ng,i] = case i of
|
||||
[] -> ss
|
||||
_ -> [x,[accent v !! (read i - 1)],ng]
|
||||
|
||||
combine = concat
|
||||
|
||||
accent v = case v of
|
||||
'a' -> "āáǎà"
|
||||
'e' -> "ēéěè"
|
||||
'i' -> "īíǐì"
|
||||
'o' -> "ōóǒò"
|
||||
'u' -> "ūúǔù"
|
||||
'ü' -> "ǖǘǚǜ"
|
||||
'v' -> "ǖǘǚǜ"
|
||||
_ -> error $ "no accents for " ++ [v]
|
||||
|
||||
Reference in New Issue
Block a user