Search in sources :

Example 21 with DATA_TYPE

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

the class ModelUtilsTest method getTargetFieldTypeWithTargetField.

@Test
public void getTargetFieldTypeWithTargetField() {
    final String fieldName = "fieldName";
    MiningField.UsageType usageType = MiningField.UsageType.PREDICTED;
    MiningField miningField = getMiningField(fieldName, usageType);
    final DataField dataField = getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING);
    final DataDictionary dataDictionary = new DataDictionary();
    dataDictionary.addDataFields(dataField);
    final MiningSchema miningSchema = new MiningSchema();
    miningSchema.addMiningFields(miningField);
    final Model model = new RegressionModel();
    model.setMiningSchema(miningSchema);
    DATA_TYPE retrieved = ModelUtils.getTargetFieldType(getFieldsFromDataDictionary(dataDictionary), model);
    assertNotNull(retrieved);
    assertEquals(DATA_TYPE.STRING, retrieved);
}
Also used : PMMLModelTestUtils.getMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField) MiningField(org.dmg.pmml.MiningField) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) DataField(org.dmg.pmml.DataField) PMMLModelTestUtils.getDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) MiningSchema(org.dmg.pmml.MiningSchema) Model(org.dmg.pmml.Model) RegressionModel(org.dmg.pmml.regression.RegressionModel) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) RegressionModel(org.dmg.pmml.regression.RegressionModel) Test(org.junit.Test)

Example 22 with DATA_TYPE

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

the class ModelUtilsTest method getDataTypeFromDataDictionary.

@Test
public void getDataTypeFromDataDictionary() {
    final DataDictionary dataDictionary = new DataDictionary();
    IntStream.range(0, 3).forEach(i -> {
        final DataField dataField = getRandomDataField();
        dataDictionary.addDataFields(dataField);
    });
    dataDictionary.getDataFields().forEach(dataField -> {
        DATA_TYPE retrieved = ModelUtils.getDATA_TYPE(getFieldsFromDataDictionary(dataDictionary), dataField.getName().getValue());
        assertNotNull(retrieved);
        DATA_TYPE expected = DATA_TYPE.byName(dataField.getDataType().value());
        assertEquals(expected, retrieved);
    });
}
Also used : DataField(org.dmg.pmml.DataField) PMMLModelTestUtils.getDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Test(org.junit.Test)

Example 23 with DATA_TYPE

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

the class ModelUtilsTest method getTargetFieldsWithoutTargetFieldsWithTargets.

@Test
public void getTargetFieldsWithoutTargetFieldsWithTargets() {
    final Model model = new RegressionModel();
    final DataDictionary dataDictionary = new DataDictionary();
    final MiningSchema miningSchema = new MiningSchema();
    final Targets targets = new Targets();
    IntStream.range(0, 3).forEach(i -> {
        final DataField dataField = getRandomDataField();
        dataDictionary.addDataFields(dataField);
        final MiningField miningField = getMiningField(dataField.getName().getValue(), MiningField.UsageType.ACTIVE);
        miningSchema.addMiningFields(miningField);
        final Target targetField = getTarget(dataField.getName().getValue(), null);
        targets.addTargets(targetField);
    });
    model.setMiningSchema(miningSchema);
    model.setTargets(targets);
    Map<String, DATA_TYPE> retrieved = ModelUtils.getTargetFieldsTypeMap(getFieldsFromDataDictionary(dataDictionary), model);
    assertNotNull(retrieved);
    assertTrue(retrieved.isEmpty());
}
Also used : PMMLModelTestUtils.getMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField) MiningField(org.dmg.pmml.MiningField) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) Target(org.dmg.pmml.Target) PMMLModelTestUtils.getRandomTarget(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTarget) PMMLModelTestUtils.getTarget(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getTarget) MiningSchema(org.dmg.pmml.MiningSchema) DataField(org.dmg.pmml.DataField) PMMLModelTestUtils.getDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) Model(org.dmg.pmml.Model) RegressionModel(org.dmg.pmml.regression.RegressionModel) Targets(org.dmg.pmml.Targets) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) RegressionModel(org.dmg.pmml.regression.RegressionModel) Test(org.junit.Test)

Example 24 with DATA_TYPE

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

the class CommonCodegenUtils method getExpressionForDataType.

public static Expression getExpressionForDataType(DataType dataTypeParam) {
    final Expression toReturn;
    if (dataTypeParam != null) {
        final DATA_TYPE dataType = DATA_TYPE.byName(dataTypeParam.value());
        toReturn = new NameExpr(DATA_TYPE.class.getName() + "." + dataType.name());
    } else {
        toReturn = new NullLiteralExpr();
    }
    return toReturn;
}
Also used : NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) Expression(com.github.javaparser.ast.expr.Expression) NameExpr(com.github.javaparser.ast.expr.NameExpr) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE)

Example 25 with DATA_TYPE

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

the class KiePMMLDiscretizeInstanceFactory method getKiePMMLDiscretize.

static KiePMMLDiscretize getKiePMMLDiscretize(final Discretize discretize) {
    List<KiePMMLDiscretizeBin> discretizeBins = discretize.hasDiscretizeBins() ? getKiePMMLDiscretizeBins(discretize.getDiscretizeBins()) : Collections.emptyList();
    String mapMissingTo = discretize.getMapMissingTo() != null ? discretize.getMapMissingTo().toString() : null;
    String defaultValue = discretize.getDefaultValue() != null ? discretize.getDefaultValue().toString() : null;
    DATA_TYPE dataType = discretize.getDataType() != null ? DATA_TYPE.byName(discretize.getDataType().value()) : null;
    return new KiePMMLDiscretize(discretize.getField().getValue(), getKiePMMLExtensions(discretize.getExtensions()), discretizeBins, mapMissingTo, defaultValue, dataType);
}
Also used : KiePMMLDiscretizeBin(org.kie.pmml.commons.model.expressions.KiePMMLDiscretizeBin) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) KiePMMLDiscretize(org.kie.pmml.commons.model.expressions.KiePMMLDiscretize)

Aggregations

DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)36 Test (org.junit.Test)17 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)15 DataField (org.dmg.pmml.DataField)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 INVALID_VALUE_TREATMENT_METHOD (org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD)8 MISSING_VALUE_TREATMENT_METHOD (org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD)8 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)8 List (java.util.List)7 MiningField (org.dmg.pmml.MiningField)7 KiePMMLMiningField (org.kie.pmml.commons.model.KiePMMLMiningField)7 KiePMMLInterval (org.kie.pmml.commons.model.expressions.KiePMMLInterval)7 KiePMMLDefineFunction (org.kie.pmml.commons.transformations.KiePMMLDefineFunction)7 KiePMMLParameterField (org.kie.pmml.commons.transformations.KiePMMLParameterField)7 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 IntStream (java.util.stream.IntStream)6 Assert.assertEquals (org.junit.Assert.assertEquals)6