How to check if a word exists in the Wordnet database

Objective: I have a document with many words. I need to figure out which words have spelling mistakes.

I have installed WordNet 3.0 for this.

With the below command, I can check if the word actually exists in the wordnet database but this needs me to specify the POS ie NOUN, PRONOUN,etc. which I might not know in advance

filter <- getTermFilter("ExactMatchFilter", "car", TRUE)
terms <- getIndexTerms("NOUN", 5, filter) 

Please let me know a way to solve my problem in R


One approach:

library(wordnet)
inWordnet <- function(w, pos =  c("ADJECTIVE", "ADVERB", "NOUN", "VERB")) {
  for (x in pos) {
     filter <- getTermFilter("ExactMatchFilter", w, TRUE)
     terms <- getIndexTerms(x, 5, filter)
     if (!is.null(terms)) return(TRUE)
  }
  return(FALSE)
}
inWordnet("car")
# [1] TRUE

or vectorized:

vInWordnet <- Vectorize(inWordnet, vectorize.args = c("w", "pos"))
vInWordnet(c("car", "asdas"))
#   car asdas 
#  TRUE FALSE 
链接地址: http://www.djcxy.com/p/62416.html

上一篇: 使用WordNet(JWI)的两个单词之间的常用Hypernym

下一篇: 如何检查Wordnet数据库中是否存在单词