コード例 #1
0
        public void SecondApplyOnAllTestForOrOperation()
        {
            initTokens();

            var words = new List <string> {
                "ok", "agreement"
            };
            var expectedValue = new HashSet <int> {
            };

            var operation   = new And();
            var actualValue = operation.ApplyOnAll(words, tokens);
        }
コード例 #2
0
        public void ApplyOnAllTestForAndOperationWhenOneWordDoesNotExistInTokens()
        {
            initTokens();

            var words = new List <string> {
                "hello", "bye"
            };
            var expectedValue = new HashSet <int> {
                2, 3, 4, 7
            };

            var operation   = new And();
            var actualValue = operation.ApplyOnAll(words, tokens);

            Assert.Equal(expectedValue, actualValue);
        }
コード例 #3
0
        public void ApplyOnAllTestForAndOperation()
        {
            initTokens();

            var words = new List <string> {
                "world", "first"
            };
            var expectedValue = new HashSet <int> {
                1, 2
            };

            var operation   = new And();
            var actualValue = operation.ApplyOnAll(words, tokens);

            Assert.Equal(expectedValue, actualValue);
        }
コード例 #4
0
        public HashSet <int> Process(string input, int numberOfDocs)
        {
            var wordsWithPlusSign  = RegexOperator.AssortTheWords(input, PLUS_REGEX, 2);
            var wordsWithMinusSign = RegexOperator.AssortTheWords(input, MINUS_REGEX, 2);
            var noneSignWords      = RegexOperator.AssortTheWords(input, NONE_SIGN_REGEX, 2);

            var and = new And();
            var or  = new Or();
            var sub = new Subtract();

            var beforeMinus = and.Apply(and.ApplyOnAll(noneSignWords, tokens),
                                        or.ApplyOnAll(wordsWithPlusSign, tokens));

            if (noneSignWords.Count == 0 && wordsWithPlusSign.Count == 0)
            {
                for (int i = 0; i < numberOfDocs; i++)
                {
                    beforeMinus.Add(i);
                }
            }
            return(sub.Apply(beforeMinus, or.ApplyOnAll(wordsWithMinusSign, tokens)));
        }