public void IssuesTest_20() { string text = "A10021003吃饭"; var keywords = new string[] { "1", "A", "2", "0", "吃" }; var iws = new IllegalWordsSearch(); var ss = new StringSearch(); var sse = new StringSearchEx2(); iws.SetKeywords(keywords); iws.UseIgnoreCase = true; iws.UseDBCcaseConverter = true; var iwsFirst = iws.FindFirst(text); Assert.AreEqual("吃", iwsFirst.Keyword); var iwsAll = iws.FindAll(text); Assert.AreEqual(1, iwsAll.Count);// 因为1A20左右都是英文或数字,所以识别失败 ss.SetKeywords(keywords); var ssFirst = ss.FindFirst(text); Assert.AreEqual("A", ssFirst); var ssAll = ss.FindAll(text); Assert.AreEqual(9, ssAll.Count); sse.SetKeywords(keywords); var sseFirst = sse.FindFirst(text); Assert.AreEqual("A", sseFirst); var sseAll = sse.FindAll(text); Assert.AreEqual(9, sseAll.Count); }
public void IssuesTest_57_3() { String test = "his is sha ash"; List <String> list = new List <String>(); list.Add("ash"); list.Add("sha"); list.Add("bcd"); IllegalWordsSearch iwords = new IllegalWordsSearch(); iwords.SetKeywords(list); var b = iwords.ContainsAny(test); Assert.AreEqual(true, b); var f = iwords.FindFirst(test); Assert.AreEqual("sha", f.Keyword); var all = iwords.FindAll(test); Assert.AreEqual(2, all.Count); }
/// <summary> /// FreeSql /// </summary> /// <param name="services"></param> public static void AddContext(this IServiceCollection services) { var configuration = services.BuildServiceProvider().GetRequiredService <IConfiguration>(); IConfigurationSection configurationSection = configuration.GetSection("ConnectionStrings:MySql"); IFreeSql fsql = new FreeSqlBuilder() .UseConnectionString(DataType.MySql, configurationSection.Value) .UseEntityPropertyNameConvert(StringConvertType.PascalCaseToUnderscoreWithLower) //全局转换实体属性名方法 https://github.com/2881099/FreeSql/pull/60 .UseAutoSyncStructure(true) //自动迁移实体的结构到数据库 .UseMonitorCommand(cmd => { Trace.WriteLine(cmd.CommandText + ";"); } ) .UseSyncStructureToLower(true) // 转小写同步结构 .Build() .SetDbContextOptions(opt => opt.EnableAddOrUpdateNavigateList = true); //联级保存功能开启(默认为关闭) fsql.Aop.CurdBefore += (s, e) => { }; fsql.Aop.CurdAfter += (s, e) => { if (e.ElapsedMilliseconds > 200) { //记录日志 //发送短信给负责人 } }; //敏感词处理 if (configuration["AuditValue:Enable"].ToBoolean()) { IllegalWordsSearch illegalWords = ToolGoodUtils.GetIllegalWordsSearch(); fsql.Aop.AuditValue += (s, e) => { if (e.Column.CsType == typeof(string) && e.Value != null) { string oldVal = (string)e.Value; string newVal = illegalWords.Replace(oldVal); //第二种处理敏感词的方式 //string newVal = oldVal.ReplaceStopWords(); if (newVal != oldVal) { e.Value = newVal; } } }; } services.AddSingleton(fsql); services.AddScoped <IUnitOfWork>(sp => sp.GetService <IFreeSql>().CreateUnitOfWork()); services.AddFreeRepository(filter => { filter.Apply <IDeleteAduitEntity>("IsDeleted", a => a.IsDeleted == false); }, typeof(AuditBaseRepository <>).Assembly); }
public void IssuesTest_57() { String test = "一,二二,三三三,四四四四,五五五五五,六六六六六六"; List <String> list = new List <String>(); list.Add("一"); list.Add("二二"); list.Add("三三三"); list.Add("四四四四"); list.Add("五五五五五"); list.Add("六六六六六六"); IllegalWordsSearch iwords = new IllegalWordsSearch(); iwords.SetKeywords(list); bool b = iwords.ContainsAny(test); Assert.AreEqual(true, b); IllegalWordsSearchResult f = iwords.FindFirst(test); Assert.AreEqual("一", f.Keyword); List <IllegalWordsSearchResult> all = iwords.FindAll(test); Assert.AreEqual("一", all[0].Keyword); Assert.AreEqual("二二", all[1].Keyword); Assert.AreEqual("三三三", all[2].Keyword); Assert.AreEqual("四四四四", all[3].Keyword); Assert.AreEqual("五五五五五", all[4].Keyword); Assert.AreEqual("六六六六六六", all[5].Keyword); }
/// <summary> /// FreeSql /// </summary> /// <param name="services"></param> public static void AddContext(this IServiceCollection services, IConfiguration configuration) { IConfigurationSection configurationSection = configuration.GetSection("ConnectionStrings:MySql"); IFreeSql fsql = new FreeSqlBuilder() .UseConnectionString(DataType.MySql, configurationSection.Value) .UseNameConvert(NameConvertType.PascalCaseToUnderscoreWithLower) .UseAutoSyncStructure(true) .UseNoneCommandParameter(true) .UseMonitorCommand(cmd => { Trace.WriteLine(cmd.CommandText + ";"); } ) .Build() .SetDbContextOptions(opt => opt.EnableAddOrUpdateNavigateList = true);//联级保存功能开启(默认为关闭) fsql.Aop.CurdAfter += (s, e) => { Log.Debug($"ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}: FullName:{e.EntityType.FullName}" + $" ElapsedMilliseconds:{e.ElapsedMilliseconds}ms, {e.Sql}"); if (e.ElapsedMilliseconds > 200) { //记录日志 //发送短信给负责人 } }; //敏感词处理 if (configuration["AuditValue:Enable"].ToBoolean()) { IllegalWordsSearch illegalWords = ToolGoodUtils.GetIllegalWordsSearch(); fsql.Aop.AuditValue += (s, e) => { if (e.Column.CsType == typeof(string) && e.Value != null) { string oldVal = (string)e.Value; string newVal = illegalWords.Replace(oldVal); //第二种处理敏感词的方式 //string newVal = oldVal.ReplaceStopWords(); if (newVal != oldVal) { e.Value = newVal; } } }; } services.AddSingleton(fsql); services.AddScoped <UnitOfWorkManager>(); fsql.GlobalFilter.Apply <IDeleteAduitEntity>("IsDeleted", a => a.IsDeleted == false); //在运行时直接生成表结构 fsql.CodeFirst.SyncStructure(ReflexHelper.GetEntityTypes(typeof(IEntity))); services.AddFreeRepository(); }
public void IssuesTest_17() { var illegalWordsSearch = new IllegalWordsSearch(); string s = "中国|zg人|abc"; illegalWordsSearch.SetKeywords(s.Split('|')); var str = illegalWordsSearch.Replace("我是中美国人厉害中国完美abcddb好的", '*'); Assert.Equal("我是中美国人厉害**完美***ddb好的", str); }
public void IssuesTest_17() { var illegalWordsSearch = new IllegalWordsSearch(); string s = "中国|zg人|abc"; illegalWordsSearch.SetKeywords(s.Split('|')); var str = illegalWordsSearch.Replace("我是中美国人厉害中国完美abcddb好的", '*'); //Assert.AreEqual("我是中美国人厉害**完美***ddb好的", str); //注,abc先转abc,再判断abc左右是否为英文或数字,因为后面为d是英文,所以不能过滤 Assert.AreEqual("我是中美国人厉害**完美abcddb好的", str); }
public void IssuesTest_65() { var search = new IllegalWordsSearch(); List <string> keywords = new List <string>(); keywords.Add("f**k"); keywords.Add("ffx"); search.SetKeywords(keywords); var result = search.Replace("fFuck"); Assert.AreEqual("*****", result); }
public Startup(IConfiguration configuration) { Configuration = configuration; IConfigurationSection configurationSection = Configuration.GetSection("ConnectionStrings:Default"); Fsql = new FreeSqlBuilder() .UseConnectionString(DataType.MySql, configurationSection.Value) .UseEntityPropertyNameConvert(StringConvertType.PascalCaseToUnderscoreWithLower) //全局转换实体属性名方法 https://github.com/2881099/FreeSql/pull/60 .UseAutoSyncStructure(true) //自动迁移实体的结构到数据库 .UseMonitorCommand(cmd => { Trace.WriteLine(cmd.CommandText); } ) .UseSyncStructureToLower(true) // 转小写同步结构 .Build(); Fsql.Aop.CurdBefore = (s, e) => { }; Fsql.Aop.CurdAfter = (s, e) => { if (e.ElapsedMilliseconds > 200) { //记录日志 //发送短信给负责人 } }; //敏感词处理 if (Configuration["AuditValue:Enable"].ToBoolean()) { IllegalWordsSearch illegalWords = ToolGoodUtils.GetIllegalWordsSearch(); Fsql.Aop.AuditValue += (s, e) => { if (e.Column.CsType == typeof(string) && e.Value != null) { string oldVal = (string)e.Value; string newVal = illegalWords.Replace(oldVal); //第二种处理敏感词的方式 //string newVal = oldVal.ReplaceStopWords(); if (newVal != oldVal) { e.Value = newVal; } } }; } }
public void IssuesTest_56() { var keywords = new string[] { "我爱中国", "中国", }; var txt = "新型财富密码就是大喊“我[爱中]国”么?伏拉夫,轻松拥有千万粉丝的新晋网红,快手粉丝465万,抖音粉丝704万。他是靠“爱中国”火起来的。伏拉夫在短视频平台上的简介是:爱中国!爱火锅!"; var iws = new IllegalWordsSearch(); iws.SetKeywords(keywords); iws.SetSkipWords("]"); var ts = iws.FindAll(txt); Assert.AreEqual(3, ts.Count); Assert.AreEqual("中]国", ts[0].Keyword); }
public void IssuesTest_57_2() { String test = "jameson吃饭"; List<String> list = new List<String>(); list.Add("jameson吃饭"); list.Add("吃饭jameson"); IllegalWordsSearch iwords = new IllegalWordsSearch(); iwords.SetKeywords(list); var b = iwords.ContainsAny(test); Assert.AreEqual(true, b); var f = iwords.FindFirst(test); Assert.AreEqual("jameson吃饭", f.Keyword); }
public BadWordService() { StringSearch = new IllegalWordsSearch(); StringSearch.UseIgnoreCase = true; StringSearch.SetKeywords(censoredWords); }
public void IllegalWordsSearchTest() { string s = "中国|国人|zg人|f**k|all|as|19|http://|ToolGood"; string test = "我是中国人"; IllegalWordsSearch iwords = new IllegalWordsSearch(2); iwords.SetKeywords(s.Split('|')); var b = iwords.ContainsAny(test); Assert.AreEqual(true, b); var f = iwords.FindFirst(test); Assert.AreEqual(true, f.Success); Assert.AreEqual("中国", f.Keyword); Assert.AreEqual(2, f.Start); Assert.AreEqual(3, f.End); var all = iwords.FindAll(test); Assert.AreEqual("中国", all[0].SrcString); Assert.AreEqual("国人", all[1].SrcString); test = "我是中国zg人"; all = iwords.FindAll(test); Assert.AreEqual("中国", all[0].SrcString); Assert.AreEqual("zg人", all[1].SrcString); Assert.AreEqual("国zg人", all[2].SrcString); test = "中间国zg人"; all = iwords.FindAll(test); Assert.AreEqual("zg人", all[0].SrcString); Assert.AreEqual("国zg人", all[1].SrcString); test = "f**k al.l"; all = iwords.FindAll(test); Assert.AreEqual("f**k", all[0].SrcString); Assert.AreEqual("al.l", all[1].SrcString); Assert.AreEqual(2, all.Count); test = "ht@tp://ToolGood.com"; all = iwords.FindAll(test); Assert.AreEqual("ht@tp://", all[0].SrcString); Assert.AreEqual("http://", all[0].Keyword); Assert.AreEqual("toolgood", all[1].Keyword); Assert.AreEqual("ToolGood", all[1].SrcString); Assert.AreEqual(2, all.Count); test = "asssert all"; all = iwords.FindAll(test); Assert.AreEqual("all", all[0].SrcString); Assert.AreEqual(1, all.Count); test = "19w 1919 all"; all = iwords.FindAll(test); Assert.AreEqual("19", all[0].SrcString); Assert.AreEqual("all", all[1].SrcString); test = "我是【中]国【人"; all = iwords.FindAll(test); Assert.AreEqual("中]国", all[0].SrcString); Assert.AreEqual("国【人", all[1].SrcString); test = "我是【中国【人"; all = iwords.FindAll(test); Assert.AreEqual("中国", all[0].SrcString); Assert.AreEqual("国【人", all[1].SrcString); Assert.AreEqual(2, all.Count); var ss = iwords.Replace(test, '*'); Assert.AreEqual("我是【****", ss); }
private MinGanProvider() { IllegalWordsSearch = new IllegalWordsSearch(); }