资源简介
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 < word.Length; i++)
{
fastCheck[word[i]] |= (byte)(1 << i);
}
for (int i = 7; i < word.Length; 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 < text.Length)
{
int count = 1;
if (index > 0 || (fastCheck[text[index]] & 1) == 0)
{
while (index < text.Length - 1 && (fastCheck[text[++index]] & 1) == 0) ;
}
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 << Math.Min(j 7))) == 0)
{
break;
}
if (j + 1 >= minWordLength)
{
if ((fastLength[begin] & (1 << Math.Min(j - 1 7))) > 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官方简体中文汉化包
相关资源
- 协同过滤算法源码
- 过滤器源代码
- crossfilter tutorial
- 敏感词汇大全 绝对够用
- 锤子Thor1.2+Thor1.34+300条过滤器规则
- springCloud路由网管负载均衡及拦截过滤
- 基于item-user混合协同过滤的推送系统
- 论文研究 - 基于DEA-Malmquist指数的玉米
- 论文研究 - 基于协同过滤和人工神经
- 敏感的词汇
- kettle 数据过滤验证
- β-SiC微粉过滤分级实验研究
- 井下千米钻机煤泥水就地循环利用工
- MapReduce基于物品的协同过滤算法实现
- 敏感词库.zip
- sparkMllib协同过滤测试数据ml-1m
- crack破解补丁
- 推荐系统手册(英文版)
- 推荐系统基于用户和Item的协同过滤算
- myeclipse下基于协同过滤算法的电影推
- 敏感词统计与过滤系统
- Linux网络数据包抓取源码分析和包过滤
- 基于协同过滤算法的电影推荐系统
- NDIS中间层 NDIS6过滤驱动开发笔记
- PCAN-Explorer5基本使用方法new
- 用户的协同过滤算法数据集及代码实
- ( Netflix Prize中的协同过滤算法.zip )
- 基于VC的包过滤防火墙论文源码有效地
- 基于数据包过滤的防火墙设计与实现
- 包过滤主机防火墙技术的研究
评论
共有 条评论