Search in sources :

Example 16 with OP_TYPE

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

the class InstanceFactoriesTestCommon method commonVerifyKiePMMLParameterField.

static void commonVerifyKiePMMLParameterField(KiePMMLParameterField toVerify, ParameterField source) {
    assertNotNull(toVerify);
    assertEquals(source.getName().getValue(), toVerify.getName());
    DATA_TYPE expectedDataType = DATA_TYPE.byName(source.getDataType().value());
    assertEquals(expectedDataType, toVerify.getDataType());
    OP_TYPE expectedOpType = OP_TYPE.byName(source.getOpType().value());
    assertEquals(expectedOpType, toVerify.getOpType());
    String expectedDisplayName = "Display-" + source.getName().getValue();
    assertEquals(expectedDisplayName, toVerify.getDisplayName());
}
Also used : OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE)

Example 17 with OP_TYPE

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

the class InstanceFactoriesTestCommon method commonVerifyKiePMMLTarget.

static void commonVerifyKiePMMLTarget(KiePMMLTarget toVerify, Target source) {
    assertNotNull(toVerify);
    assertEquals(toVerify.getTargetValues().size(), source.getTargetValues().size());
    OP_TYPE expectedOpType = OP_TYPE.byName(source.getOpType().value());
    assertEquals(expectedOpType, toVerify.getOpType());
    assertEquals(source.getField().getValue(), toVerify.getField());
    CAST_INTEGER expectedCastInteger = CAST_INTEGER.byName(source.getCastInteger().value());
    assertEquals(expectedCastInteger, toVerify.getCastInteger());
    assertEquals(source.getMin().doubleValue(), toVerify.getMin(), 0.0);
    assertEquals(source.getMax().doubleValue(), toVerify.getMax(), 0.0);
    assertEquals(source.getRescaleConstant().doubleValue(), toVerify.getRescaleConstant(), 0.0);
    assertEquals(source.getRescaleFactor().doubleValue(), toVerify.getRescaleFactor(), 0.0);
}
Also used : OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) CAST_INTEGER(org.kie.pmml.api.enums.CAST_INTEGER)

Example 18 with OP_TYPE

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

the class ModelUtilsTest method convertToKieOutputField.

@Test
public void convertToKieOutputField() {
    final OutputField toConvert = getRandomOutputField();
    org.kie.pmml.api.models.OutputField retrieved = ModelUtils.convertToKieOutputField(toConvert, null);
    assertNotNull(retrieved);
    assertEquals(toConvert.getName().getValue(), retrieved.getName());
    OP_TYPE expectedOpType = OP_TYPE.byName(toConvert.getOpType().value());
    assertEquals(expectedOpType, retrieved.getOpType());
    DATA_TYPE expectedDataType = DATA_TYPE.byName(toConvert.getDataType().value());
    assertEquals(expectedDataType, retrieved.getDataType());
    assertEquals(toConvert.getTargetField().getValue(), retrieved.getTargetField());
    RESULT_FEATURE expectedResultFeature = RESULT_FEATURE.byName(toConvert.getResultFeature().value());
    assertEquals(expectedResultFeature, retrieved.getResultFeature());
    toConvert.setOpType(null);
    toConvert.setTargetField(null);
    retrieved = ModelUtils.convertToKieOutputField(toConvert, null);
    assertNull(retrieved.getOpType());
    assertNull(retrieved.getTargetField());
}
Also used : RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) OutputField(org.dmg.pmml.OutputField) PMMLModelTestUtils.getRandomOutputField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOutputField) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Test(org.junit.Test)

Example 19 with OP_TYPE

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

the class ModelUtilsTest method getTargetFieldsWithTargetFieldsWithoutOptType.

@Test
public void getTargetFieldsWithTargetFieldsWithoutOptType() {
    final Model model = new RegressionModel();
    final DataDictionary dataDictionary = new DataDictionary();
    final MiningSchema miningSchema = new MiningSchema();
    IntStream.range(0, 3).forEach(i -> {
        final String fieldName = "fieldName-" + i;
        final DataField dataField = getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING);
        dataDictionary.addDataFields(dataField);
        final MiningField miningField = getMiningField(fieldName, MiningField.UsageType.PREDICTED);
        miningField.setOpType(null);
        miningSchema.addMiningFields(miningField);
    });
    model.setMiningSchema(miningSchema);
    List<KiePMMLNameOpType> retrieved = ModelUtils.getTargetFields(getFieldsFromDataDictionary(dataDictionary), model);
    assertNotNull(retrieved);
    assertEquals(miningSchema.getMiningFields().size(), retrieved.size());
    retrieved.forEach(kiePMMLNameOpType -> {
        assertTrue(miningSchema.getMiningFields().stream().anyMatch(fld -> kiePMMLNameOpType.getName().equals(fld.getName().getValue())));
        Optional<DataField> optionalDataField = dataDictionary.getDataFields().stream().filter(fld -> kiePMMLNameOpType.getName().equals(fld.getName().getValue())).findFirst();
        assertTrue(optionalDataField.isPresent());
        DataField dataField = optionalDataField.get();
        OP_TYPE expected = OP_TYPE.byName(dataField.getOpType().value());
        assertEquals(expected, kiePMMLNameOpType.getOpType());
    });
}
Also used : KiePMMLNameOpType(org.kie.pmml.commons.model.tuples.KiePMMLNameOpType) RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) ModelUtils.getPrefixedName(org.kie.pmml.compiler.api.utils.ModelUtils.getPrefixedName) Arrays(java.util.Arrays) Date(java.util.Date) Model(org.dmg.pmml.Model) MiningSchema(org.dmg.pmml.MiningSchema) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) Row(org.dmg.pmml.Row) FieldName(org.dmg.pmml.FieldName) FIELD_USAGE_TYPE(org.kie.pmml.api.enums.FIELD_USAGE_TYPE) OpType(org.dmg.pmml.OpType) Map(java.util.Map) InputCell(org.jpmml.model.inlinetable.InputCell) PMMLModelTestUtils.getDataTypes(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataTypes) PMMLModelTestUtils.getMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField) RegressionModel(org.dmg.pmml.regression.RegressionModel) Targets(org.dmg.pmml.Targets) DataType(org.dmg.pmml.DataType) PMMLModelTestUtils.getRandomRow(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomRow) Collectors(java.util.stream.Collectors) PMMLModelTestUtils.getParameterFields(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getParameterFields) DataField(org.dmg.pmml.DataField) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) PMMLModelTestUtils.getArray(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getArray) PMMLModelTestUtils.getRandomDataType(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataType) ParameterField(org.dmg.pmml.ParameterField) IntStream(java.util.stream.IntStream) OutputField(org.dmg.pmml.OutputField) PMMLModelTestUtils.getDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Field(org.dmg.pmml.Field) DerivedField(org.dmg.pmml.DerivedField) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) KiePMMLNameOpType(org.kie.pmml.commons.model.tuples.KiePMMLNameOpType) OutputCell(org.jpmml.model.inlinetable.OutputCell) MiningField(org.dmg.pmml.MiningField) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) DataDictionary(org.dmg.pmml.DataDictionary) Test(org.junit.Test) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) Target(org.dmg.pmml.Target) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Array(org.dmg.pmml.Array) PMMLModelTestUtils.getRandomOutputField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOutputField) PMMLModelTestUtils.getRandomTarget(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTarget) Assert.assertNull(org.junit.Assert.assertNull) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) PMMLModelTestUtils.getTarget(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getTarget) PMMLModelTestUtils.getRandomRowWithCells(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomRowWithCells) Assert.assertEquals(org.junit.Assert.assertEquals) 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) 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) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) RegressionModel(org.dmg.pmml.regression.RegressionModel) Test(org.junit.Test)

Example 20 with OP_TYPE

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

the class ModelUtilsTest method getOpTypeByMiningFields.

@Test
public void getOpTypeByMiningFields() {
    final Model model = new RegressionModel();
    final DataDictionary dataDictionary = new DataDictionary();
    final MiningSchema miningSchema = new MiningSchema();
    IntStream.range(0, 3).forEach(i -> {
        final DataField dataField = getRandomDataField();
        dataDictionary.addDataFields(dataField);
        final MiningField miningField = getRandomMiningField();
        miningField.setName(dataField.getName());
        miningSchema.addMiningFields(miningField);
    });
    model.setMiningSchema(miningSchema);
    miningSchema.getMiningFields().forEach(miningField -> {
        OP_TYPE retrieved = ModelUtils.getOpType(getFieldsFromDataDictionary(dataDictionary), model, miningField.getName().getValue());
        assertNotNull(retrieved);
        OP_TYPE expected = OP_TYPE.byName(miningField.getOpType().value());
        assertEquals(expected, 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) 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) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) RegressionModel(org.dmg.pmml.regression.RegressionModel) Test(org.junit.Test)

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