在haskell中删除单词 [英] stemming words removal in haskell
问题描述
我的目标是从用户处获取一个字符串,并检查该字符串中是否存在可用的词干单词。如果是的话,我想删除词干并返回字符串。
例如:如果输入是:他正在钓鱼和捕捉
的输出是:他是鱼和捕捉
我可以在其他语言中执行此操作。但我不知道如何在Haskell中做到这一点。做任何一个知道如何使用Haskell解决这个问题..
checkstemming :: [String] - > [String]
checkstemming [] = []
checkstemming xs = foldr(++)[]([drop x | x < - xs,x =ing])
我试过了,但我知道它错了。任何人都可以帮助我解决这个问题,请.. ..
解决方案
一次解决一个字,这使事情变得更容易:
removeStemming :: String - > String
removeStemming [] = []
removeStemming(x:ing)= [x]
removeStemming(x:xs)= x:removeStemming xs
checkStemming :: [String] - > [String]
checkStemming = map removeStemming
另一种方法是使用 isSuffixOf
来自 Data.List
:
removeStemming :: String - >字符串
removeStemming xs
| ingisSuffixOf` xs = take(length xs - 3)xs
|否则= xs
am new to Haskell and functional programing..
my aim is to get a string from user and check whether there is any stemming words available in that string. if so i want to remove the stemming and return the string.
Eg: if input is :"He is fishing and catching"
output is : "he is fish and catch"
i can do this in other languages. but i don't know how to do it in Haskell. do any one know how to solve this problem using Haskell..
checkstemming :: [String] -> [String]
checkstemming [] = []
checkstemming xs = foldr (++) [] ( [ drop x |x <- xs, x="ing"])
i tried, but i know its wrong. can anyone help me to sole this problem please..
Tackle one word at a time, this makes things much easier:
removeStemming :: String -> String
removeStemming [] = []
removeStemming (x:"ing") = [x]
removeStemming (x:xs) = x : removeStemming xs
checkStemming :: [String] -> [String]
checkStemming = map removeStemming
Another way to do this is to use isSuffixOf
from Data.List
:
removeStemming :: String -> String
removeStemming xs
| "ing" `isSuffixOf` xs = take (length xs - 3) xs
| otherwise = xs
这篇关于在haskell中删除单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!