/** ****************************************************************************** * HOMEWORK: 15-121 ****************************************************************************** * Text concordance program ****************************************************************************** * * This is a main driver for text concordance program * * * @author * @date *****************************************************************************/ import java.util.*; import java.io.*; public class MainDriver { public static void main(String[] args) throws IOException { Concordance concord = new Concordance(); String inputFile = "src/test1.txt"; System.out.println( "***BUILD concordance tree: case sensitive\n" ); BSTConcordance tree1 = concord.buildTree(inputFile); System.out.println( " the height is " + tree1.getHeight() ); System.out.println( " the number of nodes is " + tree1.getNumberOfNodes() ); System.out.println( ); ArrayList list1 = concord.sortByAlpha(tree1); System.out.println( " tree sorted by alpha " ); System.out.println( list1 ); System.out.println( ); ArrayList list2 = concord.sortByFrequency(tree1); System.out.println( " tree sorted by frequency " ); System.out.println( list2 ); System.out.println( ); ArrayList list5 = concord.getHighestFrequency(tree1); System.out.println( " all words of the highest frequency " ); System.out.println( list5 ); System.out.println( ); System.out.println( ); System.out.println( ); System.out.println( "***BUILD concordance tree; case insensitive\n" ); BSTConcordance tree2 = concord.buildTree(inputFile, new IgnoreUpperCase()); System.out.println( " the height is " + tree2.getHeight() ); System.out.println( " the number of nodes is " + tree2.getNumberOfNodes() ); System.out.println( ); System.out.println( " tree sorted by alpha " ); ArrayList list3 = concord.sortByAlpha(tree2); System.out.println( list3 ); System.out.println( ); ArrayList list4 = concord.sortByFrequency(tree2); System.out.println( " tree sorted by frequency " ); System.out.println( list4 ); System.out.println( ); ArrayList list6 = concord.getHighestFrequency(tree2); System.out.println( " all words of the highest frequency" ); System.out.println( list6 ); System.out.println( ); System.out.println( "\n\n***RE-BUILD tree with respect to frequencies\n" ); BSTConcordance treap = concord.buildTree(list2, new AlphaFrequency()); System.out.println( " root: " + treap.getRoot() ); System.out.println( "\n tree sorted by frequency " ); System.out.println( concord.sortByFrequency(treap) ); System.out.println( ); System.out.println( ); inputFile = "src/Alice's Adventures.txt"; System.out.println( "***BUILD concordance for Alice's Adventures.txt: case sensitive\n" ); BSTConcordance tree3 = concord.buildTree(inputFile); System.out.println( " the height is " + tree3.getHeight() ); System.out.println( " the number of nodes is " + tree3.getNumberOfNodes() ); System.out.println( " all words of the highest frequency " ); System.out.println( concord.getHighestFrequency(tree3) ); System.out.println( ); inputFile = "src/Tom Sawyer.txt"; System.out.println( "***BUILD concordance for Tom Sawyer.txt: case sensitive\n" ); BSTConcordance tree4 = concord.buildTree(inputFile); System.out.println( " the height is " + tree4.getHeight() ); System.out.println( " the number of nodes is " + tree4.getNumberOfNodes() ); System.out.println( " all words of the highest frequency " ); System.out.println( concord.getHighestFrequency(tree4) ); System.out.println( ); System.out.println( " search for -kind- " ); System.out.println( tree4.search(new Word("kind")) ); System.out.println( ); } }