/// <summary> /// Processes the data stream. /// </summary> private void ProcessDataStream() { string word = ""; while (!_dataLoader.IsComplete || !_dataCache.IsEmpty) { char charToProcess; if (_dataCache.TryDequeue(out charToProcess)) { TotalCharsProcessed++; //(end of word) if (charToProcess == ' ' || charToProcess == '.') { // add 1 for the space CharFrequency.TryAdd(charToProcess, 0); // make a space for the space CharFrequency[charToProcess] += 1; if (word.Length > 0) { // process the chars in the word foreach (char c in word) { CharFrequency.TryAdd(c, 0); CharFrequency[c] += 1; } // switch to lower case & remove junk chars word = CleanupWord(word); // do word frequency analysis ulong currentCount = WordFrequency.GetOrAdd(word, 0); WordFrequency.TryUpdate(word, currentCount + 1, currentCount); // do word count analysis TotalWordsProcessed++; // we are done, flush the word buffer word = ""; } } else { // add this char to the current word word += charToProcess; } } } IsComplete = true; }
public static ObservableCollection <CharFrequency> GetListCharFrequency(string text) { ObservableCollection <CharFrequency> list = new ObservableCollection <CharFrequency>(); foreach (char character in text) { CharFrequency item = GetItemIfCharIsOnList(character, list); if (item != null) { item.Frequency++; } else { list.Add(new CharFrequency(character)); } } foreach (var item in list) { item.FrequencyPercent = Convert.ToDouble(item.Frequency) / Convert.ToDouble(text.Length) * 100.0; } return(list); }
public override string ToString() { return(CharFrequency.ToString()); }