use of org.kie.pmml.pmml_4_2.model.Miningmodel 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.model.Miningmodel in project drools by kiegroup.
the class PMML4Compiler method precompile.
public List<PMMLResource> precompile(InputStream stream, ClassLoader classLoader, KieBaseModel rootKieBaseModel) {
List<PMMLResource> resources = new ArrayList<>();
KieServices services = KieServices.Factory.get();
KieModuleModel module = services.newKieModuleModel();
this.results = new ArrayList<KnowledgeBuilderResult>();
PMML pmml = loadModel(PMML, stream);
helper.setResolver(classLoader);
PMML4Unit unit = new PMML4UnitImpl(pmml);
if (unit.containsMiningModel()) {
Miningmodel rootModel = unit.getRootMiningModel();
resources = buildResourcesFromModel(pmml, rootModel, null, classLoader, module);
} else {
PMML4Model rootModel = unit.getRootModel();
if (rootModel != null) {
helper.setPack(rootModel.getModelPackageName());
KieBaseModel kbm = module.newKieBaseModel(rootModel.getModelId());
kbm.addPackage(helper.getPack()).setDefault(true).setEventProcessingMode(EventProcessingOption.CLOUD);
PMMLResource resource = new PMMLResource(helper.getPack());
resource.setKieBaseModel(kbm);
resource.addRules(rootModel.getModelId(), this.compile(pmml, classLoader));
resources.add(resource);
}
}
return resources;
}
use of org.kie.pmml.pmml_4_2.model.Miningmodel in project drools by kiegroup.
the class AbstractModel method getMiningFields.
@Override
public List<PMMLMiningField> getMiningFields() {
List<PMMLMiningField> fields = new ArrayList<>();
Map<String, MiningField> excludesTargetMap = getFilteredMiningFieldMap(false, FIELDUSAGETYPE.TARGET);
Map<String, PMMLDataField> dataDictionary = getOwner().getDataDictionaryMap();
for (String key : excludesTargetMap.keySet()) {
PMMLDataField df = dataDictionary.get(key);
MiningField mf = miningFieldMap.get(key);
if (df != null) {
fields.add(new PMMLMiningField(mf, df.getRawDataField(), this.getModelId(), true));
} else {
PMMLMiningField fld = new PMMLMiningField(mf, this.getModelId());
if (this.getParentModel() != null) {
PMML4Model ultimateParentModel = this.getParentModel();
if (ultimateParentModel instanceof Miningmodel) {
while (ultimateParentModel.getParentModel() != null) {
ultimateParentModel = ultimateParentModel.getParentModel();
}
PMMLOutputField ofld = ((Miningmodel) ultimateParentModel).findOutputField(fld.getName());
if (ofld != null) {
fld.setType(ofld.getType());
fields.add(fld);
}
}
}
}
}
return fields;
}
use of org.kie.pmml.pmml_4_2.model.Miningmodel in project drools by kiegroup.
the class Miningmodel method getChildOutputField.
private PMMLOutputField getChildOutputField(PMML4Model parentModel, String fieldName) {
PMMLOutputField output = null;
for (Iterator<PMML4Model> childIter = parentModel.getChildModels().values().iterator(); childIter.hasNext() && output == null; ) {
PMML4Model child = childIter.next();
List<PMMLOutputField> fields = child.getOutputFields();
if (fields != null && !fields.isEmpty()) {
for (Iterator<PMMLOutputField> fieldIter = fields.iterator(); fieldIter.hasNext() && output == null; ) {
PMMLOutputField fld = fieldIter.next();
if (fieldName.equals(fld.getName())) {
output = fld;
}
}
}
if (child instanceof Miningmodel && output == null) {
output = getChildOutputField(child, fieldName);
}
}
return output;
}
use of org.kie.pmml.pmml_4_2.model.Miningmodel in project drools by kiegroup.
the class PMML4ModelFactory method getModel.
public PMML4Model getModel(Segment segment, MiningSegmentation segmentation) {
PMML4Model model = null;
if (segment.getMiningModel() != null) {
MiningModel mm = segment.getMiningModel();
model = new Miningmodel(mm.getModelName(), mm, segmentation.getOwner(), null);
} else if (segment.getRegressionModel() != null) {
RegressionModel rm = segment.getRegressionModel();
model = new Regression(rm.getModelName(), rm, segmentation.getOwner(), null);
} else if (segment.getScorecard() != null) {
Scorecard sc = segment.getScorecard();
model = new ScorecardModel(sc.getModelName(), sc, segmentation.getOwner(), null);
} else if (segment.getTreeModel() != null) {
TreeModel tm = segment.getTreeModel();
model = new Treemodel(tm.getModelName(), tm, segmentation.getOwner(), null);
}
return model;
}
Aggregations