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());
}
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());
}
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));
});
}
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));
});
}
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));
});
}
Aggregations