Search in sources :

Example 36 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class PMMLModelTestUtils method getDataDictionary.

public static DataDictionary getDataDictionary(List<DataField> dataFields) {
    DataDictionary toReturn = new DataDictionary();
    toReturn.addDataFields(dataFields.toArray(new DataField[0]));
    return toReturn;
}
Also used : DataField(org.dmg.pmml.DataField) DataDictionary(org.dmg.pmml.DataDictionary)

Example 37 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class PMMLModelTestUtils method getDataField.

public static DataField getDataField(String fieldName, OpType opType) {
    DataField toReturn = new DataField();
    toReturn.setName(FieldName.create(fieldName));
    toReturn.setOpType(opType);
    return toReturn;
}
Also used : DataField(org.dmg.pmml.DataField)

Example 38 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class KiePMMLSimpleSetPredicateFactoryTest method getSimpleSetPredicateVariableDeclaration.

@Test
public void getSimpleSetPredicateVariableDeclaration() throws IOException {
    String variableName = "variableName";
    Array.Type arrayType = Array.Type.STRING;
    List<String> values = getStringObjects(arrayType, 4);
    SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate(values, arrayType, SimpleSetPredicate.BooleanOperator.IS_IN);
    String arrayTypeString = ARRAY_TYPE.class.getName() + "." + ARRAY_TYPE.byName(simpleSetPredicate.getArray().getType().value());
    String booleanOperatorString = IN_NOTIN.class.getName() + "." + IN_NOTIN.byName(simpleSetPredicate.getBooleanOperator().value());
    String valuesString = values.stream().map(valueString -> "\"" + valueString + "\"").collect(Collectors.joining(","));
    DataField dataField = new DataField();
    dataField.setName(simpleSetPredicate.getField());
    dataField.setDataType(DataType.DOUBLE);
    DataDictionary dataDictionary = new DataDictionary();
    dataDictionary.addDataFields(dataField);
    BlockStmt retrieved = KiePMMLSimpleSetPredicateFactory.getSimpleSetPredicateVariableDeclaration(variableName, simpleSetPredicate);
    String text = getFileContent(TEST_01_SOURCE);
    Statement expected = JavaParserUtils.parseBlock(String.format(text, variableName, simpleSetPredicate.getField().getValue(), arrayTypeString, booleanOperatorString, valuesString));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(KiePMMLSimpleSetPredicate.class, Arrays.class, Collections.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : Array(org.dmg.pmml.Array) PMMLModelTestUtils.getArray(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getArray) ARRAY_TYPE(org.kie.pmml.api.enums.ARRAY_TYPE) Arrays(java.util.Arrays) JavaParserUtils(org.kie.pmml.compiler.commons.utils.JavaParserUtils) DataType(org.dmg.pmml.DataType) KiePMMLSimpleSetPredicate(org.kie.pmml.commons.model.predicates.KiePMMLSimpleSetPredicate) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) DataDictionary(org.dmg.pmml.DataDictionary) Test(org.junit.Test) Statement(com.github.javaparser.ast.stmt.Statement) Collectors(java.util.stream.Collectors) Array(org.dmg.pmml.Array) FileUtils.getFileContent(org.kie.test.util.filesystem.FileUtils.getFileContent) DataField(org.dmg.pmml.DataField) FieldName(org.dmg.pmml.FieldName) List(java.util.List) PMMLModelTestUtils.getStringObjects(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getStringObjects) CodegenTestUtils.commonValidateCompilationWithImports(org.kie.pmml.compiler.commons.testutils.CodegenTestUtils.commonValidateCompilationWithImports) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) IN_NOTIN(org.kie.pmml.api.enums.IN_NOTIN) PMMLModelTestUtils.getArray(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getArray) Collections(java.util.Collections) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) DataField(org.dmg.pmml.DataField) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) DataDictionary(org.dmg.pmml.DataDictionary) KiePMMLSimpleSetPredicate(org.kie.pmml.commons.model.predicates.KiePMMLSimpleSetPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) Test(org.junit.Test)

Example 39 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class KiePMMLMiningFieldInstanceFactoryTest method getKiePMMLMiningField.

@Test
public void getKiePMMLMiningField() {
    DataField dataField = getRandomDataField();
    MiningField toConvert = getRandomMiningField(dataField);
    KiePMMLMiningField toVerify = KiePMMLMiningFieldInstanceFactory.getKiePMMLMiningField(toConvert, dataField);
    commonVerifyKiePMMLMiningField(toVerify, toConvert, dataField);
}
Also used : InstanceFactoriesTestCommon.commonVerifyKiePMMLMiningField(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLMiningField) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) MiningField(org.dmg.pmml.MiningField) DataField(org.dmg.pmml.DataField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) InstanceFactoriesTestCommon.commonVerifyKiePMMLMiningField(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLMiningField) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) Test(org.junit.Test)

Example 40 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class KiePMMLUtil method load.

/**
 * @param is
 * @return
 * @throws SAXException
 * @throws JAXBException
 * @see org.jpmml.model.PMMLUtil#unmarshal(InputStream)
 */
public static PMML load(final InputStream is, final String fileName) throws SAXException, JAXBException {
    PMML toReturn = org.jpmml.model.PMMLUtil.unmarshal(is);
    String cleanedFileName = fileName.contains(".") ? fileName.substring(0, fileName.indexOf('.')) : fileName;
    List<DataField> dataFields = toReturn.getDataDictionary().getDataFields();
    List<Model> models = toReturn.getModels();
    for (int i = 0; i < models.size(); i++) {
        Model model = models.get(i);
        populateMissingModelName(model, cleanedFileName, i);
        populateMissingOutputFieldDataType(model, dataFields);
        populateMissingMiningTargetField(model, dataFields);
        populateMissingPredictedOutputFieldTarget(model);
        if (model instanceof MiningModel) {
            populateCorrectMiningModel((MiningModel) model);
        }
    }
    return toReturn;
}
Also used : DataField(org.dmg.pmml.DataField) MiningModel(org.dmg.pmml.mining.MiningModel) Model(org.dmg.pmml.Model) MiningModel(org.dmg.pmml.mining.MiningModel) PMML(org.dmg.pmml.PMML)

Aggregations

DataField (org.dmg.pmml.DataField)109 Test (org.junit.Test)51 DataDictionary (org.dmg.pmml.DataDictionary)42 MiningField (org.dmg.pmml.MiningField)42 MiningSchema (org.dmg.pmml.MiningSchema)30 PMMLModelTestUtils.getRandomDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField)28 RegressionModel (org.dmg.pmml.regression.RegressionModel)27 CommonTestingUtils.getFieldsFromDataDictionary (org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary)27 Model (org.dmg.pmml.Model)24 PMMLModelTestUtils.getDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField)22 OutputField (org.dmg.pmml.OutputField)19 PMMLModelTestUtils.getRandomMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField)19 List (java.util.List)18 DataType (org.dmg.pmml.DataType)18 PMMLModelTestUtils.getMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField)18 FieldName (org.dmg.pmml.FieldName)17 PMML (org.dmg.pmml.PMML)17 Collectors (java.util.stream.Collectors)16 ArrayList (java.util.ArrayList)15 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)15