我正在学习 R 中的文本挖掘,并且取得了相当大的成功。但我对如何处理复数感到困惑。即我希望“nation”和“nations”被算作同一个词,理想情况下“dictionary”和“dictionaries”被算作同一个词。
x <- '"nation" and "nations" to be counted as the same word and ideally "dictionary" and "dictionaries" to be counted as the same word.'
一种可能的解决方案。这里我使用 pacman 包来使解决方案自包含:
if (!require("pacman")) install.packages("pacman"); library(pacman)
p_load_gh('hrbrmstr/pluralize')
p_load(quanteda)
x <- '"nation" and "nations" to be counted as the same word and ideally "dictionary" and "dictionaries"'
singularize(unlist(tokenize(x)))
## [1] "\"" "nation" "\"" "and" "\"" "nation" "\""
## [8] "to" "be" "counted" "a" "the" "same" "word"
## [15] "and" "ideally" "\"" "dictionary" "\"" "and" "\""
## [22] "dictionary" "\""
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)