public void TrieSearch_Should_ReturnExpected() { var trie = new AcPatternMatcher(new List <string> { "abcd", "bcd", "BC", "c", "bc cd" }); var ret = trie.Match("dd abdbc cd zzzz").ToArray(); Assert.AreEqual(4, ret.Length); Assert.AreEqual((6, "bc"), ret[0]); Assert.AreEqual((7, "c"), ret[1]); Assert.AreEqual((9, "c"), ret[2]); Assert.AreEqual((6, "bc cd"), ret[3]); }
/// <summary> /// Search in text with given patterns /// </summary> /// <param name="text">Text</param> /// <param name="acMachine">Aho-Corasick</param> /// <returns>Search results with position</returns> public static IEnumerable <(int position, string value)> Search(this string text, AcPatternMatcher acMatcher) { return(acMatcher.Match(text)); }
/// <summary> /// Search in text with given patterns /// </summary> /// <param name="text">Text</param> /// <param name="patterns">Patterns</param> /// <returns>Search results with position</returns> public static IEnumerable <(int position, string value)> Search(this string text, IEnumerable <string> patterns) { var acMatcher = new AcPatternMatcher(patterns); return(acMatcher.Match(text)); }