做一个敏感词过滤系统
txt文件 里面有 大量string敏感词
写入SenseWord表里
唔
其实就是 EF的批量添加
数据库表如下
1是 “报恐”
2是 “涩晴”
之类的
方便快速查询
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace PiLiangJiaRu2
{
class Program
{
public static void Read(string path)
{
StreamReader sr = new StreamReader(path, Encoding.Default);
String line;
CbjGameProjectXBDB1_5Entities myContext = new CbjGameProjectXBDB1_5Entities();
var SenWords = myContext.SensitiveWord;
while ((line = sr.ReadLine()) != null)
{
SenWords.Add(new SensitiveWord() {
ClassTypeId = 1,
KeyWord = line.ToString(),
}
);
var ss = myContext.SaveChanges();
if (ss > 0)
{
Console.WriteLine("非法词汇:{0}", line.ToString());
}
}
}
static void Main(string[] args)
{
Read("F://bkck.txt");
Console.ReadLine();
}
}
}
Id设置为自增列 就不用管了
记得SaveChange
本文地址:https://blog.csdn.net/qq_38992403/article/details/107638134
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!
网友评论