// Author: // Email: // Date: import java.io.*; import java.util.TreeSet; import java.util.TreeMap; import java.util.HashMap; public class WordList { private TreeSet TScontainer = new TreeSet(); //private HashMapm = new HashMap(); public WordList(String inputFileName) { StringBuffer contents = new StringBuffer(); try { BufferedReader input = new BufferedReader(new FileReader(inputFileName)); try { String line = null; while (( line = input.readLine()) != null){ contents.append(line); contents.append(System.getProperty("line.separator")); } } finally { input.close(); } } catch (IOException e){ e.printStackTrace(); } String[] list = contents.toString().split(" "); for(String x : list){ String fixedstring = x.trim(); System.out.println(fixedstring); int i; for(i=0;i tmap = new TreeMap(); for(String x : TScontainer){ int amount = 1; if(tmap.containsKey(x)){ amount = tmap.get(x); tmap.put(x, amount++); } else{ tmap.put(x, amount); } } try{ FileWriter fstream = new FileWriter("alfasorted.txt"); BufferedWriter out = new BufferedWriter(fstream); for(String x : TScontainer) out.write(x.trim()+" "+tmap.get(x)+"\n"); out.close(); }catch(Exception e){} } private void computeBackwardsOrder() { // define! } public static void main(String[] args) throws IOException { WordList wl = new WordList("provtext.txt"); // arg[0] contains the input file name wl.computeWordFrequencies(); wl.computeFrequencyMap(); wl.computeBackwardsOrder(); System.out.println("Finished!"); } }