我目前正在研究论文并以R语言实现解决方案。我必须使用词网字典库查找同义词。我得到了针对单个单词的同义词,但是当我尝试使用一组单词的循环来获取同义词时,出现错误“订阅已终止”。如果有人可以指导我如何使用循环获取文本中每个单词的同义词,或者还有其他方法可以做到这一点?这是我正在尝试的代码
*my_corpus <- "closure animal wrong carnivore herbivore meat omnivore veg wrong"
for (j in seq(my_corpus))
{
if(initDict()) {
filter <- getTermFilter("ExactMatchFilter", "my_corpus", TRUE)
terms <- getIndexTerms("NOUN", 5, filter)
getSynonyms(terms[[my_corpus]])
}
}
*
require(stringr)
my_corpus <- str_split(my_corpus," ")[[1]]
用j替换“ my_corpus”
将print()放在getSynonyms周围
my_corpus <- "closure animal wrong carnivore herbivore meat omnivore veg wrong"
require(stringr)
my_corpus <- str_split(my_corpus," ")[[1]]
for (j in (my_corpus))
{
if(initDict()) {
filter <- getTermFilter("ExactMatchFilter", j, TRUE)
terms <- getIndexTerms("NOUN", 5, filter)
print(getSynonyms(terms[[my_corpus]]))
}
}
尝试“公司”,注意没有商机出现。Synonyms from wordnet package are very incomplete