public static String extractFieldNameFromCharacteristic(Characteristic c) { String field = ""; Attribute scoreAttribute = c.getAttributes().get(0); if (scoreAttribute.getSimplePredicate() != null) { field = scoreAttribute.getSimplePredicate().getField(); } else if (scoreAttribute.getSimpleSetPredicate() != null) { field = scoreAttribute.getSimpleSetPredicate().getField(); } else if (scoreAttribute.getCompoundPredicate() != null) { Object predicate = scoreAttribute.getCompoundPredicate().getSimplePredicatesAndCompoundPredicatesAndSimpleSetPredicates().get(0); if (predicate instanceof SimplePredicate){ field = ((SimplePredicate)predicate).getField(); } else if (predicate instanceof SimpleSetPredicate){ field = ((SimpleSetPredicate)predicate).getField(); } } return field; }
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()); }