Example #1
0
        public void IllegalWordsQuickSearchTest()
        {
            string s    = "中国|国人|zg人|f**k|all|as|19|http://|ToolGood";
            string test = "我是中国人";


            IllegalWordsQuickSearch iwords = new IllegalWordsQuickSearch(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);

            test = "中间国zg人";
            all  = iwords.FindAll(test);
            Assert.AreEqual("zg人", all[0].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("toolgood", all[0].Keyword);
            Assert.AreEqual("ToolGood", all[0].SrcString);
            Assert.AreEqual(1, 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(1, all.Count);


            var ss = iwords.Replace(test, '*');

            Assert.AreEqual("我是【**【人", ss);
        }
Example #2
0
        static void Main(string[] args)
        {
            ReadBadWord();
            var text = File.ReadAllText("Talk.txt");

            //var l = text.Length;
            stringSearchEx.Save("test.ini");
            var tt = stringSearchEx.FindAll(text);

            //word2.Load("test.ini");
            Console.Write("-------------------- SetKeywords Test --------------------\r\n");

            Run(1, "StringSearch.SetKeywords  ", () => {
                List <string> list = new List <string>();
                using (StreamReader sw = new StreamReader(File.OpenRead("BadWord.txt"))) {
                    string key = sw.ReadLine();
                    while (key != null)
                    {
                        if (key != string.Empty)
                        {
                            list.Add(key);
                        }
                        key = sw.ReadLine();
                    }
                }
                StringSearch s = new StringSearch();
                s.SetKeywords(list);
            });
            Run(1, "StringSearchEx.SetKeywords  ", () => {
                List <string> list = new List <string>();
                using (StreamReader sw = new StreamReader(File.OpenRead("BadWord.txt"))) {
                    string key = sw.ReadLine();
                    while (key != null)
                    {
                        if (key != string.Empty)
                        {
                            list.Add(key);
                        }
                        key = sw.ReadLine();
                    }
                }
                StringSearchEx s = new StringSearchEx();
                s.SetKeywords(list);
            });
            Run(1, "StringSearchEx.Load  ", () => {
                StringSearchEx s = new StringSearchEx();
                s.Load("test.ini");
            });



            //var ts1 = word.FindAll(text);
            //var ts = word2.FindAll(text);
            Console.Write("-------------------- ToSenseWord Test --------------------\r\n");

            Run("ToSenseWord1  ", () => { WordTest.ToSenseWord1(text); });
            Run("ToSenseWord2  ", () => { WordTest.ToSenseWord2(text); });
            Run("ToSenseWord3  ", () => { WordTest.ToSenseWord3(text); });
            Run("ToSenseWord4  ", () => { WordTest.ToSenseWord4(text); });
            Run("ToSenseWord5  ", () => { WordTest.ToSenseWord5(text); });
            Run("ToSenseWord6  ", () => { WordTest.ToSenseWord6(text); });
            Run("ToSenseWord7  ", () => { WordTest.ToSenseWord7(text); });
            Run("ToSenseWord8  ", () => { WordTest.ToSenseWord8(text); });
            Run("ToSenseWord9  ", () => { WordTest.ToSenseWord9(text); });
            Run("ToSenseWord10  ", () => { WordTest.ToSenseWord10(text); });

            Run("GetDisablePostion1  ", () => { WordTest.GetDisablePostion1(text); });
            Run("GetDisablePostion2  ", () => { WordTest.GetDisablePostion2(text); });
            Run("GetDisablePostion3  ", () => { WordTest.GetDisablePostion3(text); });
            Run("GetDisablePostion4  ", () => { WordTest.GetDisablePostion4(text); });
            Run("GetDisablePostion5  ", () => { WordTest.GetDisablePostion5(text); });
            Run("GetDisablePostion6  ", () => { WordTest.GetDisablePostion6(text); });
            Run("GetDisablePostion7  ", () => { WordTest.GetDisablePostion7(text); });
            Run("GetDisablePostion9  ", () => { WordTest.GetDisablePostion9(text); });
            Run("GetDisablePostion8  ", () => { WordTest.GetDisablePostion8(text); });

            //Console.Write("-------------------- ToSenseIllegalWords --------------------\r\n");

            //Run("ToSenseIllegalWords", () => { WordsHelper.ToSenseIllegalWords(text); });



            Console.Write("-------------------- FindFirst OR ContainsAny --------------------\r\n");
            Run("TrieFilter", () => { tf1.HasBadWord(text); });
            Run("FastFilter", () => { ff.HasBadWord(text); });
            Run("StringSearch(ContainsAny)", () => { stringSearch.ContainsAny(text); });
            Run("StringSearch(FindFirst)", () => { stringSearch.FindFirst(text); });
            Run("StringSearchEx(ContainsAny)", () => { stringSearchEx.ContainsAny(text); });
            Run("StringSearchEx(FindFirst)", () => { stringSearchEx.FindFirst(text); });
            Run("WordsSearch(ContainsAny)", () => { wordsSearch.ContainsAny(text); });
            Run("WordsSearch(FindFirst)", () => { wordsSearch.FindFirst(text); });
            Run("WordsSearchEx(ContainsAny)", () => { wordsSearchEx.ContainsAny(text); });
            Run("WordsSearchEx(FindFirst)", () => { wordsSearchEx.FindFirst(text); });
            Run("IllegalWordsQuickSearch(FindFirst)", () => { illegalWordsQuickSearch.FindFirst(text); });
            Run("IllegalWordsQuickSearch(ContainsAny)", () => { illegalWordsQuickSearch.ContainsAny(text); });

            Run("IllegalWordsSearch(FindFirst)", () => { illegalWordsSearch.FindFirst(text); });
            Run("IllegalWordsSearch(ContainsAny)", () => { illegalWordsSearch.ContainsAny(text); });

            Console.Write("-------------------- Find All --------------------\r\n");
            Run("TrieFilter(FindAll)", () => { tf1.FindAll(text); });
            Run("FastFilter(FindAll)", () => { ff.FindAll(text); });
            Run("StringSearch(FindAll)", () => { stringSearch.FindAll(text); });
            Run("StringSearchEx(FindAll)", () => { stringSearchEx.FindAll(text); });
            Run("WordsSearch(FindAll)", () => { wordsSearch.FindAll(text); });
            Run("WordsSearchEx(FindAll)", () => { wordsSearchEx.FindAll(text); });
            Run("IllegalWordsQuickSearch(FindAll)", () => { illegalWordsQuickSearch.FindAll(text); });
            Run("IllegalWordsSearch(FindAll)", () => { illegalWordsSearch.FindAll(text); });
            Console.Write("-------------------- Replace --------------------\r\n");
            Run("TrieFilter(Replace)", () => { tf1.Replace(text); });
            Run("FastFilter(Replace)", () => { ff.Replace(text); });
            Run("StringSearch(Replace)", () => { stringSearch.Replace(text); });
            Run("StringSearchEx(Replace)", () => { stringSearchEx.Replace(text); });

            Run("WordsSearch(Replace)", () => { wordsSearch.Replace(text); });
            Run("WordsSearchEx(Replace)", () => { wordsSearchEx.Replace(text); });
            Run("IllegalWordsQuickSearch(Replace)", () => { illegalWordsQuickSearch.Replace(text); });
            Run("IllegalWordsSearch(Replace)", () => { illegalWordsSearch.Replace(text); });

            Console.Write("-------------------- Regex --------------------\r\n");
            Run("Regex.IsMatch", () => { re.IsMatch(text); });
            Run("Regex.Match", () => { re.Match(text); });
            Run("Regex.Matches", () => { re.Matches(text); });

            Console.Write("-------------------- Regex used Trie tree --------------------\r\n");
            Run("Regex.IsMatch", () => { re2.IsMatch(text); });
            Run("Regex.Match", () => { re2.Match(text); });
            Run("Regex.Matches", () => { re2.Matches(text); });


            Console.ReadKey();
        }
Example #3
0
        static void Main(string[] args)
        {
            ReadBadWord();
            var text = File.ReadAllText("Talk.txt");

            Console.Write("-------------------- ToSenseWord Test --------------------\r\n");

            Run("ToSenseWord1  ", () => { WordTest.ToSenseWord1(text); });
            Run("ToSenseWord2  ", () => { WordTest.ToSenseWord2(text); });
            Run("ToSenseWord3  ", () => { WordTest.ToSenseWord3(text); });
            Run("ToSenseWord4  ", () => { WordTest.ToSenseWord4(text); });
            Run("ToSenseWord5  ", () => { WordTest.ToSenseWord5(text); });
            Run("ToSenseWord6  ", () => { WordTest.ToSenseWord6(text); });
            Run("ToSenseWord7  ", () => { WordTest.ToSenseWord7(text); });
            Run("ToSenseWord8  ", () => { WordTest.ToSenseWord8(text); });
            Run("ToSenseWord9  ", () => { WordTest.ToSenseWord9(text); });
            Run("ToSenseWord10  ", () => { WordTest.ToSenseWord10(text); });

            //Run("GetDisablePostion1  ", () => { WordTest.GetDisablePostion1(text); });
            //Run("GetDisablePostion2  ", () => { WordTest.GetDisablePostion2(text); });
            //Run("GetDisablePostion3  ", () => { WordTest.GetDisablePostion3(text); });
            //Run("GetDisablePostion4  ", () => { WordTest.GetDisablePostion4(text); });
            //Run("GetDisablePostion5  ", () => { WordTest.GetDisablePostion5(text); });
            //Run("GetDisablePostion6  ", () => { WordTest.GetDisablePostion6(text); });
            //Run("GetDisablePostion7  ", () => { WordTest.GetDisablePostion7(text); });
            //Run("GetDisablePostion9  ", () => { WordTest.GetDisablePostion9(text); });
            //Run("GetDisablePostion8  ", () => { WordTest.GetDisablePostion8(text); });

            Console.Write("-------------------- ToSenseIllegalWords --------------------\r\n");

            Run("ToSenseIllegalWords", () => { WordsHelper.ToSenseIllegalWords(text); });



            Console.Write("-------------------- FindFirst OR ContainsAny --------------------\r\n");
            Run("TrieFilter", () => { tf1.HasBadWord(text); });
            Run("FastFilter", () => { ff.HasBadWord(text); });
            Run("StringSearch(ContainsAny)", () => { word.ContainsAny(text); });
            Run("StringSearch(FindFirst)", () => { word.FindFirst(text); });
            Run("WordsSearch(ContainsAny)", () => { search.ContainsAny(text); });
            Run("WordsSearch(FindFirst)", () => { search.FindFirst(text); });
            Run("IllegalWordsQuickSearch(FindFirst)", () => { iword1.FindFirst(text); });
            Run("IllegalWordsQuickSearch(ContainsAny)", () => { iword1.ContainsAny(text); });

            Run("IllegalWordsSearch(FindFirst)", () => { iword2.FindFirst(text); });
            Run("IllegalWordsSearch(ContainsAny)", () => { iword2.ContainsAny(text); });

            Console.Write("-------------------- Find All --------------------\r\n");
            Run("TrieFilter(FindAll)", () => { tf1.FindAll(text); });
            Run("FastFilter(FindAll)", () => { ff.FindAll(text); });
            Run("StringSearch(FindAll)", () => { word.FindAll(text); });
            Run("WordsSearch(FindAll)", () => { search.FindAll(text); });
            Run("IllegalWordsQuickSearch(FindAll)", () => { iword1.FindAll(text); });
            Run("IllegalWordsSearch(FindAll)", () => { iword2.FindAll(text); });
            Console.Write("-------------------- Replace --------------------\r\n");
            Run("TrieFilter(Replace)", () => { tf1.Replace(text); });
            Run("FastFilter(Replace)", () => { ff.Replace(text); });
            Run("StringSearch(Replace)", () => { word.Replace(text); });
            Run("WordsSearch(Replace)", () => { search.Replace(text); });
            Run("IllegalWordsQuickSearch(Replace)", () => { iword1.Replace(text); });
            Run("IllegalWordsSearch(Replace)", () => { iword2.Replace(text); });

            Console.Write("-------------------- Regex --------------------\r\n");
            Run("Regex.IsMatch", () => { re.IsMatch(text); });
            Run("Regex.Match", () => { re.Match(text); });
            Run("Regex.Matches", () => { re.Matches(text); });

            Console.Write("-------------------- Regex used Trie tree --------------------\r\n");
            Run("Regex.IsMatch", () => { re2.IsMatch(text); });
            Run("Regex.Match", () => { re2.Match(text); });
            Run("Regex.Matches", () => { re2.Matches(text); });


            Console.ReadKey();
        }