public static boolean isValidFeatureConjunctionOperand(Predicate operand) { return operand instanceof Negation && ((Negation) operand).getOperand() instanceof FeatureSet && isValidFeatureConjunctionOperand(((Negation) operand).getOperand()) || operand instanceof FeatureSet && ((FeatureSet) operand).getValues().size() == 1; }
private static String getFeatureSetKey(Predicate predicate) { if (predicate instanceof FeatureSet) { return ((FeatureSet) predicate).getKey(); } else { Negation negation = (Negation) predicate; return ((FeatureSet) negation.getOperand()).getKey(); } }
public Predicate simplifyTree(Predicate predicate) { if (predicate instanceof Disjunction) { Disjunction disjunction = (Disjunction) predicate; List<Predicate> newChildren = disjunction.getOperands().stream().map(this::simplifyTree).collect(toList()); return compressFeatureSets(newChildren); } else if (predicate instanceof Negation) { Negation negation = (Negation) predicate; negation.setOperand(simplifyTree(negation.getOperand())); return negation; } else if (predicate instanceof Conjunction) { Conjunction conjunction = (Conjunction) predicate; List<Predicate> newChildren = conjunction.getOperands().stream().map(this::simplifyTree).collect(toList()); conjunction.setOperands(newChildren); return conjunction; } else { return predicate; } }
return simplifySubTree(((Negation) predicate).getOperand(), !negated); } else if (predicate instanceof Conjunction) { List<Predicate> in = ((Conjunction)predicate).getOperands();
Predicate operand = ((Negation)predicate).getOperand(); operand = simplifySubTree(operand); if (isTrue(operand)) {
out.setLong(NODE_TYPE, TYPE_NEGATION); out = out.setArray(CHILDREN); encode(((Negation)predicate).getOperand(), out.addObject()); } else if (predicate instanceof BooleanPredicate) { out.setLong(NODE_TYPE, ((BooleanPredicate)predicate).getValue() ? TYPE_TRUE : TYPE_FALSE);