我目前正在写我的论文,并用R语言实现这个解决方案。我必须使用word-net字典库来查找同义词。我根据单个单词获取同义词,但是当我尝试使用循环获取单词集的同义词时,我得到错误消息"Subscription is out of bond“。如果有人能指导我如何使用循环针对文本中的每个单词获取同义词,或者有其他方法可以做到这一点吗?下面是我正在尝试的代码
*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]])
}
}*
发布于 2019-10-02 10:32:21
require(stringr)
my_corpus <- str_split(my_corpus," ")[[1]]将"my_corpus“替换为j
将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))
{
filter <- getTermFilter("ExactMatchFilter", j, TRUE)
terms <- getIndexTerms("NOUN", 5, filter)
print(getSynonyms(terms[[1]]))
}试试看"company“,你会注意到没有任何业务出现。Synonyms from wordnet package are very incomplete
https://stackoverflow.com/questions/57969653
复制相似问题