我对Haskell和函数式编程很陌生。
我的目标是从用户那里获得一个字符串,并检查该字符串中是否有任何词干词根可用。如果是这样的话,我希望删除词干并返回字符串。
Eg: if input is :"He is fishing and catching"
output is : "he is fish and catch"我可以用其他语言做这件事。但我不知道在Haskell该怎么做。有人知道如何用Haskell解决这个问题吗。
checkstemming :: [String] -> [String]
checkstemming [] = []
checkstemming xs = foldr (++) [] ( [ drop x |x <- xs, x="ing"])我试过了,但我知道这是错误的。有人能帮我解决这个问题吗?
发布于 2013-12-30 08:46:20
一次只处理一个词,这会使事情变得容易得多:
removeStemming :: String -> String
removeStemming [] = []
removeStemming (x:"ing") = [x]
removeStemming (x:xs) = x : removeStemming xs
checkStemming :: [String] -> [String]
checkStemming = map removeStemming另一种方法是使用来自Data.List的Data.List
removeStemming :: String -> String
removeStemming xs
| "ing" `isSuffixOf` xs = take (length xs - 3) xs
| otherwise = xshttps://stackoverflow.com/questions/20835998
复制相似问题