Search in sources :

Example 1 with PMML4UnitImpl

use of org.kie.pmml.pmml_4_2.model.PMML4UnitImpl 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;
}
Also used : HashMap(java.util.HashMap) PMML(org.kie.dmg.pmml.pmml_4_2.descr.PMML) Map(java.util.Map) HashMap(java.util.HashMap) PMML4UnitImpl(org.kie.pmml.pmml_4_2.model.PMML4UnitImpl)

Example 2 with PMML4UnitImpl

use of org.kie.pmml.pmml_4_2.model.PMML4UnitImpl 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 3 with PMML4UnitImpl

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

the class PMML4Compiler method generateTheory.

public String generateTheory(PMML pmml) {
    StringBuilder sb = new StringBuilder();
    PMML4Unit unit = new PMML4UnitImpl(pmml);
    KieBase visitor;
    try {
        visitor = checkBuildingResources(pmml);
    } catch (IOException e) {
        this.results.add(new PMMLError(e.getMessage()));
        return null;
    }
    KieSession visitorSession = visitor.newKieSession();
    helper.reset();
    visitorSession.setGlobal("registry", registry);
    visitorSession.setGlobal("fld2var", new HashMap());
    visitorSession.setGlobal("utils", helper);
    visitorSession.setGlobal("unitPackageName", helper.getPack());
    visitorSession.setGlobal("ruleUnitClassName", getRuleUnitClass(unit));
    visitorSession.setGlobal("theory", sb);
    visitorSession.insert(pmml);
    visitorSession.fireAllRules();
    String modelEvaluatingRules = sb.toString();
    visitorSession.dispose();
    return modelEvaluatingRules;
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) IOException(java.io.IOException) PMML4UnitImpl(org.kie.pmml.pmml_4_2.model.PMML4UnitImpl)

Aggregations

PMML4UnitImpl (org.kie.pmml.pmml_4_2.model.PMML4UnitImpl)3 HashMap (java.util.HashMap)2 PMML (org.kie.dmg.pmml.pmml_4_2.descr.PMML)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 PMMLResource (org.drools.compiler.compiler.PMMLResource)1 KieBase (org.kie.api.KieBase)1 KieServices (org.kie.api.KieServices)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1 KieModuleModel (org.kie.api.builder.model.KieModuleModel)1 KieSession (org.kie.api.runtime.KieSession)1 KnowledgeBuilderResult (org.kie.internal.builder.KnowledgeBuilderResult)1 Miningmodel (org.kie.pmml.pmml_4_2.model.Miningmodel)1