问题
I am currently working on my thesis and implementing the solution in R language. i have to find synonyms using word-net dictionary library. i get the synonyms against single word but when i try to get synonyms using loop for set of words i get the error "Subscription is out of bond".. kindly if some one can guide me how to get synonyms for against each word in text using loop or is there any other way to do it? here is the code i am trying
*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]])
}
}
*
回答1:
require(stringr)
my_corpus <- str_split(my_corpus," ")[[1]]
replace "my_corpus" with j
put print() around 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]]))
}
Try "company" and notice how no businesses ever come up. Synonyms from wordnet package are very incomplete
来源:https://stackoverflow.com/questions/57969653/extracting-synonyms-using-wordnet