use of org.kie.pmml.pmml_4_2.model.PMMLOutputField in project drools by kiegroup.
the class MiningSegmentation method getSegmentTransfer.
public MiningSegmentTransfer getSegmentTransfer(MiningSegment targetSegment, String targetFieldName) {
MiningSegmentTransfer xfer = null;
int lastIndex = targetSegment.getSegmentIndex() - 1;
if (lastIndex < 0) {
throw new IndexOutOfBoundsException("Cannot have an undefined mining field in the first segment");
}
for (int idx = lastIndex; idx >= 0; idx--) {
MiningSegment seg = miningSegments.get(idx);
if (seg != null && seg.getInternalModel() != null) {
List<PMMLOutputField> outputs = seg.getInternalModel().getOutputFields();
if (outputs != null) {
for (PMMLOutputField field : outputs) {
if (field.getName().equals(targetFieldName)) {
xfer = new MiningSegmentTransfer(this.segmentationId, seg.getSegmentId(), targetSegment.getSegmentId());
xfer.addResultToRequestMapping(targetFieldName, targetFieldName);
return xfer;
}
}
}
}
}
return xfer;
}
use of org.kie.pmml.pmml_4_2.model.PMMLOutputField 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.PMMLOutputField 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;
}
use of org.kie.pmml.pmml_4_2.model.PMMLOutputField 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;
}
Aggregations