extracting synonyms using wordnet

让人想犯罪 __ 提交于 2019-12-11 17:05:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!