Gibbs
Gibbs

Reputation: 22956

Android - Checking valid English words

Valid words: Words that are in Oxford dictionary. An assumption.

I want to verify whether the word formed by user is valid. I hope having a dictionary is a good option. I agree that using spell checker is the wrong option.

I read Android Word Validation). Answer suggesting to load a dictionary into sqlite. I might misunderstood this. If I load my list of words into sqlite, I may miss some words.

So my question is

  1. Is there any android built-in class which provides list of words. I don't think I can use UserDictionary of Android.

or

  1. Is there any way to load an entire dictionary to SQLite

or

  1. If I am wrong, will you please suggest me the best option.

Upvotes: 0

Views: 1512

Answers (2)

Bartosz Krzeszowski
Bartosz Krzeszowski

Reputation: 46

When it comes to other options, you could try using Oxford dictionary API for checking a specific word:

https://developer.oxforddictionaries.com/documentation

There are methods for checking the existance of words.

Upvotes: 1

Rishav Gupta
Rishav Gupta

Reputation: 46

You can use something like this below:

public class Dictionary
{
 private Set<String> wordsSet;

 public Dictionary() throws IOException    //read the file in the constructor
  {
    Path path = Paths.get("file.txt");  //path of the file in root directory
    byte[] readBytes = Files.readAllBytes(path);
    String wordListContents = new String(readBytes, "UTF-8");
    String[] words = wordListContents.split("\n"); //the text file should contain one word in one line
    wordsSet = new HashSet<>();
    Collections.addAll(wordsSet, words);
  }

  public boolean contains(String word)
  {
    return wordsSet.contains(word);   //check if it exists
  }
}

Upvotes: 0

Related Questions