Search in sources :

Example 1 with DataDictionary

use of org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary in project drools by kiegroup.

the class AbstractModel method getOutputFields.

@Override
public List<PMMLOutputField> getOutputFields() {
    List<PMMLOutputField> fields = new ArrayList<>();
    for (String key : outputFieldMap.keySet()) {
        OutputField of = outputFieldMap.get(key);
        fields.add(new PMMLOutputField(of, null, this.getModelId()));
    }
    Map<String, MiningField> includeFromMining = getFilteredMiningFieldMap(true, FIELDUSAGETYPE.PREDICTED, FIELDUSAGETYPE.TARGET);
    Map<String, PMMLDataField> dataDictionary = getOwner().getDataDictionaryMap();
    if (includeFromMining != null && !includeFromMining.isEmpty()) {
        for (String key : includeFromMining.keySet()) {
            MiningField field = includeFromMining.get(key);
            PMMLDataField df = dataDictionary.get(key);
            fields.add(new PMMLOutputField(field, df.getRawDataField(), this.getModelId()));
        }
    }
    return fields;
}
Also used : MiningField(org.kie.dmg.pmml.pmml_4_2.descr.MiningField) ArrayList(java.util.ArrayList) OutputField(org.kie.dmg.pmml.pmml_4_2.descr.OutputField)

Example 2 with DataDictionary

use of org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary in project drools by kiegroup.

the class PMML4UnitImpl method initDataDictionaryMap.

/**
 * Initializes the internal structure that holds data dictionary information.
 * This initializer should be called prior to any other initializers, since
 * many other structures may have a dependency on the data dictionary.
 */
private void initDataDictionaryMap() {
    DataDictionary dd = rawPmml.getDataDictionary();
    if (dd != null) {
        dataDictionaryMap = new HashMap<>();
        for (DataField dataField : dd.getDataFields()) {
            PMMLDataField df = new PMMLDataField(dataField);
            dataDictionaryMap.put(df.getName(), df);
        }
    } else {
        throw new IllegalStateException("BRMS-PMML requires a data dictionary section in the definition file");
    }
}
Also used : DataField(org.kie.dmg.pmml.pmml_4_2.descr.DataField) DataDictionary(org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary)

Example 3 with DataDictionary

use of org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary in project drools by kiegroup.

the class PMML4Compiler method buildResourceFromSegment.

protected PMMLResource buildResourceFromSegment(PMML pmml_origin, MiningSegment segment, ClassLoader classLoader, KieModuleModel module) {
    PMML pmml = new PMML();
    DataDictionary dd = pmml_origin.getDataDictionary();
    pmml.setDataDictionary(dd);
    pmml.setHeader(pmml_origin.getHeader());
    pmml.getAssociationModelsAndBaselineModelsAndClusteringModels().add(segment.getModel().getRawModel());
    addMissingFieldDefinition(pmml, segment.getOwner(), segment);
    // PMML4Helper.pmmlDefaultPackageName()+".mining.segment_"+segment.getSegmentId());
    helper.setPack(segment.getModel().getModelPackageName());
    String rules = this.compile(pmml, classLoader);
    KieBaseModel kbModel = module.newKieBaseModel(segment.getOwner().getOwner().getModelId() + "_" + segment.getOwner().getSegmentationId() + "_SEGMENT_" + segment.getSegmentId());
    kbModel.addPackage(helper.getPack()).setDefault(false).setEventProcessingMode(EventProcessingOption.CLOUD);
    KieSessionModel ksm = kbModel.newKieSessionModel("SEGMENT_" + segment.getSegmentId());
    ksm.setDefault(true);
    PMMLResource resource = new PMMLResource(helper.getPack());
    resource.setKieBaseModel(kbModel);
    resource.addRules(segment.getModel().getModelId(), rules);
    return resource;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) PMMLResource(org.drools.compiler.compiler.PMMLResource) PMML(org.kie.dmg.pmml.pmml_4_2.descr.PMML) DataDictionary(org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary) KieSessionModel(org.kie.api.builder.model.KieSessionModel)

Example 4 with DataDictionary

use of org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary 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 5 with DataDictionary

use of org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary in project drools by kiegroup.

the class Miningmodel method initChildModels.

protected void initChildModels() {
    childModels = new HashMap<>();
    Iterator<Serializable> extenIter = rawModel.getExtensionsAndMiningSchemasAndOutputs().iterator();
    segmentation = null;
    while (extenIter.hasNext() && segmentation == null) {
        Object obj = extenIter.next();
        if (obj instanceof Segmentation) {
            segmentation = new MiningSegmentation(this, (Segmentation) obj);
        }
    }
    if (segmentation != null) {
        List<MiningSegment> segments = segmentation.getMiningSegments();
        DataDictionary dd = this.getDataDictionary();
        for (MiningSegment seg : segmentation.getMiningSegments()) {
            childModels.put(seg.getModel().getModelId(), seg.getModel());
        }
    }
}
Also used : MiningSegmentation(org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation) Serializable(java.io.Serializable) MiningSegmentation(org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation) Segmentation(org.kie.dmg.pmml.pmml_4_2.descr.Segmentation) MiningSegment(org.kie.pmml.pmml_4_2.model.mining.MiningSegment) DataDictionary(org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary)

Aggregations

DataDictionary (org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary)3 ArrayList (java.util.ArrayList)2 MiningField (org.kie.dmg.pmml.pmml_4_2.descr.MiningField)2 Serializable (java.io.Serializable)1 PMMLResource (org.drools.compiler.compiler.PMMLResource)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1 KieSessionModel (org.kie.api.builder.model.KieSessionModel)1 DataField (org.kie.dmg.pmml.pmml_4_2.descr.DataField)1 OutputField (org.kie.dmg.pmml.pmml_4_2.descr.OutputField)1 PMML (org.kie.dmg.pmml.pmml_4_2.descr.PMML)1 Segmentation (org.kie.dmg.pmml.pmml_4_2.descr.Segmentation)1 PMML4Model (org.kie.pmml.pmml_4_2.PMML4Model)1 MiningSegment (org.kie.pmml.pmml_4_2.model.mining.MiningSegment)1 MiningSegmentation (org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation)1