/** * Adds a list of predicates to the current predicates using AND conjunctions * * @param newPredicates predicates to be added */ private void addPredicates(List<Predicate> newPredicates) { for(Predicate newPredicate : newPredicates) { if(this.predicates == null) { this.predicates = newPredicate; } else { this.predicates = new And(this.predicates, newPredicate); } } }
/** * 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(); }
/** * 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()); }
@Test public void convertNestedAndToCnfTest() { Comparison a = getComparison(); Comparison b = getComparison(); And and = new And(a, b); NotPredicate notPredicate = new NotPredicate(new Not(and)); CNF reference = new ComparisonExpression(invert(a)).asCNF().or(new ComparisonExpression(invert(b)).asCNF()); assertEquals(reference, notPredicate.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()); }
/** * Called when we leave an NotExpression. * * Checks if the expression is preceded by a Not and adds the filter in that case. * @param ctx expression context */ @Override public void exitNotExpression(GDLParser.NotExpressionContext ctx) { if (!ctx.NOT().isEmpty()) { Predicate not = new Not(currentPredicates.pop()); currentPredicates.add(not); } }
/** * Retruns the wrapped left hand side predicate * @return the left hand side */ public QueryPredicate getLhs() { return QueryPredicate.createFrom(and.getArguments()[0]); }
/** * Returns the left hand side predicate * @return the left hand side predicate */ public QueryPredicate getLhs() { return QueryPredicate.createFrom(or.getArguments()[0]); }
@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()); }
/** * 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(); }
/** * Returns the wrapped right hand side predicate * @return wrapped right hand side predicate */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(xor.getArguments()[1]); }
/** * Retruns the wrapped right hand side predicate * @return the right hand side */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(and.getArguments()[1]); }
/** * Returns the right hand side predicate * @return the right hand side predicate */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(or.getArguments()[1]); }
/** * Returns the wrapped left hand side predicate * @return wrapped left hand side predicate */ public QueryPredicate getLhs() { return QueryPredicate.createFrom(xor.getArguments()[0]); }
/** * Retruns the wrapped right hand side predicate * @return the right hand side */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(and.getArguments()[1]); }
/** * Returns the left hand side predicate * @return the left hand side predicate */ public QueryPredicate getLhs() { return QueryPredicate.createFrom(or.getArguments()[0]); }
/** * Returns the wrapped right hand side predicate * @return wrapped right hand side predicate */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(xor.getArguments()[1]); }
/** * Retruns the wrapped left hand side predicate * @return the left hand side */ public QueryPredicate getLhs() { return QueryPredicate.createFrom(and.getArguments()[0]); }
/** * Returns the right hand side predicate * @return the right hand side predicate */ public QueryPredicate getRhs() { return QueryPredicate.createFrom(or.getArguments()[1]); }