Skip to content

Instantly share code, notes, and snippets.

@kaneplusplus
Created December 17, 2014 20:24
Show Gist options
  • Save kaneplusplus/1fe92c061b32f2f7e6f1 to your computer and use it in GitHub Desktop.
Save kaneplusplus/1fe92c061b32f2f7e6f1 to your computer and use it in GitHub Desktop.
Find the synonyms of a word in R
library(wordnet)
library(foreach)
get_synonyms = function(x) {
unique(foreach(pos=c("ADJECTIVE","ADVERB","NOUN","VERB"), .combine=c) %do% {
filter <- getTermFilter("ExactMatchFilter", x, TRUE)
ret = NULL
try({
suppressWarnings({
terms <- getIndexTerms(pos, Inf, filter)
ret = getSynonyms(terms[[1]])
})
}, silent=TRUE)
ret
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment