net.jxta.search.util
Class Soundex

java.lang.Object
  |
  +--net.jxta.search.util.Soundex

public class Soundex
extends java.lang.Object

Soundex is an algorithm (due to Knuth?) to do spell-checking. Usage:

Soundex   soundex = new Soundex ();
int       numSuggestions = 4;

soundex.insertDictionary (new File ("/usr/dict/words"));
// or

soundex.insert ("Birkbeck");
soundex.insert ("Zbygniewski");
soundex.insert ("toy");
soundex.insert ("car");
soundex.insert ("lorry");
soundex.insert ("bicycle");

PriorityQueue pq = soundex.getClosest (s, numSuggestions);

if (pq == null) {
System.out.println ("No matches.");
} else {
Soundex.EditWord ew;

while ((ew = (EditWord) pq.pop ()) != null) {

System.out.println (ew.s + " with " + ew.distance + " edits.");
}
}


Inner Class Summary
static class Soundex.EditWord
           
 
Constructor Summary
Soundex()
           
 
Method Summary
 PriorityQueue getClosest(java.lang.String s, int maxDistance)
           
 void insert(java.lang.String s)
           
 void insertDictionary(java.io.File dict)
           
static void main(java.lang.String[] argv)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Soundex

public Soundex()
Method Detail

insert

public void insert(java.lang.String s)

insertDictionary

public void insertDictionary(java.io.File dict)
                      throws java.io.IOException

getClosest

public PriorityQueue getClosest(java.lang.String s,
                                int maxDistance)
                         throws java.util.NoSuchElementException
Returns:
PriorityQueue Ordered list of closest-matching words.
Throws:
java.util.NoSuchElementException - If there was no exact match and no words within maxDistance.

main

public static void main(java.lang.String[] argv)
                 throws java.io.IOException