Exemplo n.º 1
0
    public void Words()
    {
        string[] text = "string1 string2 string3".Split(' ');

        AhoCorasick.Trie <string, bool> trie = new AhoCorasick.Trie <string, bool>();
        trie.Add(new[] { "string1", "string2" }, true);
        trie.Build();

        Assert.IsTrue(trie.Find(text).Any());
    }
Exemplo n.º 2
0
        public void FindNo()
        {
            string[] text = "string my string my no afaffaseds yes find yes".Split(' ');

            AhoCorasick.Trie <string, bool> trie = new AhoCorasick.Trie <string, bool>();
            trie.Add(new[] { "" }, true);
            trie.Build();

            Assert.IsFalse(trie.Find(text).Any());
        }
Exemplo n.º 3
0
    public void LineNumbers()
    {
        string text = "stringa, and and stringb!";

        string[] words = new[] { "stringb", "stringa" };

        AhoCorasick.Trie <int> trie = new AhoCorasick.Trie <int>();
        for (int i = 0; i < words.Length; i++)
        {
            trie.Add(words[i], i);
        }
        trie.Build();

        int[] lines = trie.Find(text).ToArray();

        Assert.AreEqual(2, lines.Length);
        Assert.AreEqual(1, lines[0]);
        Assert.AreEqual(0, lines[1]);
    }