use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.
the class OrSimplifierTest method require_that_non_feature_set_nodes_are_left_untouched.
@Test
public void require_that_non_feature_set_nodes_are_left_untouched() {
Predicate p = or(feature("key1").inSet("value1"), feature("key1").inSet("value2"), not(feature("key1").inSet("value3")));
Predicate expected = or(not(feature("key1").inSet("value3")), feature("key1").inSet("value1", "value2"));
assertConvertedPredicateEquals(expected, p);
}
use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.
the class OrSimplifierTest method require_that_conversion_is_recursive_and_cascades.
@Test
public void require_that_conversion_is_recursive_and_cascades() {
Predicate p = or(feature("key1").inSet("value1", "value4"), feature("key1").inSet("value2", "value3"), or(feature("key1").inSet("value1"), feature("key1").inSet("value4")));
Predicate expected = feature("key1").inSet("value1", "value2", "value3", "value4");
assertConvertedPredicateEquals(expected, p);
}
use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.
the class OrSimplifierTest method require_that_or_with_feature_sets_of_same_key_is_simplified_to_single_feature_set.
@Test
public void require_that_or_with_feature_sets_of_same_key_is_simplified_to_single_feature_set() {
Predicate p = or(feature("key1").inSet("value1", "value4"), feature("key1").inSet("value2", "value3"), feature("key1").inSet("value1", "value4"));
Predicate expected = feature("key1").inSet("value1", "value2", "value3", "value4");
assertConvertedPredicateEquals(expected, p);
}
use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.
the class AndOrSimplifier method simplifySubTree.
public Predicate simplifySubTree(Predicate predicate, boolean negated) {
if (predicate == null) {
return null;
}
if (predicate instanceof Negation) {
return simplifySubTree(((Negation) predicate).getOperand(), !negated);
} else if (predicate instanceof Conjunction) {
List<Predicate> in = ((Conjunction) predicate).getOperands();
List<Predicate> out = new ArrayList<>(in.size());
for (Predicate operand : in) {
operand = simplifySubTree(operand, negated);
if (operand instanceof Conjunction) {
out.addAll(((Conjunction) operand).getOperands());
} else {
out.add(operand);
}
}
if (negated) {
return new Disjunction(out);
}
((Conjunction) predicate).setOperands(out);
} else if (predicate instanceof Disjunction) {
List<Predicate> in = ((Disjunction) predicate).getOperands();
List<Predicate> out = new ArrayList<>(in.size());
for (Predicate operand : in) {
operand = simplifySubTree(operand, negated);
if (operand instanceof Disjunction) {
out.addAll(((Disjunction) operand).getOperands());
} else {
out.add(operand);
}
}
if (negated) {
return new Conjunction(out);
}
((Disjunction) predicate).setOperands(out);
} else {
if (negated) {
return new Negation(predicate);
}
}
return predicate;
}
use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.
the class NotNodeReorderer method processSubTree.
/**
* @return true if the predicate ends in a negation.
*/
public boolean processSubTree(Predicate predicate) {
if (predicate == null) {
return false;
}
if (predicate instanceof Negation) {
// All negations are for leaf-nodes after AndOrSimplifier has run.
return true;
} else if (predicate instanceof Conjunction) {
List<Predicate> in = ((Conjunction) predicate).getOperands();
List<Predicate> out = new ArrayList<>(in.size());
List<Predicate> positiveChildren = new ArrayList<>(in.size());
for (Predicate operand : in) {
if (processSubTree(operand)) {
out.add(operand);
} else {
positiveChildren.add(operand);
}
}
out.addAll(positiveChildren);
((Conjunction) predicate).setOperands(out);
return positiveChildren.isEmpty();
} else if (predicate instanceof Disjunction) {
List<Predicate> in = ((Disjunction) predicate).getOperands();
List<Predicate> out = new ArrayList<>(in.size());
List<Predicate> negativeChildren = new ArrayList<>(in.size());
for (Predicate operand : in) {
if (processSubTree(operand)) {
negativeChildren.add(operand);
} else {
out.add(operand);
}
}
out.addAll(negativeChildren);
((Disjunction) predicate).setOperands(out);
return !negativeChildren.isEmpty();
}
return false;
}
Aggregations