private void Speak() { string text = string.Empty; Journal.EventsRow er = j.Events.FindByID(selectedEventID); if (er == null) { return; } if (!er.IsSubjectNull()) { text = er.Subject.ToLower() + " ..."; } if (!er.IsBodyNull()) { text += er.Body.ToLower(); } text = Regex.Replace(text, @"<\s*?lj\s*?user\s*?=\s*?\""?(\w*?)\""?\s*?>", "$1"); text = Regex.Replace(text, "<.+?>", " "); text = text.Replace("\"", "'").Replace(" ", " "); if (!chkShowBalloon.Checked) { text = string.Format("\\map=\"{0}\"=\"\"\\", text); } agent.Stop(null); request = agent.Speak(text, null); if (animations.Count > 0) { agent.Play((string)animations[(new Random()).Next(animations.Count)]); } }
static private void BuildHitCount() { ArrayList al = null; ArrayList categoryList = new ArrayList(); Regex r = new Regex("<.+>", RegexOptions.Compiled | RegexOptions.Multiline); StringBuilder sb = new StringBuilder(); // wordlists wordLists = new Hashtable(); using (StreamReader sr = new StreamReader( Assembly.GetExecutingAssembly().GetManifestResourceStream(_ridWordsResource))) { while (sr.Peek() > -1) { string s = sr.ReadLine(); if (s.StartsWith("\t")) { al = new ArrayList(); wordLists.Add(s.Substring(1), al); categoryList.Add(s.Substring(1)); } else { al.Add(s); } } } categories = (string[])categoryList.ToArray(typeof(string)); hitCounts = new Hashtable(); frequencies = new Hashtable(); foreach (string category in categories) { hitCounts.Add(category, new int[j.Events.Count]); frequencies.Add(category, new double[j.Events.Count]); } wordLengths = new int[j.Events.Count]; for (int row = 0; row < j.Events.Count; ++row) { int lastPercentComplete = 0; IDictionaryEnumerator ide; Journal.EventsRow er = j.Events[row]; string[] words; sb.Length = 0; if (!er.IsSubjectNull()) { sb.Append(r.Replace(er.Subject, string.Empty).ToLower()); sb.Append(' '); } if (!er.IsBodyNull()) { sb.Append(r.Replace(er.Body, string.Empty).ToLower()); } words = sb.ToString().Split(' ', '\n', '\t', '.', ',', '?'); wordLengths[row] = words.Length; ide = wordLists.GetEnumerator(); while (ide.MoveNext()) { al = (ArrayList)ide.Value; int[] hitCount = (int[])hitCounts[ide.Key]; double[] frequency = (double[])frequencies[ide.Key]; foreach (string word in words) { foreach (string catWord in al) { int i; if (word == null || word.Length == 0 || catWord[0] > word[0]) { break; } if (catWord[0] != word[0]) { continue; } i = catWord.Length - 1; // this is poor lemmatization, but an eyeball guesstimate of the dictionary // shows it should work for about 95% of all cases if (catWord[i] == '*') { if (word.Length >= i && word.Length < i + 3 && word.Substring(0, i) == catWord.Substring(0, i)) { hitCount[row]++; break; } } else if (catWord == word) { hitCount[row]++; break; } } } frequency[row] = ((double)hitCount[row]) / ((double)wordLengths[row]); } if (((95 * row) / j.Events.Count) - lastPercentComplete >= 5) { lastPercentComplete = (95 * row) / j.Events.Count; ascb(new AnalysisStatusEventArgs(AnalysisStatus.Analyzing, lastPercentComplete)); } } }