Reputation: 22956
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
or
or
Upvotes: 0
Views: 1512
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
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