Regex 在R语料库中搜索以“结尾的所有单词”;";
我正在使用R的Regex 在R语料库中搜索以“结尾的所有单词”;";,regex,r,dictionary,text-mining,tm,Regex,R,Dictionary,Text Mining,Tm,我正在使用R的tm包来使用字典方法获取单词频率。我想找到所有以“esque”结尾的单词,无论它们是拼写为“abcd esque”、“abcdesque”还是“abcd esque”(因为我的语料库中存在所有不同的拼写)。如何为此创建正则表达式?这就是我目前所拥有的。如有任何帮助/提示,将不胜感激 text <- Corpus(DirSource("txt/")) text <- tm_map(text,tolower) text <- tm_map(text,stripWhi
tm
包来使用字典方法获取单词频率。我想找到所有以“esque”结尾的单词,无论它们是拼写为“abcd esque”、“abcdesque”还是“abcd esque”(因为我的语料库中存在所有不同的拼写)。如何为此创建正则表达式?这就是我目前所拥有的。如有任何帮助/提示,将不胜感激
text <- Corpus(DirSource("txt/"))
text <- tm_map(text,tolower)
text <- tm_map(text,stripWhitespace)
dtm.text <- DocumentTermMatrix(text)
list<-inspect(
DocumentTermMatrix(text,list(dictionary = c("rose", "green", "esque")))
)
文本
作为旁注,tolower
不适用于当前版本的tm
。您应该改用contetn\u transformer
:
tm_map(text, content_transformer(tolower))
grep(“esque$”,x)
?
tm_map(text, content_transformer(tolower))
words = c("rose", "green", "esque", "abcd-esque", "abcdesque", "abcd esque")
grep("esque$", words)