public static void Main() { var generator = new TextGenerator(WordTypes.Name); var names = generator.GenerateText(1000); var trie = new Trie(); var words = new HashSet <string>(); names.Split(' ').ToList().ForEach( x => { words.Add(x); trie.AddWord(x); }); var result = new StringBuilder(); foreach (var word in words.OrderBy(x => x)) { int occurenceCount; trie.TryFindWord(word, out occurenceCount); result.AppendFormat("{0} -> {1} times", word, occurenceCount).AppendLine(); } Console.WriteLine(result); }
public static void Main() { var generator = new TextGenerator(WordTypes.Name); var names = generator.GenerateText(1000); var trie = new Trie(); var words = new HashSet<string>(); names.Split(' ').ToList().ForEach( x => { words.Add(x); trie.AddWord(x); }); var result = new StringBuilder(); foreach (var word in words.OrderBy(x => x)) { int occurenceCount; trie.TryFindWord(word, out occurenceCount); result.AppendFormat("{0} -> {1} times", word, occurenceCount).AppendLine(); } Console.WriteLine(result); }
public static void Main() { // Test(); var trie = new Trie(); var words = new StreamReader("sampleText.txt").ReadToEnd().Split(new char[] { '.', '!', '?', ';', ' ', ':', ',', '-' }, StringSplitOptions.RemoveEmptyEntries); foreach (var word in words) { trie.AddWord(word); } var result = new StringBuilder(); var searchedWords = new StreamReader("searchedWords.txt").ReadToEnd().Split(new char[] { '.', '!', '?', ';', ' ', ':', ',', '-' }, StringSplitOptions.RemoveEmptyEntries); int occurs = 0; foreach (var word in searchedWords) { result.Append(word); result.Append(" -> "); trie.TryFindWord(word, out occurs); result.Append(occurs); result.AppendLine(" times"); } Console.Write(result.ToString()); }
private static void Test() { var a = new Trie(); a.AddWord("hello"); a.AddWord("hello"); a.AddWord("hi"); a.AddWord("helloo"); int oc = 0; Console.WriteLine(a.TryFindWord("hel", out oc) + " -> " + oc + " times"); Console.WriteLine(a.TryFindWord("hi", out oc) + " -> " + oc + " times"); Console.WriteLine(a.TryFindWord("hii", out oc) + " -> " + oc + " times"); Console.WriteLine(a.TryFindWord("hello", out oc) + " -> " + oc + " times"); Console.WriteLine(a.TryFindWord("helloo", out oc) + " -> " + oc + " times"); }
private static void Test() { var a = new Trie(); a.AddWord("hello"); a.AddWord("hello"); a.AddWord("hi"); a.AddWord("helloo"); int oc = 0; Console.WriteLine(a.TryFindWord("hel", out oc) + " -> " + oc + " times"); Console.WriteLine(a.TryFindWord("hi", out oc) + " -> " + oc + " times"); Console.WriteLine(a.TryFindWord("hii", out oc) + " -> " + oc + " times"); Console.WriteLine(a.TryFindWord("hello", out oc) + " -> " + oc + " times"); Console.WriteLine(a.TryFindWord("helloo", out oc) + " -> " + oc + " times"); }