2

I've looked around to find a way to see if a string is a valid english word but all the solutions I find involves me using a predefined list of words. I just want the string to be compared against a local dictionary. Is there a way to do this?

Right now my code takes in a string and is sent to this method

try {
    BufferedReader in = new BufferedReader(new FileReader("/usr/local/share/dict"));
    String str;
    while ((str = in.readLine()) != null) {
        if ( str.contains( word )) {
             return true;
        } else {
             return false;
        }
    }
    in.close();
} catch (IOException e) {
}
MAV
  • 7,260
  • 4
  • 30
  • 47
KKhat
  • 159
  • 1
  • 7
  • 2
    Is a local dictionary not a predefined list of words? Or have I misunderstood what you mean? – MAV Apr 28 '13 at 23:07
  • You could also look for a good API and use a Java URL to make an API call and retrieve the response. Based on some quick google-fu, I found http://words.bighugelabs.com/api.php – Keshav Saharia Apr 28 '13 at 23:52
  • There is no single canonical list of valid english words. Witness the need for every word processor in the world to have an "add word to dictionary" feature. – Warren P Apr 29 '13 at 00:14

1 Answers1

4

Wordnet has a Java API you can use; if you really want a local hashmap/hashset then you can construct one out of Wordnet's database.

Zim-Zam O'Pootertoot
  • 17,888
  • 4
  • 41
  • 69