Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a function to recognize a word?

Tags:

r

Is there a way to evaluate a string and see if it evaluates to a word in English? Here is what I am looking for

is.word("hello world")
[1] FALSE

is.word(c("hello", "world")
[1] TRUE TRUE

The above does not work as there is no is.word logical function.

like image 416
seakyourpeak Avatar asked Dec 29 '15 16:12

seakyourpeak


1 Answers

As the comments have pointed out, you need an English dictionary to match against. The GradyAugmented object in the qdapDictionary package is one such dictionary:

A dataset containing a vector of Grady Ward's English words augmented with ‘DICTIONARY’, Mark Kantrowitz's names list, other proper nouns, and contractions.

library(qdapDictionaries)
is.word  <- function(x) x %in% GradyAugmented
is.word(c("hello world"))
## [1] FALSE
is.word(c("hello", "world"))
## [1] TRUE TRUE
is.word(c("asfasdf"))
## [1] FALSE
like image 142
Ben Bolker Avatar answered Oct 03 '22 22:10

Ben Bolker