Created
December 17, 2014 20:24
-
-
Save kaneplusplus/1fe92c061b32f2f7e6f1 to your computer and use it in GitHub Desktop.
Find the synonyms of a word in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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