public static void Main(string[] args) { Console.WriteLine("Counting words..."); DateTime start_at = DateTime.Now; TrieNode root = new TrieNode(null, '?'); Dictionary <DataReader, Thread> readers = new Dictionary <DataReader, Thread>(); if (args.Length == 0) { args = new string[] { "war-and-peace.txt", "ulysees.txt", "les-miserables.txt", "the-republic.txt", "war-and-peace.txt", "ulysees.txt", "les-miserables.txt", "the-republic.txt" }; } if (args.Length > 0) { foreach (string path in args) { DataReader new_reader = new DataReader(path, ref root); Thread new_thread = new Thread(new_reader.ThreadRun); readers.Add(new_reader, new_thread); new_thread.Start(); } } foreach (Thread t in readers.Values) { t.Join(); } DateTime stop_at = DateTime.Now; Console.WriteLine("Input data processed in {0} secs", new TimeSpan(stop_at.Ticks - start_at.Ticks).TotalSeconds); Console.WriteLine(); Console.WriteLine("Most commonly found words:"); List <TrieNode> top10_nodes = new List <TrieNode> { root, root, root, root, root, root, root, root, root, root }; int distinct_word_count = 0; int total_word_count = 0; root.GetTopCounts(ref top10_nodes, ref distinct_word_count, ref total_word_count); top10_nodes.Reverse(); foreach (TrieNode node in top10_nodes) { Console.WriteLine("{0} - {1} times", node.ToString(), node.m_word_count); } Console.WriteLine(); Console.WriteLine("{0} words counted", total_word_count); Console.WriteLine("{0} distinct words found", distinct_word_count); Console.WriteLine(); Console.WriteLine("done."); }
public static void Main(string[] args) { Console.WriteLine("Counting words..."); DateTime atTime = DateTime.Now; TrieNode root = new TrieNode(); Dictionary <DataReader, Thread> readers = new Dictionary <DataReader, Thread>(); if (args.Length == 0) { //default pile of words args = new string[] { "war-and-peace.txt", "ulysees.txt", "les-miserables.txt", "the-republic.txt", "war-and-peace.txt", "ulysees.txt", "les-miserables.txt", "the-republic.txt" }; } else //args.Length > 0 { foreach (string path in args) { DataReader newReader = new DataReader(path, ref root); Thread newThread = new Thread(newReader.ThreadRun); readers.Add(newReader, newThread); newThread.Start(); } } DateTime atStop = DateTime.Now; Console.WriteLine("Data Processing Complete {0} seconds", TimeSpan(atStop.Ticks - atTime.Ticks).TotalSeconds); Console.WriteLine("Most Commonly Found Words:"); List <TrieNode> topNodes = new List <TrieNode> { root, root, root, root, root, root, root, root, root, root }; int distinctWordsCount = 0; int totalWordCount = 0; root.GetTopCounts(ref topNodes, ref distinctWordsCount, ref totalWordCount); topNodes.Reverse(); foreach (TrieNode node in topNodes) { Console.WriteLine(" {0} - {1} times", node.ToString(), node.m_word_count); } Console.WriteLine(); Console.WriteLine("{0} words counted", total_word_count); Console.WriteLine("{0} distinct words found", distinct_word_count); Console.WriteLine(); Console.WriteLine("done."); }
public static void Main(string[] args) { Console.WriteLine("Counting words..."); DateTime start_at = DateTime.Now; TrieNode root = new TrieNode(null, '?'); if (args.Length == 1) { ReadInputFile(args[0], ref root); } else { for (int i = 0; i < 100; i++) { ReadInputFile("war-and-peace.txt", ref root); ReadInputFile("ulysees.txt", ref root); ReadInputFile("les-miserables.txt", ref root); ReadInputFile("the-republic.txt", ref root); } } DateTime stop_at = DateTime.Now; Console.WriteLine("Input data processed in {0} secs", new TimeSpan(stop_at.Ticks - start_at.Ticks).TotalSeconds); Console.WriteLine(); Console.WriteLine("{0} words found", TrieNode.DISTINCT_WORD_COUNT); Console.WriteLine("{0} nodes created", TrieNode.NODE_COUNT); Console.WriteLine("{0} words counted", TrieNode.TOTAL_WORD_COUNT); Console.WriteLine(); Console.WriteLine("Most commonly found words:"); List <TrieNode> top10_nodes = new List <TrieNode> { root, root, root, root, root, root, root, root, root, root }; root.GetTopCounts(ref top10_nodes); top10_nodes.Reverse(); foreach (TrieNode node in top10_nodes) { Console.WriteLine("{0} - {1} times", node.ToString(), node.m_word_count); } }