Search in sources :

Example 6 with PMML4Model

use of org.kie.pmml.pmml_4_2.PMML4Model 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;
}
Also used : ArrayList(java.util.ArrayList) Miningmodel(org.kie.pmml.pmml_4_2.model.Miningmodel) KieServices(org.kie.api.KieServices) PMMLResource(org.drools.compiler.compiler.PMMLResource) KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) PMML(org.kie.dmg.pmml.pmml_4_2.descr.PMML) PMML4UnitImpl(org.kie.pmml.pmml_4_2.model.PMML4UnitImpl) KnowledgeBuilderResult(org.kie.internal.builder.KnowledgeBuilderResult)

Example 7 with PMML4Model

use of org.kie.pmml.pmml_4_2.PMML4Model 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;
}
Also used : MiningField(org.kie.dmg.pmml.pmml_4_2.descr.MiningField) ArrayList(java.util.ArrayList) PMML4Model(org.kie.pmml.pmml_4_2.PMML4Model)

Example 8 with PMML4Model

use of org.kie.pmml.pmml_4_2.PMML4Model 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;
}
Also used : PMML4Model(org.kie.pmml.pmml_4_2.PMML4Model)

Example 9 with PMML4Model

use of org.kie.pmml.pmml_4_2.PMML4Model 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;
}
Also used : TreeModel(org.kie.dmg.pmml.pmml_4_2.descr.TreeModel) MiningModel(org.kie.dmg.pmml.pmml_4_2.descr.MiningModel) PMML4Model(org.kie.pmml.pmml_4_2.PMML4Model) Scorecard(org.kie.dmg.pmml.pmml_4_2.descr.Scorecard) RegressionModel(org.kie.dmg.pmml.pmml_4_2.descr.RegressionModel)

Example 10 with PMML4Model

use of org.kie.pmml.pmml_4_2.PMML4Model in project drools by kiegroup.

the class PMML4UnitImpl method getModelPackageNames.

public Map<String, String> getModelPackageNames() {
    Map<String, String> packageNames = new HashMap<>();
    packageNames.put("root", getRootPackage());
    for (PMML4Model model : this.getModels()) {
        packageNames.put(model.getModelId(), model.getModelPackageName());
    }
    return packageNames;
}
Also used : HashMap(java.util.HashMap) PMML4Model(org.kie.pmml.pmml_4_2.PMML4Model)

Aggregations

PMML4Model (org.kie.pmml.pmml_4_2.PMML4Model)10 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 PMML (org.kie.dmg.pmml.pmml_4_2.descr.PMML)3 RegressionModel (org.kie.dmg.pmml.pmml_4_2.descr.RegressionModel)3 Scorecard (org.kie.dmg.pmml.pmml_4_2.descr.Scorecard)3 TreeModel (org.kie.dmg.pmml.pmml_4_2.descr.TreeModel)3 PMML4UnitImpl (org.kie.pmml.pmml_4_2.model.PMML4UnitImpl)3 List (java.util.List)2 Map (java.util.Map)2 PMMLResource (org.drools.compiler.compiler.PMMLResource)2 KieServices (org.kie.api.KieServices)2 KieBaseModel (org.kie.api.builder.model.KieBaseModel)2 KieModuleModel (org.kie.api.builder.model.KieModuleModel)2 MiningField (org.kie.dmg.pmml.pmml_4_2.descr.MiningField)2 KnowledgeBuilderResult (org.kie.internal.builder.KnowledgeBuilderResult)2 Miningmodel (org.kie.pmml.pmml_4_2.model.Miningmodel)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1