Search in sources :

Example 26 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLDescrLhsFactoryTest method declareLhs.

@Test
public void declareLhs() {
    String name = "NAME";
    String statusToSet = "STATUS_TO_SET";
    KiePMMLDroolsRule rule = KiePMMLDroolsRule.builder(name, statusToSet, Collections.emptyList()).build();
    KiePMMLDescrLhsFactory.factory(lhsBuilder).declareLhs(rule);
    assertNotNull(lhsBuilder.getDescr());
    assertNotNull(lhsBuilder.getDescr().getDescrs());
    assertEquals(1, lhsBuilder.getDescr().getDescrs().size());
    assertTrue(lhsBuilder.getDescr().getDescrs().get(0) instanceof PatternDescr);
    PatternDescr patternDescr = (PatternDescr) lhsBuilder.getDescr().getDescrs().get(0);
    assertEquals(KiePMMLStatusHolder.class.getSimpleName(), patternDescr.getObjectType());
    assertEquals(STATUS_HOLDER, patternDescr.getIdentifier());
    assertTrue(patternDescr.getConstraint() instanceof AndDescr);
    AndDescr andDescr = (AndDescr) patternDescr.getConstraint();
    assertTrue(andDescr.getDescrs().isEmpty());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) KiePMMLStatusHolder(org.kie.pmml.models.drools.executor.KiePMMLStatusHolder) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) Test(org.junit.Test)

Example 27 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLDescrRulesFactoryTest method declareRule.

@Test
public void declareRule() {
    String name = "NAME";
    String statusToSet = "STATUS_TO_SET";
    String patternType = "TEMPERATURE";
    String agendaGroup = "agendaGroup";
    String activationGroup = "activationGroup";
    List<KiePMMLFieldOperatorValue> orConstraints = Arrays.asList(new KiePMMLFieldOperatorValue(patternType, BOOLEAN_OPERATOR.OR, Collections.singletonList(new KiePMMLOperatorValue(OPERATOR.LESS_THAN, 35)), null), new KiePMMLFieldOperatorValue(patternType, BOOLEAN_OPERATOR.AND, Collections.singletonList(new KiePMMLOperatorValue(OPERATOR.GREATER_THAN, 85)), null));
    KiePMMLDroolsRule rule = KiePMMLDroolsRule.builder(name, statusToSet, Collections.emptyList()).withAgendaGroup(agendaGroup).withActivationGroup(activationGroup).withOrConstraints(orConstraints).build();
    KiePMMLDescrRulesFactory.factory(builder).declareRule(rule);
    assertNotNull(builder.getDescr().getRules());
    assertEquals(1, builder.getDescr().getRules().size());
    final RuleDescr retrieved = builder.getDescr().getRules().get(0);
    assertEquals(name, retrieved.getName());
    assertEquals(2, retrieved.getAttributes().size());
    assertTrue(retrieved.getAttributes().containsKey("agenda-group"));
    assertEquals(agendaGroup, retrieved.getAttributes().get("agenda-group").getValue());
    assertTrue(retrieved.getAttributes().containsKey("activation-group"));
    assertEquals(activationGroup, retrieved.getAttributes().get("activation-group").getValue());
}
Also used : KiePMMLOperatorValue(org.kie.pmml.models.drools.tuples.KiePMMLOperatorValue) RuleDescr(org.drools.drl.ast.descr.RuleDescr) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) KiePMMLFieldOperatorValue(org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue) Test(org.junit.Test)

Example 28 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLSimpleSetPredicateASTFactoryTest method declareRuleFromSimpleSetPredicateIsInFinalLeaf.

@Test
public void declareRuleFromSimpleSetPredicateIsInFinalLeaf() {
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    List<String> values = Arrays.asList("-5", "0.5", "1", "10");
    final SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate("input1", values, SimpleSetPredicate.BooleanOperator.IS_IN, fieldTypeMap);
    String parentPath = "_classA";
    String currentRule = "_classA_classB";
    String result = "classB";
    String declaredType = fieldTypeMap.get("input1").getGeneratedType();
    final List<KiePMMLDroolsRule> rules = new ArrayList<>();
    PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(simpleSetPredicate, Collections.emptyList(), rules, parentPath, currentRule, fieldTypeMap);
    KiePMMLSimpleSetPredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromSimpleSetPredicate(result, true);
    assertEquals(1, rules.size());
    final KiePMMLDroolsRule retrieved = rules.get(0);
    assertNotNull(retrieved);
    assertEquals(currentRule, retrieved.getName());
    assertEquals(DONE, retrieved.getStatusToSet());
    assertEquals(String.format(STATUS_PATTERN, parentPath), retrieved.getStatusConstraint());
    assertEquals(ResultCode.OK, retrieved.getResultCode());
    assertEquals(result, retrieved.getResult());
    assertNotNull(retrieved.getInConstraints());
    final Map<String, List<Object>> inConstraints = retrieved.getInConstraints();
    assertEquals(1, inConstraints.size());
    assertTrue(inConstraints.containsKey(declaredType));
    final List<Object> retrievedValues = inConstraints.get(declaredType);
    List<String> originalPredicateValues = Arrays.asList(((String) simpleSetPredicate.getArray().getValue()).split(" "));
    assertEquals(originalPredicateValues.size(), retrievedValues.size());
    retrievedValues.forEach(retrievedValue -> {
        assertTrue(originalPredicateValues.contains(retrievedValue));
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 29 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLSimpleSetPredicateASTFactoryTest method declareRuleFromSimpleSetPredicateIsNotInNotFinalLeaf.

@Test
public void declareRuleFromSimpleSetPredicateIsNotInNotFinalLeaf() {
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    List<String> values = Arrays.asList("3", "8.5");
    final SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate("input2", values, SimpleSetPredicate.BooleanOperator.IS_NOT_IN, fieldTypeMap);
    String parentPath = "_classA";
    String currentRule = "_classA_classC";
    String result = "classC";
    String declaredType = fieldTypeMap.get("input2").getGeneratedType();
    final List<KiePMMLDroolsRule> rules = new ArrayList<>();
    PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(simpleSetPredicate, Collections.emptyList(), rules, parentPath, currentRule, fieldTypeMap);
    KiePMMLSimpleSetPredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromSimpleSetPredicate(result, 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.getResultCode());
    assertNull(retrieved.getResult());
    assertNotNull(retrieved.getNotInConstraints());
    final Map<String, List<Object>> notInConstraints = retrieved.getNotInConstraints();
    assertEquals(1, notInConstraints.size());
    assertTrue(notInConstraints.containsKey(declaredType));
    final List<Object> retrievedValues = notInConstraints.get(declaredType);
    List<String> originalPredicateValues = Arrays.asList(((String) simpleSetPredicate.getArray().getValue()).split(" "));
    assertEquals(originalPredicateValues.size(), retrievedValues.size());
    retrievedValues.forEach(retrievedValue -> {
        assertTrue(originalPredicateValues.contains(retrievedValue));
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 30 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLSimpleSetPredicateASTFactoryTest method declareRuleFromSimpleSetPredicateIsInNotFinalLeaf.

@Test
public void declareRuleFromSimpleSetPredicateIsInNotFinalLeaf() {
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    List<String> values = Arrays.asList("-5", "0.5", "1", "10");
    final SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate("input1", values, SimpleSetPredicate.BooleanOperator.IS_IN, fieldTypeMap);
    String parentPath = "_classA";
    String currentRule = "_classA_classB";
    String result = "classB";
    String declaredType = fieldTypeMap.get("input1").getGeneratedType();
    final List<KiePMMLDroolsRule> rules = new ArrayList<>();
    PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(simpleSetPredicate, Collections.emptyList(), rules, parentPath, currentRule, fieldTypeMap);
    KiePMMLSimpleSetPredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromSimpleSetPredicate(result, 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.getResultCode());
    assertNull(retrieved.getResult());
    assertNotNull(retrieved.getInConstraints());
    final Map<String, List<Object>> inConstraints = retrieved.getInConstraints();
    assertEquals(1, inConstraints.size());
    assertTrue(inConstraints.containsKey(declaredType));
    final List<Object> retrievedValues = inConstraints.get(declaredType);
    List<String> originalPredicateValues = Arrays.asList(((String) simpleSetPredicate.getArray().getValue()).split(" "));
    assertEquals(originalPredicateValues.size(), retrievedValues.size());
    retrievedValues.forEach(retrievedValue -> {
        assertTrue(originalPredicateValues.contains(retrievedValue));
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

KiePMMLDroolsRule (org.kie.pmml.models.drools.ast.KiePMMLDroolsRule)36 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)14 KiePMMLOriginalTypeGeneratedType (org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType)14 KiePMMLASTTestUtils.getPredicateASTFactoryData (org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData)14 SimplePredicate (org.dmg.pmml.SimplePredicate)9 Attribute (org.dmg.pmml.scorecard.Attribute)6 KiePMMLFieldOperatorValue (org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue)6 CompoundPredicate (org.dmg.pmml.CompoundPredicate)5 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicate)5 List (java.util.List)4 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)4 OutputField (org.dmg.pmml.OutputField)3 Characteristic (org.dmg.pmml.scorecard.Characteristic)3 ResultCode (org.kie.pmml.api.enums.ResultCode)3 KiePMMLDroolsAST (org.kie.pmml.models.drools.ast.KiePMMLDroolsAST)3 Map (java.util.Map)2 Field (org.dmg.pmml.Field)2 True (org.dmg.pmml.True)2