Пример #1
0
    static void Main(string[] args)
    {
        Stopwatch sw = new Stopwatch();
        TrieNode start = new TrieNode();
        var allWords = SetInputText();

        List<string> wordsToSearch = new List<string>();
        for (int i = 0; i < 50; i++)
        {
            wordsToSearch.Add(allWords[i].ToString());
        }

        sw.Start();

        AddWordsInTrie(start, wordsToSearch);
        IncrementOccuranceCountTrie(start, allWords);

        sw.Stop();

        Console.WriteLine("Searched words count trie: ");
        foreach (var word in wordsToSearch)
        {
            Console.WriteLine("{0}: {1}", word, start.CountWords(start, word));
        }
        Console.WriteLine();
        Console.WriteLine("Time elapsed: {0}", sw.Elapsed);
    }
Пример #2
0
    static void Main(string[] args)
    {
        Stopwatch sw       = new Stopwatch();
        TrieNode  start    = new TrieNode();
        var       allWords = SetInputText();

        List <string> wordsToSearch = new List <string>();

        for (int i = 0; i < 50; i++)
        {
            wordsToSearch.Add(allWords[i].ToString());
        }

        sw.Start();

        AddWordsInTrie(start, wordsToSearch);
        IncrementOccuranceCountTrie(start, allWords);

        sw.Stop();

        Console.WriteLine("Searched words count trie: ");
        foreach (var word in wordsToSearch)
        {
            Console.WriteLine("{0}: {1}", word, start.CountWords(start, word));
        }
        Console.WriteLine();
        Console.WriteLine("Time elapsed: {0}", sw.Elapsed);
    }
        /// <summary>
        /// Method to run the WordReader on the specified file
        /// </summary>
        /// <param name="stream"> The stream of data to be read by a StreamReader </param>
        /// <returns> Dictionary of words and count values  </returns>
        public Dictionary<string, int> Run(Stream stream)
        {
            var rootNode = new TrieNode(null, '?');

            using (var streamReader = new StreamReader(stream))
            {
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    var words = line.Split(null);
                    foreach (var word in words)
                    {
                        rootNode.AddWord(word.Trim().ToLower());
                    }
                }
            }

            var numWords = 0;
            rootNode.CountWords(ref numWords);
            return AccumulatedWords(numWords, rootNode);
        }
Пример #4
0
    static void Main()
    {
        Stopwatch sw = new Stopwatch();
        TrieNode start = new TrieNode();
        Dictionary<string, int> wordsInDictionary = new Dictionary<string, int>();
        var allWords = SetInputText();

        List<string> wordsToSearch = new List<string>();
        // change number to increase searched words count
        for (int i = 0; i < 50; i++)
        {
            wordsToSearch.Add("text");
        }

        AddWordsForSearchInDictionary(sw, wordsToSearch, wordsInDictionary);
        AddWordsForSearchInTrie(sw, start, wordsToSearch);

        IncrementOccuranceCountTrie(sw, start, allWords);
        IncrementOccuranceCountDictionary(sw, wordsInDictionary, allWords);

        Console.WriteLine("Searched words count trie: ");
        foreach (var word in wordsToSearch)
        {
            Console.WriteLine("{0}: {1}", word, start.CountWords(start, word));
        }

        Console.WriteLine("\nSearched words count dictionary: ");
        foreach (var item in wordsInDictionary)
        {
            Console.WriteLine("{0}: {1}", item.Key, item.Value);
        }
    }