//检查是否含有敏感词 public bool Check(string inputText) { m_Cursor = 0; string str = inputText.Trim(); if (str == string.Empty) { return(false); } m_SourceText = ToDBC(str); List <string> illegalWords = new List <string>(); //检测到的非法字符集 char[] tempString = m_SourceText.ToCharArray(); for (int i = 0; i < m_SourceText.Length; i++) { //查询以该字为首字符的词组 WordGroup group = MEMORYLEXICON[(int)ToDBC(m_SourceText)[i]]; if (group != null) { for (int z = 0; z < group.Count(); z++) { string word = group.GetWord(z); if (word.Length == 0 || Examine(word)) { string blackword = string.Empty; for (int pos = 0; pos < m_WordLengh + 1; pos++) { blackword += tempString[pos + m_Cursor].ToString(); //tempString[pos + m_Cursor] = replaceChar; } illegalWords.Add(blackword); m_Cursor = m_Cursor + m_WordLengh; i = i + m_WordLengh; } } } m_Cursor++; } if (illegalWords.Count > 0) { return(true); } else { return(false); } }
public void Load(string dictPath) { return; string path = HomePath.GetAbsolutePath(dictPath); if (path != string.Empty) { List <string> wordList = new List <string>(); Array.Clear(MEMORYLEXICON, 0, MEMORYLEXICON.Length); string[] words = System.IO.File.ReadAllLines(path, System.Text.Encoding.UTF8); foreach (string word in words) { string key = this.ToDBC(word); wordList.Add(key); //繁体转简体,暂不考虑 //wordList.Add(Microsoft.VisualBasic.Strings.StrConv(key, Microsoft.VisualBasic.VbStrConv.TraditionalChinese, 0)); } Comparison <string> cmp = delegate(string key1, string key2) { return(key1.CompareTo(key2)); }; wordList.Sort(cmp); for (int i = wordList.Count - 1; i > 0; i--) { if (wordList[i].ToString() == wordList[i - 1].ToString()) { wordList.RemoveAt(i); } } foreach (var word in wordList) { WordGroup group = MEMORYLEXICON[(int)word[0]]; if (group == null) { group = new WordGroup(); MEMORYLEXICON[(int)word[0]] = group; } group.Add(word.Substring(1)); } } }