Skip to content

Instantly share code, notes, and snippets.

@graingert
Created February 14, 2012 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graingert/1830956 to your computer and use it in GitHub Desktop.
Save graingert/1830956 to your computer and use it in GitHub Desktop.
public Set<String> signatureToWords(String signature){
Set<String> words = new HashSet<String>();
int index = (Collections.binarySearch(dictionary, new WordSig("", signature))*-1-2);
//System.out.println("Index: "+index);
int x = index;
String currentSig = dictionary.get(x).getSig();
String currentWord = dictionary.get(x).getWords();
/**
if(PredictivePrototype.isValidWord(currentWord)){
words.add(currentWord.toLowerCase());
}
**/
while(currentSig.equals(signature)){
//System.out.println(x);
if(PredictivePrototype.isValidWord(currentWord.toLowerCase())&&PredictivePrototype.wordToSignature(currentWord).equals(signature)){
words.add(currentWord.toLowerCase());
}
currentSig = dictionary.get(x--).getSig();
currentWord = dictionary.get(x).getWords();
//System.out.println(dictionary.get(x).toString());
}
while(currentSig.equals(signature)){
if(PredictivePrototype.isValidWord(currentWord.toLowerCase())&&PredictivePrototype.wordToSignature(currentWord).equals(signature)){
words.add(currentWord.toLowerCase());
}
currentSig = dictionary.get(index++).getSig();
currentWord = dictionary.get(index).getWords();
//System.out.println(dictionary.get(x).toString());
}
return words;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment