use of org.dmg.pmml.OutputField in project drools by kiegroup.
the class KiePMMLScorecardModelASTFactory method getKiePMMLDroolsAST.
/**
* Returns the <code>KiePMMLDroolsAST</code> built out of the given parameters.
* It also <b>populate</b> the <b>fieldNameTypeNameMap</b> with mapping between
* original field' name and <b>original type/generated type</b> tupla
*
* @param fields
* @param model
* @param fieldTypeMap
* @param types
* @return
*/
public static KiePMMLDroolsAST getKiePMMLDroolsAST(final List<Field<?>> fields, final Scorecard model, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap, final List<KiePMMLDroolsType> types) {
logger.trace("getKiePMMLDroolsAST {} {} {}", fields, model, fieldTypeMap);
DATA_TYPE targetType = getTargetFieldType(fields, model);
List<OutputField> outputFields = model.getOutput() != null ? model.getOutput().getOutputFields() : Collections.emptyList();
KiePMMLScorecardModelCharacteristicASTFactory factory = KiePMMLScorecardModelCharacteristicASTFactory.factory(fieldTypeMap, outputFields, targetType);
if (model.isUseReasonCodes()) {
factory = factory.withReasonCodes(model.getBaselineScore(), REASONCODE_ALGORITHM.byName(model.getReasonCodeAlgorithm().value()));
}
final List<KiePMMLDroolsRule> rules = factory.declareRulesFromCharacteristics(model.getCharacteristics(), "", model.getInitialScore());
return new KiePMMLDroolsAST(types, rules);
}
use of org.dmg.pmml.OutputField in project drools by kiegroup.
the class KiePMMLTreeModelASTFactory method getKiePMMLDroolsAST.
/**
* Returns the <code>KiePMMLDroolsAST</code> built out of the given parameters.
* It also <b>populate</b> the <b>fieldNameTypeNameMap</b> with mapping between original field' name and <b>original type/generated type</b> tupla
*
* @param dataDictionary
* @param model
* @param fieldTypeMap
* @param types
* @return
*/
public static KiePMMLDroolsAST getKiePMMLDroolsAST(final List<Field<?>> fields, final TreeModel model, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap, final List<KiePMMLDroolsType> types) {
logger.trace("getKiePMMLDroolsAST {} {}", fields, model);
DATA_TYPE targetType = getTargetFieldType(fields, model);
List<OutputField> outputFields = model.getOutput() != null ? model.getOutput().getOutputFields() : Collections.emptyList();
List<KiePMMLDroolsRule> rules = KiePMMLTreeModelNodeASTFactory.factory(fieldTypeMap, outputFields, model.getNoTrueChildStrategy(), targetType).declareRulesFromRootNode(model.getNode(), "");
return new KiePMMLDroolsAST(types, rules);
}
use of org.dmg.pmml.OutputField in project drools by kiegroup.
the class DMNImportPMMLInfo method registerOutputFieldType.
private static void registerOutputFieldType(Model pmmlModel, DMNModelImpl dmnModel, Import i) {
String modelName = pmmlModel.getModelName();
List<OutputField> outputFields = pmmlModel.getOutput() == null ? Collections.emptyList() : pmmlModel.getOutput().getOutputFields();
if (outputFields.size() > 1) {
if (modelName != null && !modelName.isEmpty()) {
// In case of multiple output fields,
// register <import name>.<pmml MODEL name>, being a composite type of the different model outputs fields
Map<String, DMNType> typeMap = new HashMap<>();
outputFields.stream().forEach(field -> {
String fieldName = field.getName().getValue();
BuiltInType ft = getBuiltInTypeByDataType(field.getDataType());
DMNType type = new SimpleTypeImpl(i.getNamespace(), fieldName, null, false, null, dmnModel.getTypeRegistry().resolveType(dmnModel.getDefinitions().getURIFEEL(), ft.getName()), ft);
typeMap.put(fieldName, type);
});
DMNType compositeType = new CompositeTypeImpl(i.getNamespace(), modelName, null, false, typeMap, null, null);
dmnModel.getTypeRegistry().registerType(compositeType);
return;
} else {
// Case of multiple/complex output AND model without name, raise a Warning from the compilation/engine side (for the editor to use FEEL Any as the typeRef in the BKM)
LOG.warn("PMML modelName is not provided, while output is a composite / multiple fields. Unable to synthesize CompositeType for DMN side.");
}
}
}
use of org.dmg.pmml.OutputField 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);
}
use of org.dmg.pmml.OutputField in project drools by kiegroup.
the class PMMLModelTestUtils method getRandomOutputField.
public static OutputField getRandomOutputField(DataField dataField) {
OutputField toReturn = getRandomOutputField();
toReturn.setName(dataField.getName());
toReturn.setDataType(dataField.getDataType());
return toReturn;
}
Aggregations