Exemple #1
0
        public HomeController()
        {
            Parser parse = new Parser(tokens);
            Node root = parse.BinaryTree.root;

            Evaluater eval = new Evaluater(root, index);
            List<string> res = eval.result.ToList<string>();
        }
Exemple #2
0
        public void TestParserSimpleLogicExpression()
        {
            Tokens tokens = new Tokens();
            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("w1"));
            tokens.AddToken(new OrToken());
            tokens.AddToken(new WordToken("w2"));
            tokens.AddToken(new ParenthesisEndToken());

            _parser = new Parser(tokens);
            Node treeRoot = _parser.BinaryTree.root;
            Assert.AreEqual(3, _parser.BinaryTree.count);
        }
Exemple #3
0
        public void TestAndNot()
        {
            Tokens tokens = new Tokens();
            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("word6"));
            tokens.AddToken(new AndNotToken());
            tokens.AddToken(new WordToken("word12"));
            tokens.AddToken(new ParenthesisEndToken());

            Parser parse = new Parser(tokens);
            Node root = parse.BinaryTree.root;

            Evaluater eval = new Evaluater(root, index);
            List<string> res = eval.result.ToList<string>();
            Assert.IsNotNull(res);
            Assert.Contains("doc2", res);
            Assert.AreEqual(1, res.Count);
        }
Exemple #4
0
        public void TestParserComplexLogicExpression()
        {
            Tokens tokens = new Tokens();
            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("good men"));
            tokens.AddToken(new OrToken());
            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("evil"));
            tokens.AddToken(new OrToken());
            tokens.AddToken(new WordToken("bad"));
            tokens.AddToken(new ParenthesisEndToken());
            tokens.AddToken(new ParenthesisEndToken());
            tokens.AddToken(new AndToken());
            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("women"));
            tokens.AddToken(new AndToken());
            tokens.AddToken(new WordToken("children"));
            tokens.AddToken(new ParenthesisEndToken());

            _parser = new Parser(tokens);
            Node treeRoot = _parser.BinaryTree.root;
            Assert.AreEqual(9, _parser.BinaryTree.count);
        }
Exemple #5
0
        public void TestParserSingleWordOnly()
        {
            Tokens tokens = new Tokens();
            tokens.AddToken(new WordToken("good men"));

            _parser = new Parser(tokens);
            Node treeRoot = _parser.BinaryTree.root;
            Assert.AreEqual(1, _parser.BinaryTree.count);
        }
Exemple #6
0
        public void TestParserWordsOnlyNoLogic()
        {
            Tokens tokens = new Tokens();
            tokens.AddToken(new WordToken("w1"));
            tokens.AddToken(new WordToken("w2"));
            tokens.AddToken(new WordToken("w3"));
            tokens.AddToken(new WordToken("w4"));
            tokens.AddToken(new WordToken("w5"));
            tokens.AddToken(new WordToken("w6"));
            tokens.AddToken(new WordToken("w7"));

            _parser = new Parser(tokens);
            Node treeRoot = _parser.BinaryTree.root;
            Assert.AreEqual(13, _parser.BinaryTree.count);
        }
Exemple #7
0
        public void TestOr()
        {
            Tokens tokens = new Tokens();
            tokens.AddToken(new WordToken("word1"));
            tokens.AddToken(new WordToken("word2"));
            tokens.AddToken(new WordToken("word4"));
            tokens.AddToken(new WordToken("word6"));
            tokens.AddToken(new WordToken("word8"));

            Parser parse = new Parser(tokens);
            Node root = parse.BinaryTree.root;

            Evaluater eval = new Evaluater(root, index);
            List<string> res = eval.result.ToList<string>();
            Assert.IsNotNull(res);
            Assert.Contains("doc1", res);
            Assert.Contains("doc2", res);
            Assert.Contains("doc3", res);
            Assert.Contains("doc4", res);
            Assert.Contains("doc6", res);
            Assert.AreEqual(5, res.Count);
            Assert.AreNotEqual(2, res.Count);
        }