예제 #1
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();
    }
예제 #2
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();
            }
        }
예제 #3
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);
        }
예제 #4
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());
    }
예제 #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);
        }