/** * 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 wrapped left hand side predicate * @return wrapped left hand side predicate */ public QueryPredicate getLhs() { return QueryPredicate.createFrom(xor.getArguments()[0]); }
@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()); }
/** * Returns the wrapped right hand side predicate * @return wrapped right hand side predicate */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(xor.getArguments()[1]); }
@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()); }
/** * Returns the wrapped left hand side predicate * @return wrapped left hand side predicate */ public QueryPredicate getLhs() { return QueryPredicate.createFrom(xor.getArguments()[0]); }
/** * Returns the wrapped right hand side predicate * @return wrapped right hand side predicate */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(xor.getArguments()[1]); }
/** * 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(); }