Search in sources :

Example 1 with KiePMMLTarget

use of org.kie.pmml.commons.model.KiePMMLTarget in project drools by kiegroup.

the class KiePMMLTargetInstanceFactory method getKiePMMLTarget.

public static KiePMMLTarget getKiePMMLTarget(final Target target) {
    final List<TargetValue> targetValues = target.hasTargetValues() ? target.getTargetValues().stream().map(KiePMMLTargetInstanceFactory::getKieTargetValue).collect(Collectors.toList()) : Collections.emptyList();
    final OP_TYPE opType = target.getOpType() != null ? OP_TYPE.byName(target.getOpType().value()) : null;
    final String field = target.getField() != null ? target.getField().getValue() : null;
    final CAST_INTEGER castInteger = target.getCastInteger() != null ? CAST_INTEGER.byName(target.getCastInteger().value()) : null;
    TargetField targetField = new TargetField(targetValues, opType, field, castInteger, target.getMin(), target.getMax(), target.getRescaleConstant(), target.getRescaleFactor());
    final KiePMMLTarget.Builder builder = KiePMMLTarget.builder(targetField.getName(), Collections.emptyList(), targetField);
    return builder.build();
}
Also used : TargetValue(org.kie.pmml.api.models.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) KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget)

Example 2 with KiePMMLTarget

use of org.kie.pmml.commons.model.KiePMMLTarget in project drools by kiegroup.

the class KiePMMLTargetInstanceFactoryTest method getKiePMMLTarget.

@Test
public void getKiePMMLTarget() {
    final Target toConvert = getRandomTarget();
    KiePMMLTarget retrieved = KiePMMLTargetInstanceFactory.getKiePMMLTarget(toConvert);
    commonVerifyKiePMMLTarget(retrieved, toConvert);
}
Also used : KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget) InstanceFactoriesTestCommon.commonVerifyKiePMMLTarget(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLTarget) Target(org.dmg.pmml.Target) PMMLModelTestUtils.getRandomTarget(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTarget) KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget) InstanceFactoriesTestCommon.commonVerifyKiePMMLTarget(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLTarget) Test(org.junit.Test)

Example 3 with KiePMMLTarget

use of org.kie.pmml.commons.model.KiePMMLTarget in project drools by kiegroup.

the class PostProcessTest method executeTargets.

@Test
public void executeTargets() {
    // Build model
    String TARGET_NAME = "TARGET_NAME";
    String FIELD_NAME = "FIELD_NAME";
    TargetField targetField = new TargetField(Collections.emptyList(), null, FIELD_NAME, null, 4.34, null, null, null);
    KiePMMLTarget kiePMMLTarget = KiePMMLTarget.builder(TARGET_NAME, Collections.emptyList(), targetField).build();
    List<KiePMMLTarget> kiePMMLTargets = Arrays.asList(kiePMMLTarget, KiePMMLTarget.builder("NEW_TARGET", Collections.emptyList(), new TargetField(Collections.emptyList(), null, "NEW_TARGET", null, null, null, null, null)).build());
    KiePMMLTestingModel model = KiePMMLTestingModel.builder("TESTINGMODEL", Collections.emptyList(), MINING_FUNCTION.REGRESSION).withKiePMMLTargets(kiePMMLTargets).build();
    // Build PMML4Result
    PMML4Result toModify = new PMML4Result();
    toModify.setResultCode(ResultCode.FAIL.getName());
    toModify.addResultVariable(FIELD_NAME, 4.33);
    assertEquals(4.33, toModify.getResultVariables().get(FIELD_NAME));
    ProcessingDTO processingDTO = getProcessingDTO(model, new ArrayList<>());
    PostProcess.executeTargets(toModify, processingDTO);
    assertEquals(4.33, toModify.getResultVariables().get(FIELD_NAME));
    toModify.setResultCode(ResultCode.OK.getName());
    PostProcess.executeTargets(toModify, processingDTO);
    assertEquals(4.33, toModify.getResultVariables().get(FIELD_NAME));
    toModify.setResultObjectName(FIELD_NAME);
    PostProcess.executeTargets(toModify, processingDTO);
    assertEquals(4.34, toModify.getResultVariables().get(FIELD_NAME));
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) TargetField(org.kie.pmml.api.models.TargetField) KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget) Test(org.junit.Test)

Aggregations

KiePMMLTarget (org.kie.pmml.commons.model.KiePMMLTarget)3 Test (org.junit.Test)2 TargetField (org.kie.pmml.api.models.TargetField)2 Target (org.dmg.pmml.Target)1 PMML4Result (org.kie.api.pmml.PMML4Result)1 CAST_INTEGER (org.kie.pmml.api.enums.CAST_INTEGER)1 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)1 TargetValue (org.kie.pmml.api.models.TargetValue)1 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)1 ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)1 KiePMMLTestingModel (org.kie.pmml.commons.testingutility.KiePMMLTestingModel)1 PMMLModelTestUtils.getRandomTarget (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTarget)1 InstanceFactoriesTestCommon.commonVerifyKiePMMLTarget (org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLTarget)1