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