Search in sources :

Example 26 with OP_TYPE

use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.

the class KiePMMLParameterFieldInstanceFactory method getKiePMMLParameterField.

static KiePMMLParameterField getKiePMMLParameterField(final ParameterField parameterField) {
    DATA_TYPE dataType = parameterField.getDataType() != null ? DATA_TYPE.byName(parameterField.getDataType().value()) : null;
    OP_TYPE opType = parameterField.getOpType() != null ? OP_TYPE.byName(parameterField.getOpType().value()) : null;
    return KiePMMLParameterField.builder(parameterField.getName().getValue(), Collections.emptyList()).withDataType(dataType).withOpType(opType).withDisplayName(parameterField.getDisplayName()).build();
}
Also used : OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE)

Example 27 with OP_TYPE

use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.

the class KiePMMLClassificationTableFactory method setStaticGetter.

// not-public code-generation
static void setStaticGetter(final RegressionCompilationDTO compilationDTO, final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap, final MethodDeclaration staticGetterMethod, final String variableName) {
    final BlockStmt classificationTableBody = staticGetterMethod.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, staticGetterMethod)));
    final VariableDeclarator variableDeclarator = getVariableDeclarator(classificationTableBody, TO_RETURN).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, TO_RETURN, classificationTableBody)));
    final BlockStmt newBody = new BlockStmt();
    final Map<String, Expression> regressionTableCategoriesMap = new LinkedHashMap<>();
    regressionTablesMap.forEach((className, tableSourceCategory) -> {
        MethodCallExpr methodCallExpr = new MethodCallExpr();
        methodCallExpr.setScope(new NameExpr(className));
        methodCallExpr.setName(KiePMMLRegressionTableFactory.GETKIEPMML_TABLE);
        regressionTableCategoriesMap.put(tableSourceCategory.getCategory(), methodCallExpr);
    });
    // populate map
    String categoryTableMapName = String.format(VARIABLE_NAME_TEMPLATE, CATEGORICAL_TABLE_MAP, variableName);
    createPopulatedLinkedHashMap(newBody, categoryTableMapName, Arrays.asList(String.class.getSimpleName(), KiePMMLRegressionTable.class.getName()), regressionTableCategoriesMap);
    final MethodCallExpr initializer = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, TO_RETURN, classificationTableBody))).asMethodCallExpr();
    final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", initializer);
    builder.setArgument(0, new StringLiteralExpr(variableName));
    final REGRESSION_NORMALIZATION_METHOD regressionNormalizationMethod = compilationDTO.getDefaultREGRESSION_NORMALIZATION_METHOD();
    getChainedMethodCallExprFrom("withRegressionNormalizationMethod", initializer).setArgument(0, new NameExpr(regressionNormalizationMethod.getClass().getSimpleName() + "." + regressionNormalizationMethod.name()));
    OP_TYPE opType = compilationDTO.getOP_TYPE();
    getChainedMethodCallExprFrom("withOpType", initializer).setArgument(0, new NameExpr(opType.getClass().getSimpleName() + "." + opType.name()));
    getChainedMethodCallExprFrom("withCategoryTableMap", initializer).setArgument(0, new NameExpr(categoryTableMapName));
    boolean isBinary = compilationDTO.isBinary(regressionTablesMap.size());
    final Expression probabilityMapFunctionExpression = getProbabilityMapFunctionExpression(compilationDTO.getModelNormalizationMethod(), isBinary);
    getChainedMethodCallExprFrom("withProbabilityMapFunction", initializer).setArgument(0, probabilityMapFunctionExpression);
    getChainedMethodCallExprFrom("withIsBinary", initializer).setArgument(0, getExpressionForObject(isBinary));
    getChainedMethodCallExprFrom("withTargetField", initializer).setArgument(0, getExpressionForObject(compilationDTO.getTargetFieldName()));
    getChainedMethodCallExprFrom("withTargetCategory", initializer).setArgument(0, getExpressionForObject(null));
    classificationTableBody.getStatements().forEach(newBody::addStatement);
    staticGetterMethod.setBody(newBody);
}
Also used : BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) CommonCodegenUtils.getVariableDeclarator(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator) LinkedHashMap(java.util.LinkedHashMap) CommonCodegenUtils.createPopulatedLinkedHashMap(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.createPopulatedLinkedHashMap) Expression(com.github.javaparser.ast.expr.Expression) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) REGRESSION_NORMALIZATION_METHOD(org.kie.pmml.models.regression.model.enums.REGRESSION_NORMALIZATION_METHOD) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 28 with OP_TYPE

use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.

the class ModelUtils method convertToKieTargetField.

/**
 * Return a <code>org.kie.pmml.api.models.TargetField</code> out of a <code>org.dmg.pmml.Target</code>
 * @param toConvert
 * @return
 */
public static TargetField convertToKieTargetField(final Target toConvert) {
    final List<org.kie.pmml.api.models.TargetValue> targetValues = convertToKieTargetValueList(toConvert.getTargetValues());
    final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
    final CAST_INTEGER castInteger = toConvert.getCastInteger() != null ? CAST_INTEGER.byName(toConvert.getCastInteger().value()) : null;
    final Double min = toConvert.getMin() != null ? toConvert.getMin().doubleValue() : null;
    final Double max = toConvert.getMax() != null ? toConvert.getMax().doubleValue() : null;
    final Double rescaleConstant = toConvert.getRescaleConstant() != null ? toConvert.getRescaleConstant().doubleValue() : null;
    final Double rescaleFactor = toConvert.getRescaleFactor() != null ? toConvert.getRescaleFactor().doubleValue() : null;
    return new TargetField(targetValues, opType, toConvert.getField().getValue(), castInteger, min, max, rescaleConstant, rescaleFactor);
}
Also used : TargetValue(org.dmg.pmml.TargetValue) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) CAST_INTEGER(org.kie.pmml.api.enums.CAST_INTEGER) TargetField(org.kie.pmml.api.models.TargetField)

Example 29 with OP_TYPE

use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.

the class ModelUtils method convertToKieOutputField.

/**
 * Return a <code>org.kie.pmml.api.models.OutputField</code> out of a <code>org.dmg.pmml.OutputField</code> one
 * @param toConvert
 * @param field - this may be <code>null</code>
 * @return
 */
public static org.kie.pmml.api.models.OutputField convertToKieOutputField(final OutputField toConvert, final Field<?> field) {
    final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
    final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
    final DATA_TYPE dataFieldDataType = field != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
    final DATA_TYPE dataType = toConvert.getDataType() != null ? DATA_TYPE.byName(toConvert.getDataType().value()) : dataFieldDataType;
    final String targetField = toConvert.getTargetField() != null ? toConvert.getTargetField().getValue() : null;
    final RESULT_FEATURE resultFeature = toConvert.getResultFeature() != null ? RESULT_FEATURE.byName(toConvert.getResultFeature().value()) : null;
    final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : null;
    return new org.kie.pmml.api.models.OutputField(name, opType, dataType, targetField, resultFeature, allowedValues);
}
Also used : DataField(org.dmg.pmml.DataField) RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) OutputField(org.dmg.pmml.OutputField) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE)

Example 30 with OP_TYPE

use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.

the class ModelUtils method convertToKieMiningField.

/**
 * Return a <code>org.kie.pmml.api.models.MiningField</code> out of a <code>org.dmg.pmml.MiningField</code> and
 * relative <code>org.dmg.pmml.DataField</code> ones
 * @param toConvert
 * @param field
 * @return
 */
public static org.kie.pmml.api.models.MiningField convertToKieMiningField(final MiningField toConvert, final Field<?> field) {
    final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
    final FIELD_USAGE_TYPE fieldUsageType = toConvert.getUsageType() != null ? FIELD_USAGE_TYPE.byName(toConvert.getUsageType().value()) : null;
    final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
    final DATA_TYPE dataType = field.getDataType() != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
    final MISSING_VALUE_TREATMENT_METHOD missingValueTreatmentMethod = toConvert.getMissingValueTreatment() != null ? MISSING_VALUE_TREATMENT_METHOD.byName(toConvert.getMissingValueTreatment().value()) : null;
    final INVALID_VALUE_TREATMENT_METHOD invalidValueTreatmentMethod = toConvert.getInvalidValueTreatment() != null ? INVALID_VALUE_TREATMENT_METHOD.byName(toConvert.getInvalidValueTreatment().value()) : null;
    final String missingValueReplacement = toConvert.getMissingValueReplacement() != null ? toConvert.getMissingValueReplacement().toString() : null;
    final String invalidValueReplacement = toConvert.getInvalidValueReplacement() != null ? toConvert.getInvalidValueReplacement().toString() : null;
    final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : Collections.emptyList();
    final List<org.kie.pmml.api.models.Interval> intervals = field instanceof DataField ? convertDataFieldIntervals(((DataField) field).getIntervals()) : Collections.emptyList();
    return new org.kie.pmml.api.models.MiningField(name, fieldUsageType, opType, dataType, missingValueTreatmentMethod, invalidValueTreatmentMethod, missingValueReplacement, invalidValueReplacement, allowedValues, intervals);
}
Also used : MiningField(org.dmg.pmml.MiningField) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD) MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) FIELD_USAGE_TYPE(org.kie.pmml.api.enums.FIELD_USAGE_TYPE) DataField(org.dmg.pmml.DataField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Interval(org.dmg.pmml.Interval)

Aggregations

OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)31 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)14 DataField (org.dmg.pmml.DataField)13 Test (org.junit.Test)13 MiningField (org.dmg.pmml.MiningField)12 DataDictionary (org.dmg.pmml.DataDictionary)8 MiningSchema (org.dmg.pmml.MiningSchema)8 OutputField (org.dmg.pmml.OutputField)8 CommonTestingUtils.getFieldsFromDataDictionary (org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary)8 PMMLModelTestUtils.getDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField)8 PMMLModelTestUtils.getMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField)8 PMMLModelTestUtils.getRandomDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField)8 PMMLModelTestUtils.getRandomMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField)8 Model (org.dmg.pmml.Model)7 Target (org.dmg.pmml.Target)7 RegressionModel (org.dmg.pmml.regression.RegressionModel)7 FIELD_USAGE_TYPE (org.kie.pmml.api.enums.FIELD_USAGE_TYPE)7 DataType (org.dmg.pmml.DataType)6 DerivedField (org.dmg.pmml.DerivedField)6 ParameterField (org.dmg.pmml.ParameterField)6