use of org.dmg.pmml.True in project jpmml-sparkml by jpmml.
the class TreeModelCompactor method isCategoricalField.
private boolean isCategoricalField(FieldName name) {
Deque<PMMLObject> parents = getParents();
for (PMMLObject parent : parents) {
if (parent instanceof Node) {
Node node = (Node) parent;
Predicate predicate = node.getPredicate();
if (predicate instanceof SimpleSetPredicate) {
SimpleSetPredicate simpleSetPredicate = (SimpleSetPredicate) predicate;
FieldName categoricalField = simpleSetPredicate.getField();
if ((name).equals(categoricalField)) {
return true;
}
} else if (predicate instanceof True) {
True truePredicate = (True) predicate;
FieldName categoricalField = this.categoricalFields.get(truePredicate);
if ((name).equals(categoricalField)) {
return true;
}
}
} else {
return false;
}
}
return false;
}
use of org.dmg.pmml.True in project drools by kiegroup.
the class KiePMMLTruePredicateASTFactoryTest method declareRuleFromTruePredicateNotFinalLeaf.
@Test
public void declareRuleFromTruePredicateNotFinalLeaf() {
String parentPath = "_will play";
String currentRule = "_will play_will play";
final List<KiePMMLDroolsRule> rules = new ArrayList<>();
True truePredicate = new True();
PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(truePredicate, Collections.emptyList(), rules, parentPath, currentRule, Collections.emptyMap());
KiePMMLTruePredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromTruePredicateWithResult(DONE, false);
assertEquals(1, rules.size());
final KiePMMLDroolsRule retrieved = rules.get(0);
assertNotNull(retrieved);
assertEquals(currentRule, retrieved.getName());
assertEquals(currentRule, retrieved.getStatusToSet());
assertEquals(String.format(STATUS_PATTERN, parentPath), retrieved.getStatusConstraint());
assertNull(retrieved.getAndConstraints());
assertNull(retrieved.getResultCode());
}
use of org.dmg.pmml.True in project drools by kiegroup.
the class KiePMMLPredicateInstanceFactoryTest method getKiePMMLPredicate.
@Test
public void getKiePMMLPredicate() {
List<Field<?>> fields = IntStream.range(0, 3).mapToObj(i -> getRandomDataField()).collect(Collectors.toList());
SimplePredicate simplePredicate1 = getRandomSimplePredicate((DataField) fields.get(0));
KiePMMLPredicate retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(simplePredicate1, fields);
commonVerifyKiePMMLPredicate(retrieved, simplePredicate1);
SimpleSetPredicate simpleSetPredicate = getRandomSimpleSetPredicate((DataField) fields.get(2));
retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(simpleSetPredicate, fields);
commonVerifyKiePMMLPredicate(retrieved, simpleSetPredicate);
final CompoundPredicate compoundPredicate = getRandomCompoundPredicate(fields);
retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(compoundPredicate, fields);
commonVerifyKiePMMLPredicate(retrieved, compoundPredicate);
False falsePredicate = new False();
retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(falsePredicate, fields);
commonVerifyKiePMMLPredicate(retrieved, falsePredicate);
True truePredicate = new True();
retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(truePredicate, fields);
commonVerifyKiePMMLPredicate(retrieved, truePredicate);
}
use of org.dmg.pmml.True in project drools by kiegroup.
the class KiePMMLTruePredicateFactoryTest method getTruePredicateVariableDeclaration.
@Test
public void getTruePredicateVariableDeclaration() throws IOException {
String variableName = "variableName";
BlockStmt retrieved = KiePMMLTruePredicateFactory.getTruePredicateVariableDeclaration(variableName, new True());
String text = getFileContent(TEST_01_SOURCE);
Statement expected = JavaParserUtils.parseBlock(String.format(text, variableName));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(KiePMMLTruePredicate.class, Collections.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.dmg.pmml.True in project drools by kiegroup.
the class KiePMMLTreeModelNodeASTFactory method declareDefaultRuleFromNode.
/**
* This method is meant to be executed when <b>noTrueChildStrategy</b> is <code>TreeModel.NoTrueChildStrategy.RETURN_LAST_PREDICTION</code>, <b>node</b>
* is not a <i>final leaf</i>, and <b>node</b>'s score is not null
* @param node
* @param parentPath
* @param rules
*/
protected void declareDefaultRuleFromNode(final Node node, final String parentPath, final List<KiePMMLDroolsRule> rules) {
logger.trace("declareDefaultRuleFromNode {} {}", node, parentPath);
String originalRule = String.format(PATH_PATTERN, parentPath, node.hashCode());
String currentRule = String.format(PATH_PATTERN, "default", originalRule);
PredicateASTFactoryData predicateASTFactoryData = new PredicateASTFactoryData(new True(), outputFields, rules, originalRule, currentRule, fieldTypeMap);
KiePMMLPredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromPredicate(getCorrectlyFormattedResult(node.getScore(), targetType), true);
}
Aggregations