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"); } }
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"); } }
private void doPredicateRetrieve(String expected) { SimpleSetSegmentPredicate sssp = new SimpleSetSegmentPredicate(predicate); String text = sssp.getPredicateRule(); assertNotNull(text); assertEquals(expected,text); }
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 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()); } }