FileDocCategorySizeDatePackage
Dict.javaAPI DocExample1911Mon Aug 21 18:55:00 BST 2000tuning.dict

Dict

public class Dict extends Object

Fields Summary
static int
SEED
public static String[]
DICT
public static String[]
RAND_DICT
Constructors Summary
Methods Summary
public static voidinitialize(boolean garbageCollect)

    BufferedReader r = new BufferedReader(new FileReader("tuning\\dict\\ENGLISH.MED"));
    Vector v = new Vector(500000);
    String line;
    while( (line = r.readLine()) != null)
    {
      v.addElement(line);
    }
    r.close();

    DICT = new String[v.size()];
    for (int i = 0; i < DICT.length; i++)
      DICT[i] = (String) v.elementAt(i);

    RAND_DICT = new String[v.size()];
    Random rand = new Random(SEED);
    int idx;
    for (int i = DICT.length-1; i >= 0 ; i--)
    {
	idx = (int) ((Math.abs(rand.nextInt()) * (long) i)/Integer.MAX_VALUE);
	RAND_DICT[i] = (String) v.elementAt(idx);
	v.setElementAt(v.elementAt(i), idx);
	v.setElementAt(null, i);
    }
    v = null;
    r = null;
    line = null;
    rand = null;
    if (garbageCollect)
      System.gc();
  
public static voidmain(java.lang.String[] args)


      
  
    try
    {
      initialize(false);
      System.out.println(DICT.length);
      System.out.println(RAND_DICT.length);
      Hashtable h = new Hashtable();
      for (int i = 0; i < DICT.length; i++)
      {
        if (DICT[i] == null) throw new Exception("DICT[i] == null");
	h.put(DICT[i],Boolean.TRUE);
      }
      Object o;
      for (int i = 0; i < RAND_DICT.length; i++)
      {
        if (RAND_DICT[i] == null) throw new Exception("DICT[i] == null");
	if ( (o=h.put(DICT[i],Boolean.FALSE)) != Boolean.TRUE ) throw new Exception("h.put");
      }
    }
    catch(Exception e){e.printStackTrace();}