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