import type.lang.*;
import java.util.*;

public class DemoWordFreq
{
	public static void main(String[] args)
	{
		if (args.length != 1)
		{
			IO.println("----------------------------------------");
			IO.println("usage: java WordFreq file\n");
			IO.println("where 'file' is any text file");
			IO.println("(NOTE: list elements are tokens in file)");
			IO.println("----------------------------------------");
			System.exit(0);
		}

		final String DELIMITER = " \t\f\n\r~!@#$%^&*()_+={}|[]\\:\";<>?,./";

		UniReader ur = new UniReader(args[0]);
		TreeMap tm = new TreeMap();
		String s;
		while ((s = ur.readLine()) != null)
		{	
			StringTokenizer st = new StringTokenizer(s, DELIMITER);
			while (st.hasMoreTokens())
			{
				String key = st.nextToken().toLowerCase();
				if (!tm.containsKey(key))
					tm.put(key, new Integer(1));
				else
				{
					int count = ((Integer)tm.get(key)).intValue();
					tm.put(key, new Integer(count + 1));
				}
			}
		}

		IO.println("Size = " + tm.size());
		IO.println("Elements: " + tm);
	}
}
