use of org.kie.pmml.pmml_4_2.model.PMMLMiningField 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;
}
}
}
});
}
use of org.kie.pmml.pmml_4_2.model.PMMLMiningField 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;
}
Aggregations