Search in sources :

Example 16 with True

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;
}
Also used : Node(org.dmg.pmml.tree.Node) PMMLObject(org.dmg.pmml.PMMLObject) True(org.dmg.pmml.True) FieldName(org.dmg.pmml.FieldName) Predicate(org.dmg.pmml.Predicate) SimplePredicate(org.dmg.pmml.SimplePredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate)

Example 17 with True

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());
}
Also used : ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) True(org.dmg.pmml.True) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) Test(org.junit.Test)

Example 18 with True

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);
}
Also used : IntStream(java.util.stream.IntStream) PMMLModelTestUtils.getRandomSimplePredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimplePredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicate) PMMLModelTestUtils.getRandomCompoundPredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomCompoundPredicate) False(org.dmg.pmml.False) Test(org.junit.Test) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) Collectors(java.util.stream.Collectors) KiePMMLPredicate(org.kie.pmml.commons.model.predicates.KiePMMLPredicate) DataField(org.dmg.pmml.DataField) List(java.util.List) SimplePredicate(org.dmg.pmml.SimplePredicate) Field(org.dmg.pmml.Field) InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) PMMLModelTestUtils.getRandomSimpleSetPredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimpleSetPredicate) True(org.dmg.pmml.True) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) DataField(org.dmg.pmml.DataField) Field(org.dmg.pmml.Field) KiePMMLPredicate(org.kie.pmml.commons.model.predicates.KiePMMLPredicate) InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate) True(org.dmg.pmml.True) CompoundPredicate(org.dmg.pmml.CompoundPredicate) PMMLModelTestUtils.getRandomCompoundPredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomCompoundPredicate) False(org.dmg.pmml.False) PMMLModelTestUtils.getRandomSimplePredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimplePredicate) SimplePredicate(org.dmg.pmml.SimplePredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) PMMLModelTestUtils.getRandomSimpleSetPredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimpleSetPredicate) Test(org.junit.Test)

Example 19 with True

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);
}
Also used : Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Assert.assertTrue(org.junit.Assert.assertTrue) True(org.dmg.pmml.True) Test(org.junit.Test)

Example 20 with True

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);
}
Also used : True(org.dmg.pmml.True) PredicateASTFactoryData(org.kie.pmml.models.drools.ast.factories.PredicateASTFactoryData)

Aggregations

True (org.dmg.pmml.True)21 Node (org.dmg.pmml.tree.Node)9 TreeModel (org.dmg.pmml.tree.TreeModel)7 SimplePredicate (org.dmg.pmml.SimplePredicate)5 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicate)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 FieldName (org.dmg.pmml.FieldName)3 Predicate (org.dmg.pmml.Predicate)3 MiningModel (org.dmg.pmml.mining.MiningModel)3 Segment (org.dmg.pmml.mining.Segment)3 Segmentation (org.dmg.pmml.mining.Segmentation)3 List (java.util.List)2 Model (org.dmg.pmml.Model)2 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 Statement (com.github.javaparser.ast.stmt.Statement)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1