Class ModelUtils

java.lang.Object
org.kie.pmml.compiler.api.utils.ModelUtils

public class ModelUtils extends Object
Class to provide common methods to interact with Model, to convert org.dmn.pmml objects to Kie ones, etc...
  • Method Details

    • getTargetFieldName

      public static Optional<String> getTargetFieldName(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)
      Return an Optional with the name of the field whose usageType is TARGET or PREDICTED

      While 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 DATA_TYPE getTargetFieldType(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)
      Return the DATA_TYPE of the field whose usageType is TARGET or PREDICTED. It throws exception if none of such fields are found

      While 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<KiePMMLNameOpType> getTargetFields(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)
      Return a List<KiePMMLNameOpType> of target fields Please note that only predicted/target MiningField are considered.
      Parameters:
      fields -
      model -
      Returns:
    • getTargetFieldsTypeMap

      public static Map<String,DATA_TYPE> getTargetFieldsTypeMap(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model)
      Returns a Map<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/target MiningField are considered.
      Parameters:
      fields -
      model -
      Returns:
    • getOpType

      public static OP_TYPE getOpType(List<org.dmg.pmml.Field<?>> fields, org.dmg.pmml.Model model, String targetFieldName)
      OP_TYPE may be defined inside DataField, MiningField or both. In the latter case, MiningField override DataField definition
      Parameters:
      fields -
      model -
      targetFieldName -
      Returns:
    • getOpTypeFromFields

      public static Optional<OP_TYPE> getOpTypeFromFields(List<org.dmg.pmml.Field<?>> fields, String fieldName)
      Return Optional<OP_TYPE> of field with given fieldName from DataDictionary
      Parameters:
      fields -
      fieldName -
      Returns:
    • getOpTypeFromMiningFields

      public static Optional<OP_TYPE> getOpTypeFromMiningFields(org.dmg.pmml.MiningSchema miningSchema, String fieldName)
      Return Optional<OP_TYPE> of field with given fieldName from MiningSchema
      Parameters:
      miningSchema -
      fieldName -
      Returns:
    • getOpTypeFromTargets

      public static Optional<OP_TYPE> getOpTypeFromTargets(org.dmg.pmml.Targets targets, String fieldName)
      Return Optional<OP_TYPE> of field with given fieldName from Targets
      Parameters:
      targets -
      fieldName -
      Returns:
    • getDataType

      public static org.dmg.pmml.DataType getDataType(List<org.dmg.pmml.Field<?>> fields, String fieldName)
      DataType of the given field, first looked upon derivedFields and then in dataDictionary
      Parameters:
      fields -
      fieldName -
      Returns:
    • getDATA_TYPE

      public static DATA_TYPE getDATA_TYPE(List<org.dmg.pmml.Field<?>> fields, String fieldName)
      DATA_TYPE of 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)
      Return List<DerivedField>s from the given TransformationDictionary and LocalTransformations
      Parameters:
      transformationDictionary -
      localTransformations -
      Returns:
    • getObjectsFromArray

      public static List<Object> getObjectsFromArray(org.dmg.pmml.Array source)
    • convertToKieMiningFieldList

      public static List<MiningField> convertToKieMiningFieldList(org.dmg.pmml.MiningSchema toConvert, List<org.dmg.pmml.Field<?>> fields)
      Return a List<org.kie.pmml.api.models.MiningField&glt; out of a org.dmg.pmml .MiningSchema one
      Parameters:
      toConvert -
      fields -
      Returns:
    • convertToKieMiningField

      public static MiningField convertToKieMiningField(org.dmg.pmml.MiningField toConvert, org.dmg.pmml.Field<?> field)
      Return a org.kie.pmml.api.models.MiningField out of a org.dmg.pmml.MiningField and relative org.dmg.pmml.DataField ones
      Parameters:
      toConvert -
      field -
      Returns:
    • convertToKieOutputFieldList

      public static List<OutputField> convertToKieOutputFieldList(org.dmg.pmml.Output toConvert, List<org.dmg.pmml.Field<?>> fields)
      Return a List<org.kie.pmml.api.models.OutputField> out of a org.dmg.pmml .Output one
      Parameters:
      toConvert -
      Returns:
    • convertToKieOutputFieldList

      public static List<OutputField> convertToKieOutputFieldList(List<org.dmg.pmml.OutputField> toConvert, List<org.dmg.pmml.Field<?>> fields)
      Return a List<org.kie.pmml.api.models.OutputField> out of a List<org.dmg.pmml.OutputField> one
      Parameters:
      toConvert -
      Returns:
    • convertToKieOutputField

      public static OutputField convertToKieOutputField(org.dmg.pmml.OutputField toConvert, org.dmg.pmml.Field<?> field)
      Return a org.kie.pmml.api.models.OutputField out of a org.dmg.pmml.OutputField one
      Parameters:
      toConvert -
      field - - this may be null
      Returns:
    • convertToKieTargetFieldList

      public static List<TargetField> convertToKieTargetFieldList(org.dmg.pmml.Targets toConvert)
      Return a List<org.kie.pmml.api.models.TargetField> out of a org.dmg.pmml .Targets
      Parameters:
      toConvert -
      Returns:
    • convertToKieTargetField

      public static TargetField convertToKieTargetField(org.dmg.pmml.Target toConvert)
      Return a org.kie.pmml.api.models.TargetField out of a org.dmg.pmml.Target
      Parameters:
      toConvert -
      Returns:
    • convertToKieTargetValueList

      public static List<TargetValue> convertToKieTargetValueList(List<org.dmg.pmml.TargetValue> toConvert)
      Return a List<org.kie.pmml.api.models.TargetValue> out of a List<org.dmg.pmml.TargetValue>
      Parameters:
      toConvert -
      Returns:
    • convertToKieTargetValue

      public static TargetValue convertToKieTargetValue(org.dmg.pmml.TargetValue toConvert)
      Return a org.kie.pmml.api.models.TargetValue out of a org.dmg.pmml .TargetValue
      Parameters:
      toConvert -
      Returns:
    • getBoxedClassName

      public static String getBoxedClassName(org.dmg.pmml.ParameterField parameterField)
      Retrieve the mapped class name of the given ParameterField, eventually boxed (for primitive ones) It returns Object ParameterField.getDataType() is null
      Parameters:
      parameterField -
      Returns:
    • getBoxedClassName

      public static String getBoxedClassName(org.dmg.pmml.DataType dataType)
      Retrieve the mapped class name of the given DataType, 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)
    • convertDataFieldValues

      public static List<String> convertDataFieldValues(List<org.dmg.pmml.Value> toConvert)
    • convertDataFieldIntervals

      public static List<Interval> convertDataFieldIntervals(List<org.dmg.pmml.Interval> toConvert)
    • getRowDataMap

      public static Map<String,Object> getRowDataMap(org.dmg.pmml.Row source)
    • getPrefixedName

      public static String getPrefixedName(QName qName)