資源簡介
net過濾臟字的代碼,一般用于處理論壇等言論的敏感詞過濾,我主要用到了代碼內的TrieFilter工具類,其他工具類若有需求可以自行研究

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Collections;
namespace?FilterTest
{
????///?
????///?http://www.cnblogs.com/xingd/archive/2008/02/01/1061800.html上的方法
????///?
????public?class?BadWordsFilter
????{
????????private?HashSet?hash?=?new?HashSet();
????????private?byte[]?fastCheck?=?new?byte[char.MaxValue];
????????private?byte[]?fastLength?=?new?byte[char.MaxValue];
????????private?BitArray?charCheck?=?new?BitArray(char.MaxValue);
????????private?BitArray?endCheck?=?new?BitArray(char.MaxValue);
????????private?int?maxWordLength?=?0;
????????private?int?minWordLength?=?int.MaxValue;
????????public?BadWordsFilter()
????????{
????????}
????????public?void?AddKey(string?word)
????????{
????????????maxWordLength?=?Math.Max(maxWordLength?word.Length);
????????????minWordLength?=?Math.Min(minWordLength?word.Length);
????????????for?(int?i?=?0;?i?7?&&?i?????????????{
????????????????fastCheck[word[i]]?|=?(byte)(1?<????????????}
????????????for?(int?i?=?7;?i?????????????{
????????????????fastCheck[word[i]]?|=?0x80;
????????????}
????????????if?(word.Length?==?1)
????????????{
????????????????charCheck[word[0]]?=?true;
????????????}
????????????else
????????????{
????????????????fastLength[word[0]]?|=?(byte)(1?<(Math.Min(7?word.Length?-?2)));
????????????????endCheck[word[word.Length?-?1]]?=?true;
????????????????hash.Add(word);
????????????}
????????}
????????public?string?Filter(string?text?string?mask)
????????{
????????????throw?new?NotImplementedException();
????????}
????????public?bool?HasBadWord(string?text)
????????{
????????????int?index?=?0;
????????????while?(index?????????????{
????????????????int?count?=?1;
????????????????if?(index?>?0?||?(fastCheck[text[index]]?&?1)?==?0)
????????????????{
????????????????????while?(index?????????????????}
????????????????char?begin?=?text[index];
????????????????if?(minWordLength?==?1?&&?charCheck[begin])
????????????????{
????????????????????return?true;
????????????????}
????????????????for?(int?j?=?1;?j?<=?Math.Min(maxWordLength?text.Length?-?index?-?1);?j++)
????????????????{
????????????????????char?current?=?text[index?+?j];
????????????????????if?((fastCheck[current]?&?1)?==?0)
????????????????????{
????????????????????????++count;
????????????????????}
????????????????????if?((fastCheck[current]?&?(1?<????????????????????{
????????????????????????break;
????????????????????}
????????????????????if?(j?+?1?>=?minWordLength)
????????????????????{
????????????????????????if?((fastLength[begin]?&?(1?<?0?&&?endCheck[current])
????????????????????????{
????????????????????????????string?sub?=?text.Substring(index?j?+?1);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-09-12?10:14??FilterTest\
?????目錄???????????0??2017-09-12?10:14??FilterTest\Backup\
?????目錄???????????0??2017-09-12?10:14??FilterTest\Backup\FilterTest\
?????文件???????65391??2011-08-25?22:53??FilterTest\Backup\FilterTest\BadWord.txt
?????文件????????3341??2011-09-01?13:51??FilterTest\Backup\FilterTest\BadWordsFilter.cs
?????文件????????3031??2011-08-25?23:15??FilterTest\Backup\FilterTest\CodeTimer.cs
?????文件????????2916??2011-09-01?13:43??FilterTest\Backup\FilterTest\FilterTest.csproj
?????文件?????????168??2011-09-01?13:43??FilterTest\Backup\FilterTest\FilterTest.csproj.user
?????文件????????3002??2011-09-01?13:43??FilterTest\Backup\FilterTest\HashFilter.cs
?????文件????????2938??2011-09-01?13:50??FilterTest\Backup\FilterTest\Program.cs
?????目錄???????????0??2017-09-12?10:14??FilterTest\Backup\FilterTest\Properties\
?????文件????????1376??2011-09-01?13:33??FilterTest\Backup\FilterTest\Properties\AssemblyInfo.cs
?????文件????????1285??2011-08-29?07:34??FilterTest\Backup\FilterTest\Talk.txt
?????文件????????5634??2011-09-01?13:46??FilterTest\Backup\FilterTest\TrieFilter.cs
?????文件?????????920??2011-09-01?13:33??FilterTest\Backup\FilterTest.sln
?????目錄???????????0??2017-09-12?10:15??FilterTest\FilterTest\
?????文件????????3341??2011-09-01?13:51??FilterTest\FilterTest\BadWordsFilter.cs
?????文件????????3031??2011-08-25?23:15??FilterTest\FilterTest\CodeTimer.cs
?????文件????????4405??2017-04-11?14:38??FilterTest\FilterTest\FilterTest.csproj
?????文件?????????498??2017-04-11?14:38??FilterTest\FilterTest\FilterTest.csproj.user
?????文件????????3002??2011-09-01?13:43??FilterTest\FilterTest\HashFilter.cs
?????文件????????4608??2017-04-12?18:31??FilterTest\FilterTest\Program.cs
?????目錄???????????0??2017-09-12?10:14??FilterTest\FilterTest\Properties\
?????文件????????1376??2011-09-01?13:33??FilterTest\FilterTest\Properties\AssemblyInfo.cs
?????文件????????1285??2011-08-29?07:34??FilterTest\FilterTest\Talk.txt
?????文件????????5688??2017-04-11?14:38??FilterTest\FilterTest\TrieFilter.cs
?????文件?????????161??2017-04-11?14:38??FilterTest\FilterTest\app.config
?????目錄???????????0??2017-09-12?10:14??FilterTest\FilterTest\bin\
?????目錄???????????0??2017-09-12?10:14??FilterTest\FilterTest\bin\Debug\
?????文件?????1607406??2017-04-12?11:15??FilterTest\FilterTest\bin\Debug\BadWord.txt
?????文件???????14848??2017-04-12?18:33??FilterTest\FilterTest\bin\Debug\FilterTest.exe
............此處省略20個文件信息
- 上一篇:土地報備坐標信息轉換
- 下一篇:Multisim12官方簡體中文漢化包
評論
共有 條評論