Пример #1
0
        static void Main(string[] args)
        {
            string textfile = "";

            using (StreamReader fs = new StreamReader(@"C:\Новая папка\1.txt"))
            {
                while (true)
                {
                    string temp = fs.ReadLine();
                    if (temp == null)
                    {
                        break;
                    }
                    textfile += temp + ':';
                }
            }

            Console.WriteLine(textfile);

            Console.ReadKey();
            AhoCorasick.Trie trie = new AhoCorasick.Trie();
            trie.Add("string");
            trie.Build();
            string[] matches = trie.Find(textfile).ToArray();
            foreach (var item in matches)
            {
                Console.WriteLine(item);
                Console.ReadKey();
            }
        }
Пример #2
0
        public void NoString()
        {
            string textfile = "";

            using (StreamReader fs = new StreamReader(@"C:\Новая папка\3.txt"))
            {
                while (true)
                {
                    string temp = fs.ReadLine();
                    if (temp == null)
                    {
                        break;
                    }
                    textfile += temp;
                }
            }



            AhoCorasick.Trie trie = new AhoCorasick.Trie();
            trie.Add("NONONO");
            trie.Build();

            string[] matches = trie.Find(textfile).ToArray();

            Assert.AreEqual(0, matches.Length);
        }
Пример #3
0
    public void Contains()
    {
        string text = "string and stringa ta fsd fafad string!";

        AhoCorasick.Trie trie = new AhoCorasick.Trie();
        trie.Add("sring");
        trie.Add("stringa");
        trie.Build();

        Assert.IsTrue(trie.Find(text).Any());
    }
Пример #4
0
    public void String()
    {
        string text = "string and stringa ta fsd fafad string!";

        AhoCorasick.Trie trie = new AhoCorasick.Trie();
        trie.Add("string");
        trie.Add("and");
        trie.Build();

        trie.Add("NONONO");
        trie.Add("NaNaNa");
        trie.Build();

        string[] matches = trie.Find(text).ToArray();
    }
Пример #5
0
 public Node(TNode word, Trie <T, TValue> .Node <TNode, TNodeValue> parent)
 {
     this.word   = word;
     this.parent = parent;
 }