void xCountCalc(word w) { w.xCount = 0; foreach (int chr in variations.SplitIntoChars(w.ToString())) { w.xCount -= CharCounts[chr]; } }
public void FeedBack(string s, word w) { if (w.ToString().IndexOf(" ") != -1) { return; } if (allWords.ContainsValue(w)) { if (w.m_index > 0 && thread == null) { if (trieReader != null) { trieReader.Close(); trieReader = null; } variations.FeedBack(s, w.ToString()); totalWordCount++; w.count++; FileStream fs = File.OpenWrite("trie.dat"); BinaryWriter bw = new BinaryWriter(fs); bw.Write(totalWordCount); bw.Flush(); fs.Position = w.m_index; fs.Position += w.ToString().Length + 1; bw.Write(w.count); bw.Write(w.xCount); bw.Close(); fs.Close(); trieReader = new BinaryReader(File.OpenRead("trie.dat")); } } else { List <int> chrs = variations.SplitIntoChars(w.ToString()); if (chrs == null) { return; } word nw = GetIndexedWord(BaseWord).Add(chrs, 1, variations.MergeChars(chrs) + "|"); totalWordCount++; xCountCalc(nw); word now = GetIndexedWord(BaseWord); ThreadParameters.Add(now.m_index); foreach (int chr in chrs) { now = GetIndexedWord(now.children[chr]); Console.WriteLine("{0} {1}", variations.Chars[chr], now.m_index); if (now.m_index > 0) { ThreadParameters.Add(now.m_index); } } if (thread != null) { thread.Abort(); ThreadReader.Close(); bw.Close(); csvfile.Close(); } thread = new Thread(ThreadFunction); thread.Start(); } }