public static void Main() { Console.WriteLine("Generating a very big mothereffing lorem text. Please stand by..."); RandomDataGenerator.GenerateLorem(LoremPath); var trie = TrieFactory.CreateTrie(); var wordsSet = new List <string>(1000); Console.WriteLine("Reading words from file..."); var words = File.ReadAllLines(LoremPath).SelectMany(x => x.Split(new[] { ' ', ',', '.', '!', '?' }, StringSplitOptions.RemoveEmptyEntries)); Console.WriteLine("Saving words..."); foreach (var word in words) { trie.AddWord(word); if (!wordsSet.Contains(word) && wordsSet.Count < 999) { wordsSet.Add(word); } } var sb = new StringBuilder(); Console.WriteLine("Counting words..."); foreach (var word in wordsSet) { sb.AppendLine(string.Format("{0} occured {1} times in the text.", word, trie.WordCount(word))); } Console.WriteLine(sb.ToString()); }
public void AddWord_EmptyString01() { trie = TrieFactory.CreateTrie(); Assert.AreEqual(0, trie.GetWords().Count); trie.AddWord(""); Assert.AreNotEqual(0, trie.GetWords().Count); }
static void Setup() { /*Setup dictionary*/ _dictionary = TrieFactory.CreateTrie(); StreamReader reader = new StreamReader("..\\..\\..\\SampleText.txt"); string[] words = reader.ReadToEnd().Split(' ', '.', ',', '?', '!', ':', ';'); foreach (var word in words) { _dictionary.AddWord(word.ToLower()); } /*end dictionary*/ /*setup sample sentence*/ _sentence = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; /*end sample sentence*/ /*setup random encryption*/ _encryption = Service.GetRandomEncryption(); /*end random encryption*/ /*encrypt sentence*/ _encryptedSentence = Service.Encrypt(_sentence, _encryption); /*end ecnryption*/ }
public static void Main(string[] args) { // Trie implementation from https://github.com/rmandvikar/csharp-trie Console.WriteLine("The program read all words from 'text.txt',"); Console.WriteLine("adds them in a Trie and prnt the first 1000 words"); Console.WriteLine("along with the occurrences of each word"); Console.WriteLine("Press any key to begin.."); Console.ReadKey(); ITrie trie = TrieFactory.CreateTrie(); var reader = new StreamReader("../../text.txt"); ReadWordsFromText(reader, trie); var counter = 0; foreach (var currentWord in trie.GetWords()) { counter++; if (counter == 1000) { break; } var wordCounter = trie.WordCount(currentWord); Console.WriteLine("{0} - {1}", currentWord, wordCounter); } }
public static void Main() { var trie = TrieFactory.CreateTrie(); var words = GenerateRandomWords(1000000); var uniqueWords = new HashSet <string>(words); AddWordsToTrie(words, trie); GetCountOfAllUniqueWords(uniqueWords, trie); }
public void Test13() { var trie = TrieFactory.CreateTrie(); trie.AddWord(""); trie.AddWord(""); Assert.AreEqual(1, trie.GetWords().Count); trie.RemoveWord(""); Assert.AreEqual(0, trie.GetWords().Count); trie.AddWord(""); Assert.AreEqual(1, trie.GetWords().Count); trie.RemoveWord(""); Assert.AreEqual(0, trie.GetWords().Count); }
private ITrie LowerCaseWords() { ITrie trie = TrieFactory.CreateTrie(); string[] strings = { "this", "test", "the", "temp", "token", "take", "thump" }; foreach (string s in strings) { trie.AddWord(s); } return(trie); }
private ITrie UpperCaseWords() { ITrie trie = TrieFactory.CreateTrie(); string[] strings = { "THIS", "TEST", "THE", "TEMP", "TOKEN", "TAKE", "THUMP" }; foreach (string s in strings) { trie.AddWord(s); } return(trie); }
private ITrie Words() { ITrie trie = TrieFactory.CreateTrie(); string[] strings = { "this", "test", "the", "TEMP", "TOKEN", "TAKE", "THUMP" }; foreach (string s in strings) { trie.AddWord(s); } return(trie); }
private ITrie Digits() { ITrie trie = TrieFactory.CreateTrie(); string[] strings = { "123", "1", "23" }; foreach (string s in strings) { trie.AddWord(s); } return(trie); }
public static void Main() { ITrie trie = TrieFactory.CreateTrie(); using (var reader = new StreamReader(@"..\..\Files\text.txt")) { while (!reader.EndOfStream) { reader .ReadLine() .Split(' ', '.', ',', '?', '!', ':') .ToList() .ForEach(word => { trie.AddWord(word); }); } } var countOfLorem = trie.WordCount("lorem"); Console.WriteLine("Lorem -> {0} times", countOfLorem); }
static void Main(string[] args) { var trie = TrieFactory.CreateTrie(); HashSet <string> words = new HashSet <string>(); using (StreamReader reader = new StreamReader("../../100MB.txt")) { string line; while ((line = reader.ReadLine()) != null) { foreach (var word in line.Split(' ')) { words.Add(word); trie.AddWord(word); } } } foreach (var word in words) { Console.WriteLine("{0} - {1} times", word, trie.WordCount(word)); } }