Пример #1
0
        public void MultiString()
        {
            string textfile = "";

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



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

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

            Assert.AreEqual(2, matches.Length);
            Assert.AreEqual("STRING1", matches[0]);
            Assert.AreEqual("STRING2", matches[1]);
        }
Пример #2
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());
    }
Пример #3
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();
    }
Пример #4
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();
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            //// Input keys (use only 'a'
            //// through 'z' and lower case)
            //string[] keys = {"the", "a", "there", "answer",
            //            "any", "by", "bye", "their"};

            //string[] output = { "Not present in trie", "Present in trie" };

            //root = new TrieNode();

            //// Construct trie
            //int i;
            //for (i = 0; i < keys.Length; i++)
            //    Insert(keys[i]);

            //// Search for different keys
            //if (Search("the") == true)
            //    Console.WriteLine("the --- " + output[1]);
            //else Console.WriteLine("the --- " + output[0]);

            //if (Search("these") == true)
            //    Console.WriteLine("these --- " + output[1]);
            //else Console.WriteLine("these --- " + output[0]);

            //if (Search("their") == true)
            //    Console.WriteLine("their --- " + output[1]);
            //else Console.WriteLine("their --- " + output[0]);

            //if (Search("thaw") == true)
            //    Console.WriteLine("thaw --- " + output[1]);
            //else Console.WriteLine("thaw --- " + output[0]);


            //Trie trie = new Trie();

            //// add words
            //trie.Add("hello");
            //trie.Add("world");

            //// build search tree
            //trie.Build();

            //string text = "hellow and welcome to this beautiful world!";

            //// find words
            //foreach (string word in trie.Find(text))
            //{
            //    Console.WriteLine(word);
            //}

            //Trie<int> trie = new Trie<int>();

            //// add words
            //trie.Add("hello", 123);
            //trie.Add("world", 456);

            //// build search tree
            //trie.Build();

            //string text = "hello and welcome to this beautiful world!";

            //// retrieve IDs
            //foreach (int id in trie.Find(text))
            //{
            //    Console.WriteLine(id);
            //}


            string[] text = "hello world i say to you".Split(' ');

            Trie <string, bool> trie = new Trie <string, bool>();

            trie.Add("hello world".Split(' '), true);
            trie.Build();
            bool containsHelloWorld = trie.Find(text).Any();

            Console.WriteLine(containsHelloWorld);
        }