use of org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate in project knime-core by knime.
the class PMMLRuleTranslator method collectPredicates.
/**
* The predicates of a {@link CompoundRule} in the order they appear.
*
* @param compoundRule An xml {@link CompoundRule}.
* @return The flat list of {@link PMMLPredicate}s.
*/
private List<PMMLPredicate> collectPredicates(final CompoundRule compoundRule) {
List<PMMLPredicate> ret = new ArrayList<PMMLPredicate>();
XmlCursor cursor = compoundRule.newCursor();
if (cursor.toFirstChild()) {
do {
XmlObject object = cursor.getObject();
if (object instanceof CompoundRuleDocument.CompoundRule) {
CompoundRuleDocument.CompoundRule cr = (CompoundRuleDocument.CompoundRule) object;
ret.addAll(collectPredicates(cr));
} else if (object instanceof SimpleRule) {
SimpleRule sr = (SimpleRule) object;
ret.add(createRule(sr).getCondition());
} else if (object instanceof SimplePredicate) {
SimplePredicate sp = (SimplePredicate) object;
ret.add(parseSimplePredicate(sp));
} else if (object instanceof CompoundPredicate) {
CompoundPredicate cp = (CompoundPredicate) object;
ret.add(parseCompoundPredicate(cp));
}
} while (cursor.toNextSibling());
}
return ret;
}
use of org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate in project knime-core by knime.
the class PMMLRuleTranslator method setPredicate.
/**
* As the predicates can be of different subclasses of {@link PMMLPredicate}, creating them adding their properties
* to the {@code simpleRule} is done with this method.
*
* @param simpleRule An xml {@link SimpleRule} (recently created).
* @param predicate A {@link PMMLPredicate} with preferably from the Rule versions of
* {@link PMMLRuleSimplePredicate} and {@link PMMLRuleCompoundPredicate}.
* @since 2.12
*/
public void setPredicate(final SimpleRule simpleRule, final PMMLPredicate predicate) {
if (predicate instanceof PMMLFalsePredicate) {
simpleRule.addNewFalse();
} else if (predicate instanceof PMMLTruePredicate) {
simpleRule.addNewTrue();
} else if (predicate instanceof PMMLSimplePredicate) {
PMMLSimplePredicate simple = (PMMLSimplePredicate) predicate;
SimplePredicate pred = simpleRule.addNewSimplePredicate();
pred.setField(simple.getSplitAttribute());
setOperator(pred, simple);
if (simple.getThreshold() != null) {
pred.setValue(simple.getThreshold());
}
} else if (predicate instanceof PMMLCompoundPredicate) {
PMMLCompoundPredicate comp = (PMMLCompoundPredicate) predicate;
CompoundPredicate p = simpleRule.addNewCompoundPredicate();
setCompound(p, comp);
} else if (predicate instanceof PMMLSimpleSetPredicate) {
PMMLSimpleSetPredicate set = (PMMLSimpleSetPredicate) predicate;
SimpleSetPredicate s = simpleRule.addNewSimpleSetPredicate();
setSetPredicate(s, set);
}
}
use of org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate in project knime-core by knime.
the class PMMLRuleTranslator method setPredicate.
/**
* For an xml {@link CompoundPredicate} ({@code cp}) sets the parameters based on {@code pred}'s properties.
*
* @param cp An xml {@link CompoundPredicate}.
* @param pred The {@link PMMLPredicate} with the rule version subclasses.
*/
private void setPredicate(final CompoundPredicate cp, final PMMLPredicate pred) {
if (pred instanceof PMMLFalsePredicate) {
cp.addNewFalse();
} else if (pred instanceof PMMLTruePredicate) {
cp.addNewTrue();
} else if (pred instanceof PMMLSimplePredicate) {
PMMLSimplePredicate simple = (PMMLSimplePredicate) pred;
SimplePredicate s = cp.addNewSimplePredicate();
s.setField(simple.getSplitAttribute());
setOperator(s, simple);
s.setValue(simple.getThreshold());
} else if (pred instanceof PMMLCompoundPredicate) {
PMMLCompoundPredicate compound = (PMMLCompoundPredicate) pred;
CompoundPredicate c = cp.addNewCompoundPredicate();
setCompound(c, compound);
} else if (pred instanceof PMMLSimpleSetPredicate) {
PMMLSimpleSetPredicate set = (PMMLSimpleSetPredicate) pred;
SimpleSetPredicate ss = cp.addNewSimpleSetPredicate();
setSetPredicate(ss, set);
}
}
Aggregations