public String getValueFieldName() { return "v".concat(getCapitalizedFieldName()); }
private List<Object> getValueObjects() { List<Object> objects = new ArrayList<>(); Matcher matcher = getMatcher(); if (matcher != null) { if ("int".equalsIgnoreCase(this.setType)) { while(matcher.find()) { Integer value = Integer.valueOf(matcher.group(0)); objects.add(value); } } else if ("real".equals(this.setType)) { while (matcher.find()) { String valueStr = matcher.group(0); Double value = Double.valueOf(valueStr); objects.add(value); } } else { while (matcher.find()) { objects.add(matcher.group(0)); } } } return objects; }
@Override public String getPredicateRule() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); CompiledTemplate ct = getTemplate(); if (ct != null) { Map<String,Object>vars = new HashMap<>(); vars.put("missingFieldName", this.getMissingFieldName()); vars.put("fieldName", this.getValueFieldName()); vars.put("operator", getOperatorText()); vars.put("setType", setType); vars.put("values", getValueObjects()); TemplateRuntime.execute(ct,null,new MapVariableResolverFactory(vars),baos); } return new String(baos.toByteArray()); }
private void doPredicateRetrieve(String expected) { SimpleSetSegmentPredicate sssp = new SimpleSetSegmentPredicate(predicate); String text = sssp.getPredicateRule(); assertNotNull(text); assertEquals(expected,text); }
public static PredicateRuleProducer getPredicateProducer(Serializable serializable) { if (serializable instanceof SimplePredicate) return new SimpleSegmentPredicate((SimplePredicate)serializable); if (serializable instanceof SimpleSetPredicate) return new SimpleSetSegmentPredicate((SimpleSetPredicate)serializable); if (serializable instanceof CompoundPredicate) return new CompoundSegmentPredicate((CompoundPredicate)serializable); if (serializable instanceof True) return new BooleanSegmentPredicate((True)serializable); if (serializable instanceof False) return new BooleanSegmentPredicate((False)serializable); throw new IllegalArgumentException("Serializable object [" + serializable.getClass().getName() + "] is not one of the known predicate types"); } }
@Override public List<String> getFieldMissingFieldNames() { List<String> fieldNames = new ArrayList<>(); fieldNames.add(getMissingFieldName()); return fieldNames; }
public SimpleSetSegmentPredicate(SimpleSetPredicate predicate) { this.setType = predicate.getArray().getType(); this.operator = predicate.getBooleanOperator(); this.baseFieldName = predicate.getField(); this.setValuesString = predicate.getArray().getContent(); this.valueCount = predicate.getArray().getN(); this.valuesList = getValueObjects(); if (this.valueCount != null && this.valueCount.intValue() != this.valuesList.size()) { throw new IllegalStateException("PMML-SimpleSetPredicate: Number of values found (" +valuesList.size()+") does not equal number of values declared (" +this.valueCount+")"); } if (this.operator == null || (!this.operator.equals("isIn") && !this.operator.equals("isNotIn"))) { throw new IllegalStateException("PMML-SimpleSetPredicate: booleanOperator was not one of the allowed values (\"isIn\" or \"isNotIn\")"); } }
public String getPredicate(Attribute attrib) { String predicateText = null; if (attrib.getSimplePredicate() != null) { SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(attrib.getSimplePredicate()); predicateText = ssp.getPredicateRule(); return "( "+predicateText+" )"; } else if (attrib.getSimpleSetPredicate() != null) { SimpleSetSegmentPredicate sssp = new SimpleSetSegmentPredicate(attrib.getSimpleSetPredicate()); return sssp.getPredicateRule(); } else if (attrib.getCompoundPredicate() != null) { CompoundSegmentPredicate csp = new CompoundSegmentPredicate(attrib.getCompoundPredicate()); if (csp.hasSurrogation()) { return getSurrogationPredicateText(csp,-1); } else { return csp.getPredicateRule(); } } else if (attrib.getTrue() != null) { return "( 1 == 1 )"; } else if (attrib.getFalse() != null) { return "( 1 == 0 )"; } throw new IllegalStateException("Unable to determine predicate for Attribute with reason code: "+attrib.getReasonCode()); }
public CompoundSegmentPredicate(CompoundPredicate predicate) { subpredicates = new ArrayList<>(); for (Serializable serializable : predicate.getSimplePredicatesAndCompoundPredicatesAndSimpleSetPredicates()) { if (serializable instanceof SimplePredicate) { subpredicates.add(new SimpleSegmentPredicate((SimplePredicate)serializable)); } else if (serializable instanceof SimpleSetPredicate) { subpredicates.add(new SimpleSetSegmentPredicate((SimpleSetPredicate)serializable)); } else if (serializable instanceof CompoundPredicate) { subpredicates.add(new CompoundSegmentPredicate((CompoundPredicate)serializable)); } } booleanOperator = predicate.getBooleanOperator(); if (booleanOperator == null) { throw new IllegalStateException("PMML-CompoundPredicate: Missing the booleanOperator attribute"); } if (!booleanOperator.equalsIgnoreCase("and") && !booleanOperator.equalsIgnoreCase("or") && !booleanOperator.equalsIgnoreCase("xor") && !booleanOperator.equalsIgnoreCase("surrogate")) { throw new IllegalStateException("PMML-CompoundPredicate: Invalid value ("+booleanOperator+") for the booleanOperator attribute"); } }
public MiningSegment( MiningSegmentation owner, Segment segment, int segmentIndex) { this.owner = owner; this.internalModel = PMML4ModelFactory.getInstance().getModel(segment,owner); this.segmentId = segment.getId(); this.segmentIndex = segmentIndex; this.weight = segment.getWeight(); if (segment.getSimplePredicate() != null) { predicateRuleProducer = new SimpleSegmentPredicate(segment.getSimplePredicate()); } else if (segment.getSimpleSetPredicate() != null) { predicateRuleProducer = new SimpleSetSegmentPredicate(segment.getSimpleSetPredicate()); } else if (segment.getCompoundPredicate() != null) { predicateRuleProducer = new CompoundSegmentPredicate(segment.getCompoundPredicate()); } else if (segment.getTrue() != null) { predicateRuleProducer = new BooleanSegmentPredicate(segment.getTrue()); } else if (segment.getFalse() != null) { predicateRuleProducer = new BooleanSegmentPredicate(segment.getFalse()); } }
public String getMissingFieldName() { return "m".concat(getCapitalizedFieldName()); }