Package org.kie.pmml.compiler.api.utils
Class ModelUtils
- java.lang.Object
-
- org.kie.pmml.compiler.api.utils.ModelUtils
-
public class ModelUtils extends Object
Class to provide common methods to interact withModel, to convert org.dmn.pmml objects to Kie ones, etc...
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.kie.pmml.api.models.MiningFieldconvertToKieMiningField(org.dmg.pmml.MiningField toConvert, org.dmg.pmml.Field<?> field)Return aorg.kie.pmml.api.models.MiningFieldout of aorg.dmg.pmml.MiningFieldand relativeorg.dmg.pmml.DataFieldonesstatic List<org.kie.pmml.api.models.MiningField>convertToKieMiningFieldList(org.dmg.pmml.MiningSchema toConvert, List<org.dmg.pmml.Field<?>> fields)Return aList<org.kie.pmml.api.models.MiningField&glt;out of aorg.dmg.pmml .MiningSchemaonestatic org.kie.pmml.api.models.OutputFieldconvertToKieOutputField(org.dmg.pmml.OutputField toConvert, org.dmg.pmml.Field<?> field)Return aorg.kie.pmml.api.models.OutputFieldout of aorg.dmg.pmml.OutputFieldonestatic List<org.kie.pmml.api.models.OutputField>convertToKieOutputFieldList(org.dmg.pmml.Output toConvert, List<org.dmg.pmml.Field<?>> fields)Return aList<org.kie.pmml.api.models.OutputField>out of aorg.dmg.pmml .Outputonestatic org.kie.pmml.commons.model.KiePMMLTargetconvertToKiePMMLTarget(org.dmg.pmml.Target toConvert)Return aorg.kie.pmml.commons.model.KiePMMLTargetout of aorg.dmg.pmml.Targetstatic List<org.kie.pmml.commons.model.KiePMMLTarget>convertToKiePMMLTargetList(org.dmg.pmml.Targets toConvert)Return aList<org.kie.pmml.commons.model.KiePMMLTarget>out of aorg.dmg.pmml .Targetsstatic org.kie.pmml.commons.model.KiePMMLTargetValueconvertToKiePMMLTargetValue(org.dmg.pmml.TargetValue toConvert)Return aorg.kie.pmml.commons.model.KiePMMLTargetValueout of aorg.dmg.pmml .TargetValuestatic List<org.kie.pmml.commons.model.KiePMMLTargetValue>convertToKiePMMLTargetValueList(List<org.dmg.pmml.TargetValue> toConvert)Return aList<org.kie.pmml.commons.model.KiePMMLTargetValue>out of aList<org.dmg.pmml.TargetValue>static StringgetBoxedClassName(org.dmg.pmml.DataType dataType)Retrieve the mapped class name of the givenDataType, eventually boxed (for primitive ones).static StringgetBoxedClassName(org.dmg.pmml.ParameterField parameterField)Retrieve the mapped class name of the givenParameterField, eventually boxed (for primitive ones) It returns ObjectParameterField.getDataType()is nullstatic org.kie.pmml.api.enums.DATA_TYPEgetDATA_TYPE(List<org.dmg.pmml.Field<?>> fields, String fieldName)DATA_TYPEof the given fieldstatic org.dmg.pmml.DataTypegetDataType(List<org.dmg.pmml.Field<?>> fields, String fieldName)DataTypeof the given field, first looked upon derivedFields and then in dataDictionarystatic List<org.dmg.pmml.DerivedField>getDerivedFields(org.dmg.pmml.TransformationDictionary transformationDictionary, org.dmg.pmml.LocalTransformations localTransformations)ReturnList<DerivedField>s from the givenTransformationDictionaryandLocalTransformationsstatic List<org.dmg.pmml.Field<?>>getFieldsFromDataDictionaryAndTransformationDictionary(org.dmg.pmml.DataDictionary dataDictionary, org.dmg.pmml.TransformationDictionary transformationDictionary)static List<org.dmg.pmml.Field<?>>getFieldsFromDataDictionaryTransformationDictionaryAndModel(org.dmg.pmml.DataDictionary dataDictionary, org.dmg.pmml.TransformationDictionary transformationDictionary, org.dmg.pmml.Model model)static List<Object>getObjectsFromArray(org.dmg.pmml.Array source)static org.kie.pmml.api.enums.OP_TYPEgetOpType(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model, String targetFieldName)OP_TYPEmay be defined insideDataField,MiningFieldor both.static Optional<org.kie.pmml.api.enums.OP_TYPE>getOpTypeFromFields(List<org.dmg.pmml.Field<?>> fields, String fieldName)ReturnOptional<OP_TYPE>of field with given fieldName fromDataDictionarystatic Optional<org.kie.pmml.api.enums.OP_TYPE>getOpTypeFromMiningFields(org.dmg.pmml.MiningSchema miningSchema, String fieldName)ReturnOptional<OP_TYPE>of field with given fieldName fromMiningSchemastatic Optional<org.kie.pmml.api.enums.OP_TYPE>getOpTypeFromTargets(org.dmg.pmml.Targets targets, String fieldName)ReturnOptional<OP_TYPE>of field with given fieldName fromTargetsstatic Optional<String>getTargetFieldName(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)Return anOptionalwith the name of the field whose usageType isTARGETorPREDICTEDstatic List<org.kie.pmml.commons.model.tuples.KiePMMLNameOpType>getTargetFields(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)Return aList<KiePMMLNameOpType>of target fields Please note that only predicted/targetMiningFieldare considered.static Map<String,org.kie.pmml.api.enums.DATA_TYPE>getTargetFieldsTypeMap(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)Returns aMap<String, DATA_TYPE>of target fields, where the key is the name of the field, and the value is the type of the field Please note that only predicted/targetMiningFieldare considered.static org.kie.pmml.api.enums.DATA_TYPEgetTargetFieldType(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)Return theDATA_TYPE> of the field whose usageType isTARGETorPREDICTED.
-
-
-
Method Detail
-
getTargetFieldName
public static Optional<String> getTargetFieldName(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)
Return anOptionalwith the name of the field whose usageType isTARGETorPREDICTEDWhile the xsd schema does not strictly enforce this, it seems that by convention majority of models has only one target.
(see https://github.com/jpmml/jpmml-evaluator/issues/64 discussion)
- Parameters:
fields-model-- Returns:
-
getTargetFieldType
public static org.kie.pmml.api.enums.DATA_TYPE getTargetFieldType(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)
Return theDATA_TYPE> of the field whose usageType isTARGETorPREDICTED. It throws exception if none of such fields are foundWhile the xsd schema does not strictly enforce this, it seems that by convention majority of models has only one target.
(see https://github.com/jpmml/jpmml-evaluator/issues/64 discussion)
- Parameters:
fields-model-- Returns:
-
getTargetFields
public static List<org.kie.pmml.commons.model.tuples.KiePMMLNameOpType> getTargetFields(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)
Return aList<KiePMMLNameOpType>of target fields Please note that only predicted/targetMiningFieldare considered.- Parameters:
fields-model-- Returns:
-
getTargetFieldsTypeMap
public static Map<String,org.kie.pmml.api.enums.DATA_TYPE> getTargetFieldsTypeMap(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)
Returns aMap<String, DATA_TYPE>of target fields, where the key is the name of the field, and the value is the type of the field Please note that only predicted/targetMiningFieldare considered.- Parameters:
fields-model-- Returns:
-
getOpType
public static org.kie.pmml.api.enums.OP_TYPE getOpType(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model, String targetFieldName)
OP_TYPEmay be defined insideDataField,MiningFieldor both. In the latter case,MiningFieldoverrideDataFielddefinition- Parameters:
fields-model-targetFieldName-- Returns:
-
getOpTypeFromFields
public static Optional<org.kie.pmml.api.enums.OP_TYPE> getOpTypeFromFields(List<org.dmg.pmml.Field<?>> fields, String fieldName)
ReturnOptional<OP_TYPE>of field with given fieldName fromDataDictionary- Parameters:
fields-fieldName-- Returns:
-
getOpTypeFromMiningFields
public static Optional<org.kie.pmml.api.enums.OP_TYPE> getOpTypeFromMiningFields(org.dmg.pmml.MiningSchema miningSchema, String fieldName)
ReturnOptional<OP_TYPE>of field with given fieldName fromMiningSchema- Parameters:
miningSchema-fieldName-- Returns:
-
getOpTypeFromTargets
public static Optional<org.kie.pmml.api.enums.OP_TYPE> getOpTypeFromTargets(org.dmg.pmml.Targets targets, String fieldName)
ReturnOptional<OP_TYPE>of field with given fieldName fromTargets- Parameters:
targets-fieldName-- Returns:
-
getDataType
public static org.dmg.pmml.DataType getDataType(List<org.dmg.pmml.Field<?>> fields, String fieldName)
DataTypeof the given field, first looked upon derivedFields and then in dataDictionary- Parameters:
fields-fieldName-- Returns:
-
getDATA_TYPE
public static org.kie.pmml.api.enums.DATA_TYPE getDATA_TYPE(List<org.dmg.pmml.Field<?>> fields, String fieldName)
DATA_TYPEof the given field- Parameters:
fields-fieldName-- Returns:
-
getDerivedFields
public static List<org.dmg.pmml.DerivedField> getDerivedFields(org.dmg.pmml.TransformationDictionary transformationDictionary, org.dmg.pmml.LocalTransformations localTransformations)
ReturnList<DerivedField>s from the givenTransformationDictionaryandLocalTransformations- Parameters:
transformationDictionary-localTransformations-- Returns:
-
convertToKieMiningFieldList
public static List<org.kie.pmml.api.models.MiningField> convertToKieMiningFieldList(org.dmg.pmml.MiningSchema toConvert, List<org.dmg.pmml.Field<?>> fields)
Return aList<org.kie.pmml.api.models.MiningField&glt;out of aorg.dmg.pmml .MiningSchemaone- Parameters:
toConvert-fields-- Returns:
-
convertToKieMiningField
public static org.kie.pmml.api.models.MiningField convertToKieMiningField(org.dmg.pmml.MiningField toConvert, org.dmg.pmml.Field<?> field)Return aorg.kie.pmml.api.models.MiningFieldout of aorg.dmg.pmml.MiningFieldand relativeorg.dmg.pmml.DataFieldones- Parameters:
toConvert-field-- Returns:
-
convertToKieOutputFieldList
public static List<org.kie.pmml.api.models.OutputField> convertToKieOutputFieldList(org.dmg.pmml.Output toConvert, List<org.dmg.pmml.Field<?>> fields)
Return aList<org.kie.pmml.api.models.OutputField>out of aorg.dmg.pmml .Outputone- Parameters:
toConvert-- Returns:
-
convertToKieOutputField
public static org.kie.pmml.api.models.OutputField convertToKieOutputField(org.dmg.pmml.OutputField toConvert, org.dmg.pmml.Field<?> field)Return aorg.kie.pmml.api.models.OutputFieldout of aorg.dmg.pmml.OutputFieldone- Parameters:
toConvert-field- - this may benull- Returns:
-
convertToKiePMMLTargetList
public static List<org.kie.pmml.commons.model.KiePMMLTarget> convertToKiePMMLTargetList(org.dmg.pmml.Targets toConvert)
Return aList<org.kie.pmml.commons.model.KiePMMLTarget>out of aorg.dmg.pmml .Targets- Parameters:
toConvert-- Returns:
-
convertToKiePMMLTarget
public static org.kie.pmml.commons.model.KiePMMLTarget convertToKiePMMLTarget(org.dmg.pmml.Target toConvert)
Return aorg.kie.pmml.commons.model.KiePMMLTargetout of aorg.dmg.pmml.Target- Parameters:
toConvert-- Returns:
-
convertToKiePMMLTargetValueList
public static List<org.kie.pmml.commons.model.KiePMMLTargetValue> convertToKiePMMLTargetValueList(List<org.dmg.pmml.TargetValue> toConvert)
Return aList<org.kie.pmml.commons.model.KiePMMLTargetValue>out of aList<org.dmg.pmml.TargetValue>- Parameters:
toConvert-- Returns:
-
convertToKiePMMLTargetValue
public static org.kie.pmml.commons.model.KiePMMLTargetValue convertToKiePMMLTargetValue(org.dmg.pmml.TargetValue toConvert)
Return aorg.kie.pmml.commons.model.KiePMMLTargetValueout of aorg.dmg.pmml .TargetValue- Parameters:
toConvert-- Returns:
-
getBoxedClassName
public static String getBoxedClassName(org.dmg.pmml.ParameterField parameterField)
Retrieve the mapped class name of the givenParameterField, eventually boxed (for primitive ones) It returns ObjectParameterField.getDataType()is null- Parameters:
parameterField-- Returns:
-
getBoxedClassName
public static String getBoxedClassName(org.dmg.pmml.DataType dataType)
Retrieve the mapped class name of the givenDataType, eventually boxed (for primitive ones). It returns Object if null- Parameters:
dataType-- Returns:
-
getFieldsFromDataDictionaryAndTransformationDictionary
public static List<org.dmg.pmml.Field<?>> getFieldsFromDataDictionaryAndTransformationDictionary(org.dmg.pmml.DataDictionary dataDictionary, org.dmg.pmml.TransformationDictionary transformationDictionary)
-
getFieldsFromDataDictionaryTransformationDictionaryAndModel
public static List<org.dmg.pmml.Field<?>> getFieldsFromDataDictionaryTransformationDictionaryAndModel(org.dmg.pmml.DataDictionary dataDictionary, org.dmg.pmml.TransformationDictionary transformationDictionary, org.dmg.pmml.Model model)
-
-