How to check if a word exists in the Wordnet database

1.1k views Asked by At

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 i.e. 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

1

There are 1 answers

0
lukeA On

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