コード例 #1
0
        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());
        }
コード例 #2
0
ファイル: TrieTest.cs プロジェクト: radu-solca/IA_Labs
 public void AddWord_EmptyString01()
 {
     trie = TrieFactory.CreateTrie();
     Assert.AreEqual(0, trie.GetWords().Count);
     trie.AddWord("");
     Assert.AreNotEqual(0, trie.GetWords().Count);
 }
コード例 #3
0
        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*/
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        public static void Main()
        {
            var trie = TrieFactory.CreateTrie();

            var words       = GenerateRandomWords(1000000);
            var uniqueWords = new HashSet <string>(words);

            AddWordsToTrie(words, trie);
            GetCountOfAllUniqueWords(uniqueWords, trie);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        private ITrie Digits()
        {
            ITrie trie = TrieFactory.CreateTrie();

            string[] strings =
            {
                "123", "1", "23"
            };

            foreach (string s in strings)
            {
                trie.AddWord(s);
            }
            return(trie);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: FindWords.cs プロジェクト: nelfurion/TelerikAcademy
        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));
            }
        }