我正在尝试将 .csv 转换为
femin,femin,1,f,woman,women,
aqu,aqu,1,f,water,waters,
..
进入 .pl 文件
noun(femin,femin,1,f,trans(woman,women)).
noun(aqu,aqu,1,f,trans(water,waters)).
..
这是我当前的源代码:
-- get from "femin, femin, 1, f, woman, women" to noun(femin, femin, 1, f ,trans(woman,women)).
import qualified Data.Attoparsec as P
data NounClause = NounClause
{
nom :: String,
gen :: String,
declension :: String,
gender :: String,
sgtrans :: String,
pltrans :: String
} deriving Show
parseNounClause :: P.Parser NounClause
parseNounClause = do
nom <- String
char ","
gen <- String
char ","
declension <- String
char ","
gender <- String
char ","
sgtrans <- String
char ","
pltrans <- String
return $ NounClause nom gen declension gender sgtrans pltrans
但是,这似乎不起作用。为什么会这样?
另外,如何将此解析器应用于每一行?这也是我的函数,它接受解析的数据并返回一个字符串。
c = ","
convert :: NounClause -> String
convert NounClause = "noun(" ++ nom ++ c ++ gen ++ c ++ declension ++ c ++ gender ++ "trans(" ++ sgtrans ++ c ++ pltrans ++ "))."
我非常感谢任何在这个项目上帮助我的人;他们的贡献对我来说是最有价值的。