use of org.kie.pmml.pmml_4_2.PMML4Model in project drools by kiegroup.
the class PMML4ModelFactory method getModels.
public List<PMML4Model> getModels(PMML4Unit owner) {
List<PMML4Model> pmml4Models = new ArrayList<>();
owner.getRawPMML().getAssociationModelsAndBaselineModelsAndClusteringModels().forEach(serializable -> {
if (serializable instanceof Scorecard) {
Scorecard sc = (Scorecard) serializable;
ScorecardModel model = new ScorecardModel(sc.getModelName(), sc, null, owner);
pmml4Models.add(model);
} else if (serializable instanceof RegressionModel) {
RegressionModel rm = (RegressionModel) serializable;
Regression model = new Regression(rm.getModelName(), rm, null, owner);
pmml4Models.add(model);
} else if (serializable instanceof TreeModel) {
TreeModel tm = (TreeModel) serializable;
Treemodel model = new Treemodel(tm.getModelName(), tm, null, owner);
pmml4Models.add(model);
} else if (serializable instanceof MiningModel) {
MiningModel mm = (MiningModel) serializable;
Miningmodel model = new Miningmodel(mm.getModelName(), mm, null, owner);
pmml4Models.add(model);
}
});
return pmml4Models;
}
use of org.kie.pmml.pmml_4_2.PMML4Model in project drools by kiegroup.
the class PMML4UnitImpl method getModels.
@Override
public Map<String, PMML4Model> getModels(PMML4ModelType type, PMML4Model parent) {
Map<String, PMML4Model> filteredModels = new HashMap<>();
Map<String, PMML4Model> unfilteredModels = parent == null ? getRootModels() : getChildModels(parent.getModelId());
if (unfilteredModels != null && !unfilteredModels.isEmpty()) {
for (PMML4Model model : unfilteredModels.values()) {
if (model.getModelType() == type) {
filteredModels.put(model.getModelId(), model);
}
}
}
return filteredModels;
}
use of org.kie.pmml.pmml_4_2.PMML4Model in project drools by kiegroup.
the class PMML4UnitImpl method addChildModelsToMap.
/**
* Recursive method that adds children models (i.e. models contained within models)
* to the internal map of models
*
* @param parentModel The model which may contain child models
*/
private void addChildModelsToMap(PMML4Model parentModel) {
Map<String, PMML4Model> childModels = parentModel.getChildModels();
if (childModels != null && !childModels.isEmpty()) {
for (PMML4Model model : childModels.values()) {
modelsMap.put(model.getModelId(), model);
addChildModelsToMap(model);
}
}
}
use of org.kie.pmml.pmml_4_2.PMML4Model in project drools by kiegroup.
the class PMML4Compiler method addMissingFieldDefinition.
private void addMissingFieldDefinition(PMML pmml, MiningSegmentation msm, MiningSegment seg) {
// get the list of models that may contain the field definition
List<PMML4Model> models = msm.getMiningSegments().stream().filter(s -> s != seg && s.getSegmentIndex() < seg.getSegmentIndex()).map(iseg -> {
return iseg.getModel();
}).collect(Collectors.toList());
seg.getModel().getMiningFields().stream().filter(mf -> !mf.isInDictionary()).forEach(pmf -> {
String fldName = pmf.getName();
boolean fieldAdded = false;
for (Iterator<PMML4Model> iter = models.iterator(); iter.hasNext() && !fieldAdded; ) {
PMML4Model mdl = iter.next();
PMMLOutputField outfield = mdl.findOutputField(fldName);
PMMLMiningField target = (outfield != null && outfield.getTargetField() != null) ? mdl.findMiningField(outfield.getTargetField()) : null;
if (outfield != null) {
DataField e = null;
if (outfield.getRawDataField() != null && outfield.getRawDataField().getDataType() != null) {
e = outfield.getRawDataField();
} else if (target != null) {
e = target.getRawDataField();
}
if (e != null) {
e.setName(fldName);
pmml.getDataDictionary().getDataFields().add(e);
BigInteger bi = pmml.getDataDictionary().getNumberOfFields();
pmml.getDataDictionary().setNumberOfFields(bi.add(BigInteger.ONE));
fieldAdded = true;
}
}
}
});
}
use of org.kie.pmml.pmml_4_2.PMML4Model in project drools by kiegroup.
the class PMML4Compiler method getJavaClasses.
@Override
public Map<String, String> getJavaClasses(InputStream stream) {
Map<String, String> javaClasses = new HashMap<>();
PMML pmml = loadModel(PMML, stream);
if (pmml != null) {
PMML4Unit unit = new PMML4UnitImpl(pmml);
if (unit != null) {
List<PMML4Model> models = unit.getModels();
models.forEach(model -> {
Map.Entry<String, String> inputPojo = model.getMappedMiningPojo();
Map.Entry<String, String> ruleUnit = model.getMappedRuleUnit();
if (inputPojo != null)
javaClasses.put(inputPojo.getKey(), inputPojo.getValue());
if (ruleUnit != null)
javaClasses.put(ruleUnit.getKey(), ruleUnit.getValue());
});
}
}
return javaClasses;
}
Aggregations