0

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.
Gibbs
  • 21,904
  • 13
  • 74
  • 138

2 Answers2

1

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.

  • There are multiple plans to choose from. You can check them on the bottom of https://developer.oxforddictionaries.com/ There is a free version as well. – Bartosz Krzeszowski Sep 28 '17 at 07:12
  • There also is a method for retrieving a list of words in the chosen dictionary. You could write a simple code to get the whole list by specifying limit and offset with each request and put them in a local database. You might need to get some permission for doing so, as I don't think it is meant to be used this way. – Bartosz Krzeszowski Sep 28 '17 at 07:26
0

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
  }
}
  • U mean I should have a file of valid words. It might be GB in size. Will it not affect the performance? – Gibbs Sep 28 '17 at 07:05
  • Here is a link of such a file: https://raw.githubusercontent.com/dwyl/english-words/master/words.txt , this contains around 350,000 words and still the size is around 4.64 MB. So yeah that won't affect the performance – Rishav Gupta Sep 28 '17 at 07:11
  • Anyways, a better solution will be calling an API as mentioned by @Bartosz, but if you want a local solution then this(mentioned above) can be the solution. – Rishav Gupta Sep 28 '17 at 07:13