Example #1
0
        private KeywordProcessor GetSimpleProcessor()
        {
            var kp = new KeywordProcessor();

            kp.AddKeywords(new [] { ".NET Core", "Java", "C语言", "字典 tree", "CET-4", "网络 编程" });
            return(kp);
        }
Example #2
0
        public void TestExtractSpans()
        {
            var kp = new KeywordProcessor();

            kp.AddKeywords(new [] { "Big Apple", "Bay Area" });
            var keywords = kp.ExtractKeywordSpans("I love Big Apple and Bay Area.");
            var expected = new List <TextSpan> {
                new TextSpan("Big Apple", 7, 16), new TextSpan("Bay Area", 21, 29)
            };

            CollectionAssert.AreEqual(expected, keywords);
        }
Example #3
0
        public void TestExtract()
        {
            var kp = new KeywordProcessor();

            kp.AddKeywords(new [] { "Big Apple", "Bay Area" });
            var keywords = kp.ExtractKeywords("I love Big Apple and Bay Area.");
            var expected = new List <string> {
                "Big Apple", "Bay Area"
            };

            CollectionAssert.AreEqual(expected, keywords);
        }
Example #4
0
        public void TestRemoveKeyword()
        {
            var kp = new KeywordProcessor();

            kp.AddKeyword(".net core");
            kp.AddKeyword("C# 8.0");
            kp.AddKeywords(new [] { "C# 7.0", "C# 8.0" });

            var keywords = kp.ExtractKeywords("I am learning .net core and c# 8.0");
            var expected = new List <string> {
                ".net core", "C# 8.0"
            };

            CollectionAssert.AreEqual(expected, keywords);

            Assert.That(kp.Contains("C# 8.0"), Is.True);
            kp.RemoveKeyword("C# 8.0");
            Assert.That(kp.Contains("C# 8.0"), Is.False);
            keywords = kp.ExtractKeywords("I am learning .net core and c# 8.0");
            expected = new List <string> {
                ".net core"
            };
            CollectionAssert.AreEqual(expected, keywords);
        }