Exemplo n.º 1
0
  public boolean isWord(String word) {
    Letter thisLetter = root;

    while (word.length() > 0) {
      Character thisChar = word.charAt(0);
      word = word.substring(1);

      if (!thisLetter.hasChild(thisChar)) {
        return false;
      } else {
        thisLetter = thisLetter.getChild(thisChar);
      }
    }
    return thisLetter.isWord();
  }
Exemplo n.º 2
0
  public Double scoreString(String prefix) {
    Letter thisLetter = root;

    while (prefix.length() > 0) {
      Character thisChar = prefix.charAt(0);
      prefix = prefix.substring(1);

      if (!thisLetter.hasChild(thisChar)) {
        return new Double(0);
      } else {
        thisLetter = thisLetter.getChild(thisChar);
      }
    }
    return thisLetter.score().doubleValue();
  }