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"); } }
@Test(expected=IllegalStateException.class) public void testBadOperator() { predicate.setOperator(BAD_OP); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNull(text); }
@Test public void testStringValue() { stringPred.setOperator(SimpleSegmentPredicate.EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(stringPred); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF3 == false ) && ( vTF3 == \"optA\" )",text); predicate.setOperator(SimpleSegmentPredicate.EQUAL); ssp = new SimpleSegmentPredicate(predicate); text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 == 123 )",text); }
@Test public void testEquals() { predicate.setOperator(SimpleSegmentPredicate.EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 == 123 )",text); }
@Test public void testLessThan() { predicate.setOperator(SimpleSegmentPredicate.LESSER); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 < 123 )",text); }
@Test public void testMissing() { predicate.setOperator(SimpleSegmentPredicate.MISSING); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("mTF2 == true",text); }
@Test public void testNotMissing() { predicate.setOperator(SimpleSegmentPredicate.NOT_MISSING); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("mTF2 == false",text); }
@Test public void testNotEquals() { predicate.setOperator(SimpleSegmentPredicate.NOT_EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 != 123 )",text); }
@Test public void testGreaterThan() { predicate.setOperator(SimpleSegmentPredicate.GREATER); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 > 123 )",text); }
@Test public void testGreaterEqual() { predicate.setOperator(SimpleSegmentPredicate.GREATER_EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 >= 123 )",text); }
@Test public void testLesserEqual() { predicate.setOperator(SimpleSegmentPredicate.LESSER_EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 <= 123 )",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()); } }