/** * Processes a conjuctive expression (AND, OR, XOR) and connects the filter with the corresponding operator * * @param conjunctions list of conjunction operators */ private void processConjunctionExpression(List<TerminalNode> conjunctions) { Predicate conjunctionReuse; for (int i = conjunctions.size() - 1; i >= 0; i--) { Predicate rhs = currentPredicates.removeLast(); Predicate lhs = currentPredicates.removeLast(); switch (conjunctions.get(i).getText().toLowerCase()) { case "and": conjunctionReuse = new And(lhs, rhs); break; case "or": conjunctionReuse = new Or(lhs, rhs); break; default: conjunctionReuse = new Xor(lhs, rhs); break; } currentPredicates.add(conjunctionReuse); } }
/** * Returns the left hand side predicate * @return the left hand side predicate */ public QueryPredicate getLhs() { return QueryPredicate.createFrom(or.getArguments()[0]); }
@Test public void testGetLhs() { Comparison a = getComparison(); Comparison b = getComparison(); OrPredicate orPredicate = new OrPredicate(new Or(a, b)); assertEquals(new ComparisonExpression(a), orPredicate.getLhs()); }
/** * Returns the right hand side predicate * @return the right hand side predicate */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(or.getArguments()[1]); }
@Test public void testGetRhs() { Comparison a = getComparison(); Comparison b = getComparison(); OrPredicate orPredicate = new OrPredicate(new Or(a, b)); assertEquals(new ComparisonExpression(b), orPredicate.getRhs()); }
/** * Returns the left hand side predicate * @return the left hand side predicate */ public QueryPredicate getLhs() { return QueryPredicate.createFrom(or.getArguments()[0]); }
@Test public void testGetRhs() { Comparison a = getComparison(); Comparison b = getComparison(); OrPredicate orPredicate = new OrPredicate(new Or(a, b)); assertEquals(new ComparisonExpression(b), orPredicate.getRhs()); }
/** * Returns the right hand side predicate * @return the right hand side predicate */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(or.getArguments()[1]); }
@Test public void testGetLhs() { Comparison a = getComparison(); Comparison b = getComparison(); OrPredicate orPredicate = new OrPredicate(new Or(a, b)); assertEquals(new ComparisonExpression(a), orPredicate.getLhs()); }
@Test public void convertToCnfTest() { Comparison a = getComparison(); Comparison b = getComparison(); OrPredicate orPredicate = new OrPredicate(new Or(a, b)); CNF reference = orPredicate.getLhs().asCNF().or(orPredicate.getRhs().asCNF()); assertEquals(reference, orPredicate.asCNF()); }
/** * Converts the predicate into conjunctive normal form * * @return predicate in cnf */ public CNF asCNF() { Predicate lhs = xor.getArguments()[0]; Predicate rhs = xor.getArguments()[1]; QueryPredicate wrapper = QueryPredicate.createFrom( new Or(new And(lhs, new Not(rhs)), new And(new Not(lhs), rhs)) ); return wrapper.asCNF(); }
/** * Converts the predicate into conjunctive normal form * * @return predicate in cnf */ public CNF asCNF() { Predicate lhs = xor.getArguments()[0]; Predicate rhs = xor.getArguments()[1]; QueryPredicate wrapper = QueryPredicate.createFrom( new Or(new And(lhs, new Not(rhs)), new And(new Not(lhs), rhs)) ); return wrapper.asCNF(); }
@Test public void convertToCnfTest() { Comparison a = getComparison(); Comparison b = getComparison(); XorPredicate xorPredicate = new XorPredicate(new Xor(a, b)); CNF reference = new OrPredicate( new Or( new And( a, new Not(b) ), new And( new Not(a), b ) ) ).asCNF(); assertEquals(reference, xorPredicate.asCNF()); }
@Test public void convertNestedOrToCnfTest() { Comparison a = getComparison(); Comparison b = getComparison(); Or or = new Or(a, b); NotPredicate notPredicate = new NotPredicate(new Not(or)); CNF reference = new ComparisonExpression(invert(a)).asCNF().and(new ComparisonExpression(invert(b)).asCNF()); assertEquals(reference, notPredicate.asCNF()); }
@Test public void convertNestedXorToCnfTest() { Comparison a = getComparison(); Comparison b = getComparison(); Xor xor = new Xor(a, b); NotPredicate notPredicate = new NotPredicate(new Not(xor)); CNF reference = QueryPredicate.createFrom( new Or( new And(a, b), new And( new Not(a), new Not(b) ) ) ).asCNF(); assertEquals(reference, notPredicate.asCNF()); }