Beispiel #1
0
        public void SingleWordTest()
        {
            const string SearchTerm = "life";

            var detector = new WordDetector(
                new WordDetectorSettings(SearchTerm));

            // Only whole words should be matched case insensitively, so this text should contain
            // 3 matches.
            const string TestSentence =
                "Life can be a challenge, which is why LifeTime is now offering" +
                " a new life package deal to enhance your life. What a time to be alive.";

            var result = detector.Detect(TestSentence).GetMatchesFor(SearchTerm).Collection;

            // Verify total count.
            Assert.AreEqual(result.Count, 3);

            // Yes, I did count these indexes by hand. Felt pretty stupid while doing it, too,
            // but by the end of the first line I realized it was too late to give up.
            Assert.AreEqual(result[0].Index, 0);
            Assert.AreEqual(result[0].Value, "Life");

            Assert.AreEqual(result[1].Index, 69);
            Assert.AreEqual(result[1].Value, "life");

            Assert.AreEqual(result[2].Index, 103);
            Assert.AreEqual(result[2].Value, "life");
        }
Beispiel #2
0
        public void MultiWordAdvanced()
        {
            const string Search1 = "Pumpkin";
            const string Search2 = "Pineapple";

            var detector = new WordDetector(
                new WordDetectorSettings(new string[] { Search1, Search2 }));

            const string TestSentence =
                "Pumpkin Pineapple pumpkin pineapple pUmpkin pineApple " +
                "pumpkin pIneapple pumpkin. Pineapple. But seriously, pumpkin.";

            var result = detector.Detect(TestSentence);

            var pumpkin   = result.GetMatchesFor(Search1).Collection;
            var pineapple = result.GetMatchesFor(Search2).Collection;

            // I also did these indexes by hand and using math...impressed yet?

            // Pumpkin
            Assert.AreEqual(pumpkin.Count, 6);

            Assert.AreEqual(pumpkin[0].Index, 0);
            Assert.AreEqual(pumpkin[0].Value, "Pumpkin");

            Assert.AreEqual(pumpkin[1].Index, 18);
            Assert.AreEqual(pumpkin[1].Value, "pumpkin");

            Assert.AreEqual(pumpkin[2].Index, 36);
            Assert.AreEqual(pumpkin[2].Value, "pUmpkin");

            Assert.AreEqual(pumpkin[3].Index, 54);
            Assert.AreEqual(pumpkin[3].Value, "pumpkin");

            Assert.AreEqual(pumpkin[4].Index, 72);
            Assert.AreEqual(pumpkin[4].Value, "pumpkin");

            Assert.AreEqual(pumpkin[5].Index, 107);
            Assert.AreEqual(pumpkin[5].Value, "pumpkin");

            //==============================
            // Pineapple

            Assert.AreEqual(pineapple.Count, 5);

            Assert.AreEqual(pineapple[0].Index, 8);
            Assert.AreEqual(pineapple[0].Value, "Pineapple");

            Assert.AreEqual(pineapple[1].Index, 26);
            Assert.AreEqual(pineapple[1].Value, "pineapple");

            Assert.AreEqual(pineapple[2].Index, 44);
            Assert.AreEqual(pineapple[2].Value, "pineApple");

            Assert.AreEqual(pineapple[3].Index, 62);
            Assert.AreEqual(pineapple[3].Value, "pIneapple");

            Assert.AreEqual(pineapple[4].Index, 81);
            Assert.AreEqual(pineapple[4].Value, "Pineapple");
        }
Beispiel #3
0
 private void Handler(WordDetector detector, string message) //через обработчик события передаем всю информацию
 {                                                           //о результате работы парсера представлению
     if (Done != null)
     {
         Done.Invoke(message, detector.Words);
     }
 }
Beispiel #4
0
 public Presenter()//незабываем проинициализировать
 {
     loader             = new HtmlLoader();
     parser             = new Parser();
     detector           = new WordDetector();
     detector.Finished += Handler;
 }
Beispiel #5
0
        public void KeyForEveryUniqueWord()
        {
            // I'm not sure how I feel about this test, since
            // technically the WordDetectorSettings class is what removes redundant
            // keys... It is still useful but may be out of the correct scope.

            var detector = new WordDetector(
                new WordDetectorSettings(
                    new string[] { "A", "b", "apple", "banana", "apple" }));

            var result = detector.Detect("Unimportant text to search.");

            Assert.AreEqual(result.MatchWordCount, 4);
        }
Beispiel #6
0
        private bool ContainsWordMatch(CommentChildData comment, out WordDetectorResult result)
        {
            if (comment == null)
            {
                throw new ArgumentNullException(nameof(comment));
            }

            // Assign a value to result to return.
            result = default;

            var match = WordDetector.Detect(comment.Body);

            bool containsWordMatch = match.TotalMatches > 0;

            if (containsWordMatch)
            {
                result = match;
            }

            return(containsWordMatch);
        }
Beispiel #7
0
        public void ResultKeysMatchInput()
        {
            const string Key1 = "Lopsided";
            const string Key2 = "Forever here";
            const string Key3 = "audio.";

            const string KeyNotInInstance = "I'm Not Used";

            var detector = new WordDetector(
                new WordDetectorSettings(
                    new string[] { Key1, Key2, Key3 }));

            var result = detector.Detect("This text doesn't matter, yet again.");

            // We expect non-null results for all keys we passed into the instance.
            Assert.IsNotNull(result.GetMatchesFor(Key1));
            Assert.IsNotNull(result.GetMatchesFor(Key2));
            Assert.IsNotNull(result.GetMatchesFor(Key3));

            // But for a key that was not passed into the instance, we do expect null.
            Assert.IsNull(result.GetMatchesFor(KeyNotInInstance));
        }
Beispiel #8
0
        // Stateful class that will make sure comments don't get duplicated!

        public CommentFilter(WordDetector wordDetector)
        {
            WordDetector      = wordDetector ?? throw new ArgumentNullException(nameof(wordDetector));
            RecentCommentsIds = new HashedFixedSizeQueue <string>(RecentCommentIdBufferSize);
        }
Beispiel #9
0
	void Start(){
		if(!wd)wd=GetComponent<WordDetector>();
		if(!SpawnMarker)SpawnMarker=wd.PutPastaPosition;
	}