Search in sources :

Example 1 with STATUS_NULL

use of org.kie.pmml.models.drools.ast.factories.KiePMMLAbstractModelASTFactory.STATUS_NULL in project drools by kiegroup.

the class KiePMMLSimpleSetPredicateASTFactory method getBuilderForSimpleSetPredicate.

private KiePMMLDroolsRule.Builder getBuilderForSimpleSetPredicate(final String statusToSet) {
    logger.trace("declareRuleFromSimpleSetPredicate {}", statusToSet);
    String statusConstraint = StringUtils.isEmpty(predicateASTFactoryData.getParentPath()) ? STATUS_NULL : String.format(STATUS_PATTERN, predicateASTFactoryData.getParentPath());
    SimpleSetPredicate simpleSetPredicate = (SimpleSetPredicate) predicateASTFactoryData.getPredicate();
    String key = predicateASTFactoryData.getFieldTypeMap().get(simpleSetPredicate.getField().getValue()).getGeneratedType();
    String stringValue = (String) simpleSetPredicate.getArray().getValue();
    String[] valuesArray = stringValue.split(" ");
    List<Object> value = Arrays.stream(valuesArray).map(rawValue -> {
        String originalType = predicateASTFactoryData.getFieldTypeMap().get(simpleSetPredicate.getField().getValue()).getOriginalType();
        switch(originalType) {
            case "string":
                return "\"" + rawValue + "\"";
            case "double":
                return Double.valueOf(rawValue).toString();
            default:
                return rawValue;
        }
    }).collect(Collectors.toList());
    Map<String, List<Object>> constraints = Collections.singletonMap(key, value);
    KiePMMLDroolsRule.Builder toReturn = KiePMMLDroolsRule.builder(predicateASTFactoryData.getCurrentRule(), statusToSet, predicateASTFactoryData.getOutputFields()).withStatusConstraint(statusConstraint);
    if (SimpleSetPredicate.BooleanOperator.IS_IN.equals(simpleSetPredicate.getBooleanOperator())) {
        toReturn = toReturn.withInConstraints(constraints);
    } else {
        toReturn = toReturn.withNotInConstraints(constraints);
    }
    return toReturn;
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) DONE(org.kie.pmml.commons.Constants.DONE) List(java.util.List) KiePMMLReasonCodeAndValue(org.kie.pmml.models.drools.tuples.KiePMMLReasonCodeAndValue) Map(java.util.Map) STATUS_PATTERN(org.kie.pmml.models.drools.ast.factories.KiePMMLAbstractModelASTFactory.STATUS_PATTERN) Collections(java.util.Collections) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) STATUS_NULL(org.kie.pmml.models.drools.ast.factories.KiePMMLAbstractModelASTFactory.STATUS_NULL) StringUtils(org.drools.core.util.StringUtils) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) List(java.util.List) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate)

Aggregations

Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicate)1 StringUtils (org.drools.core.util.StringUtils)1 DONE (org.kie.pmml.commons.Constants.DONE)1 KiePMMLDroolsRule (org.kie.pmml.models.drools.ast.KiePMMLDroolsRule)1 STATUS_NULL (org.kie.pmml.models.drools.ast.factories.KiePMMLAbstractModelASTFactory.STATUS_NULL)1 STATUS_PATTERN (org.kie.pmml.models.drools.ast.factories.KiePMMLAbstractModelASTFactory.STATUS_PATTERN)1 KiePMMLReasonCodeAndValue (org.kie.pmml.models.drools.tuples.KiePMMLReasonCodeAndValue)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1