Exemplo n.º 1
0
        internal Statistics RecomputeStatistics()
        {
            var totalWordsIndexed        = 0;
            var totalUniqueWordsIndexed  = 0;
            var longestWordIndexed       = string.Empty;
            var shortestWordIndexed      = string.Empty;
            var mostFrequentWordIndexed  = string.Empty;
            var leastFrequentWordIndexed = string.Empty;
            var mostFrequentWordCount    = 0;
            var leastFrequentWordCount   = int.MaxValue;

            var currentWordId        = -1;
            var currentWord          = string.Empty;
            var currentWordFrequency = 0;

            foreach (var compoundKey in wordCompoundIdToOccurrenceMap.Keys)
            {
                var wordId = CompoundId.Split(compoundKey).Item1;

                if (currentWordId != wordId)
                {
                    if (currentWordId != -1)
                    {
                        if (currentWordFrequency >= mostFrequentWordCount)
                        {
                            mostFrequentWordCount   = currentWordFrequency;
                            mostFrequentWordIndexed = currentWord;
                        }
                        if (currentWordFrequency <= leastFrequentWordCount)
                        {
                            leastFrequentWordCount   = currentWordFrequency;
                            leastFrequentWordIndexed = currentWord;
                        }
                    }

                    currentWordId        = wordId;
                    currentWordFrequency = 0;
                    currentWord          = idToWordMap[wordId];
                    totalUniqueWordsIndexed++;

                    if (currentWord.Length >= longestWordIndexed.Length)
                    {
                        longestWordIndexed = currentWord;
                    }
                    if (currentWord.Length <= shortestWordIndexed.Length || string.IsNullOrEmpty(shortestWordIndexed))
                    {
                        shortestWordIndexed = currentWord;
                    }
                }
                totalWordsIndexed++;
                currentWordFrequency++;
            }

            return(new Statistics(totalWordsIndexed, totalUniqueWordsIndexed, longestWordIndexed, shortestWordIndexed, mostFrequentWordIndexed, leastFrequentWordIndexed));
        }