use of org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary in project knime-core by knime.
the class PMMLMapValuesTranslator method exportToTransDict.
/**
* {@inheritDoc}
*/
@Override
public TransformationDictionary exportToTransDict() {
TransformationDictionary dictionary = TransformationDictionary.Factory.newInstance();
dictionary.setDerivedFieldArray(createDerivedFields());
return dictionary;
}
use of org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary in project knime-core by knime.
the class DerivedFieldMapper method getDerivedFields.
/**
* @param pmml the pmml document to retrieve the derived fields from
* @return all derived fields from the transformation dictionary as well as
* of all local transformation elements, or an empty array if no
* derived fields are defined.
*/
public static DerivedField[] getDerivedFields(final PMML pmml) {
List<DerivedField> derivedFields = new ArrayList<DerivedField>();
TransformationDictionary trans = pmml.getTransformationDictionary();
if (trans != null) {
derivedFields.addAll(Arrays.asList(trans.getDerivedFieldArray()));
}
LocalTransformations localTrans = null;
if (pmml.getAssociationModelArray().length > 0) {
localTrans = pmml.getAssociationModelArray(0).getLocalTransformations();
} else if (pmml.getClusteringModelArray().length > 0) {
localTrans = pmml.getClusteringModelArray(0).getLocalTransformations();
} else if (pmml.getGeneralRegressionModelArray().length > 0) {
localTrans = pmml.getGeneralRegressionModelArray(0).getLocalTransformations();
} else if (pmml.getNaiveBayesModelArray().length > 0) {
localTrans = pmml.getNaiveBayesModelArray(0).getLocalTransformations();
} else if (pmml.getNeuralNetworkArray().length > 0) {
localTrans = pmml.getNeuralNetworkArray(0).getLocalTransformations();
} else if (pmml.getRegressionModelArray().length > 0) {
localTrans = pmml.getRegressionModelArray(0).getLocalTransformations();
} else if (pmml.getRuleSetModelArray().length > 0) {
localTrans = pmml.getRuleSetModelArray(0).getLocalTransformations();
} else if (pmml.getSequenceModelArray().length > 0) {
localTrans = pmml.getSequenceModelArray(0).getLocalTransformations();
} else if (pmml.getSupportVectorMachineModelArray().length > 0) {
localTrans = pmml.getSupportVectorMachineModelArray(0).getLocalTransformations();
} else if (pmml.getTextModelArray().length > 0) {
localTrans = pmml.getTextModelArray(0).getLocalTransformations();
} else if (pmml.getTimeSeriesModelArray().length > 0) {
localTrans = pmml.getTimeSeriesModelArray(0).getLocalTransformations();
} else if (pmml.getTreeModelArray().length > 0) {
localTrans = pmml.getTreeModelArray(0).getLocalTransformations();
} else if (pmml.sizeOfRuleSetModelArray() > 0) {
localTrans = pmml.getRuleSetModelArray(0).getLocalTransformations();
}
if (localTrans != null) {
derivedFields.addAll(Arrays.asList(localTrans.getDerivedFieldArray()));
}
return derivedFields.toArray(new DerivedField[0]);
}
use of org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary in project knime-core by knime.
the class PMMLBinningTranslator method exportToTransDict.
@Override
public TransformationDictionary exportToTransDict() {
final TransformationDictionary dictionary = TransformationDictionary.Factory.newInstance();
dictionary.setDerivedFieldArray(createDerivedFields());
return dictionary;
}
use of org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary in project knime-core by knime.
the class PMMLPortObject method moveDerivedFields.
/**
* Moves the content of the transformation dictionary to local
* transformations.
* @param type the type of model to move the derived fields to
* @return the {@link LocalTransformations} element containing the moved
* derived fields or an empty local transformation object if nothing
* has to be moved
*/
private LocalTransformations moveDerivedFields(final SchemaType type) {
PMML pmml = m_pmmlDoc.getPMML();
TransformationDictionary transDict = pmml.getTransformationDictionary();
LocalTransformations localTrans = LocalTransformations.Factory.newInstance();
if (transDict == null) {
// nothing to be moved
return localTrans;
}
localTrans.setDerivedFieldArray(transDict.getDerivedFieldArray());
localTrans.setExtensionArray(transDict.getExtensionArray());
/*
* Unfortunately the PMML models have no common base class. Therefore a
* cast to the specific type is necessary for being able to add the
* mining schema.
*/
boolean known = true;
if (AssociationModel.type.equals(type)) {
AssociationModel model = pmml.getAssociationModelArray(0);
model.setLocalTransformations(localTrans);
} else if (ClusteringModel.type.equals(type)) {
ClusteringModel model = pmml.getClusteringModelArray(0);
model.setLocalTransformations(localTrans);
} else if (GeneralRegressionModel.type.equals(type)) {
GeneralRegressionModel model = pmml.getGeneralRegressionModelArray(0);
model.setLocalTransformations(localTrans);
} else if (MiningModel.type.equals(type)) {
MiningModel model = pmml.getMiningModelArray(0);
model.setLocalTransformations(localTrans);
} else if (NaiveBayesModel.type.equals(type)) {
NaiveBayesModel model = pmml.getNaiveBayesModelArray(0);
model.setLocalTransformations(localTrans);
} else if (NeuralNetwork.type.equals(type)) {
NeuralNetwork model = pmml.getNeuralNetworkArray(0);
model.setLocalTransformations(localTrans);
} else if (RegressionModel.type.equals(type)) {
RegressionModel model = pmml.getRegressionModelArray(0);
model.setLocalTransformations(localTrans);
} else if (RuleSetModel.type.equals(type)) {
RuleSetModel model = pmml.getRuleSetModelArray(0);
model.setLocalTransformations(localTrans);
} else if (SequenceModel.type.equals(type)) {
SequenceModel model = pmml.getSequenceModelArray(0);
model.setLocalTransformations(localTrans);
} else if (SupportVectorMachineModel.type.equals(type)) {
SupportVectorMachineModel model = pmml.getSupportVectorMachineModelArray(0);
model.setLocalTransformations(localTrans);
} else if (TextModel.type.equals(type)) {
TextModel model = pmml.getTextModelArray(0);
model.setLocalTransformations(localTrans);
} else if (TimeSeriesModel.type.equals(type)) {
TimeSeriesModel model = pmml.getTimeSeriesModelArray(0);
model.setLocalTransformations(localTrans);
} else if (TreeModel.type.equals(type)) {
TreeModel model = pmml.getTreeModelArray(0);
model.setLocalTransformations(localTrans);
} else {
if (type != null) {
LOGGER.error("Could not move TransformationDictionary to " + "unsupported model of type \"" + type + "\".");
}
known = false;
}
if (known) {
// remove derived fields from TransformationDictionary
transDict.setDerivedFieldArray(new DerivedField[0]);
transDict.setExtensionArray(new ExtensionDocument.Extension[0]);
}
return localTrans;
}
Aggregations