Search in sources :

Example 1 with DataField

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

use of org.kie.dmg.pmml.pmml_4_2.descr.DataField 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;
                }
            }
        }
    });
}
Also used : ResourceFactory(org.kie.internal.io.ResourceFactory) SupportVectorMachineModel(org.kie.dmg.pmml.pmml_4_2.descr.SupportVectorMachineModel) Miningmodel(org.kie.pmml.pmml_4_2.model.Miningmodel) TemplateRegistry(org.mvel2.templates.TemplateRegistry) Map(java.util.Map) BigInteger(java.math.BigInteger) Scorecard(org.kie.dmg.pmml.pmml_4_2.descr.Scorecard) KieSession(org.kie.api.runtime.KieSession) TemplateCompiler(org.mvel2.templates.TemplateCompiler) EventProcessingOption(org.kie.api.conf.EventProcessingOption) PMML4UnitImpl(org.kie.pmml.pmml_4_2.model.PMML4UnitImpl) PMMLMiningField(org.kie.pmml.pmml_4_2.model.PMMLMiningField) TreeModel(org.kie.dmg.pmml.pmml_4_2.descr.TreeModel) KnowledgeBuilderResult(org.kie.internal.builder.KnowledgeBuilderResult) KieBaseModel(org.kie.api.builder.model.KieBaseModel) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Resource(org.kie.api.io.Resource) List(java.util.List) PMMLCompiler(org.drools.compiler.compiler.PMMLCompiler) KieSessionModel(org.kie.api.builder.model.KieSessionModel) SAXException(org.xml.sax.SAXException) Writer(java.io.Writer) NaiveBayesModel(org.kie.dmg.pmml.pmml_4_2.descr.NaiveBayesModel) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) ResourceType(org.kie.api.io.ResourceType) Schema(javax.xml.validation.Schema) ArrayList(java.util.ArrayList) MiningSegmentation(org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation) RegressionModel(org.kie.dmg.pmml.pmml_4_2.descr.RegressionModel) ClusteringModel(org.kie.dmg.pmml.pmml_4_2.descr.ClusteringModel) IoUtils(org.drools.core.util.IoUtils) PMMLResource(org.drools.compiler.compiler.PMMLResource) KieServices(org.kie.api.KieServices) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayResource(org.drools.core.io.impl.ByteArrayResource) XMLConstants(javax.xml.XMLConstants) KieBase(org.kie.api.KieBase) SimpleTemplateRegistry(org.mvel2.templates.SimpleTemplateRegistry) JAXBContext(javax.xml.bind.JAXBContext) MiningSegment(org.kie.pmml.pmml_4_2.model.mining.MiningSegment) OutputStream(java.io.OutputStream) Unmarshaller(javax.xml.bind.Unmarshaller) SchemaFactory(javax.xml.validation.SchemaFactory) Iterator(java.util.Iterator) DataField(org.kie.dmg.pmml.pmml_4_2.descr.DataField) KieContainer(org.kie.api.runtime.KieContainer) IOException(java.io.IOException) DataDictionary(org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary) File(java.io.File) PMMLOutputField(org.kie.pmml.pmml_4_2.model.PMMLOutputField) ClassPathResource(org.drools.core.io.impl.ClassPathResource) KieModuleModel(org.kie.api.builder.model.KieModuleModel) PMML(org.kie.dmg.pmml.pmml_4_2.descr.PMML) Collections(java.util.Collections) InputStream(java.io.InputStream) NeuralNetwork(org.kie.dmg.pmml.pmml_4_2.descr.NeuralNetwork) PMMLOutputField(org.kie.pmml.pmml_4_2.model.PMMLOutputField) DataField(org.kie.dmg.pmml.pmml_4_2.descr.DataField) BigInteger(java.math.BigInteger) PMMLMiningField(org.kie.pmml.pmml_4_2.model.PMMLMiningField)

Aggregations

DataDictionary (org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary)2 DataField (org.kie.dmg.pmml.pmml_4_2.descr.DataField)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Writer (java.io.Writer)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 XMLConstants (javax.xml.XMLConstants)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1