本文整理汇总了Java中org.dmg.pmml.Predicate类的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Predicate类属于org.dmg.pmml包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateNode
import org.dmg.pmml.Predicate; //导入依赖的package包/类
private Boolean evaluateNode(Trail trail, Node node, EvaluationContext context){
EmbeddedModel embeddedModel = node.getEmbeddedModel();
if(embeddedModel != null){
throw new UnsupportedElementException(embeddedModel);
}
Predicate predicate = PredicateUtil.ensurePredicate(node);
// A compound predicate whose boolean operator is "surrogate" represents a special case
if(predicate instanceof CompoundPredicate){
CompoundPredicate compoundPredicate = (CompoundPredicate)predicate;
PredicateUtil.CompoundPredicateResult result = PredicateUtil.evaluateCompoundPredicateInternal(compoundPredicate, context);
if(result.isAlternative()){
trail.addMissingLevel();
}
return result.getResult();
} else
{
return PredicateUtil.evaluate(predicate, context);
}
}
示例2: transform
import org.dmg.pmml.Predicate; //导入依赖的package包/类
private Predicate transform(SimpleSetPredicate simpleSetPredicate){
Array array = simpleSetPredicate.getArray();
List<String> content = ArrayUtil.getContent(array);
if(content.size() != 1){
return simpleSetPredicate;
}
String value = content.get(0);
SimpleSetPredicate.BooleanOperator booleanOperator = simpleSetPredicate.getBooleanOperator();
switch(booleanOperator){
case IS_IN:
return createSimplePredicate(simpleSetPredicate.getField(), SimplePredicate.Operator.EQUAL, value);
case IS_NOT_IN:
return createSimplePredicate(simpleSetPredicate.getField(), SimplePredicate.Operator.NOT_EQUAL, value);
default:
break;
}
return simpleSetPredicate;
}
示例3: intern
import org.dmg.pmml.Predicate; //导入依赖的package包/类
public Predicate intern(Predicate predicate){
if(predicate instanceof SimplePredicate){
return intern((SimplePredicate)predicate);
} else
if(predicate instanceof SimpleSetPredicate){
return intern((SimpleSetPredicate)predicate);
} else
if(predicate instanceof True){
return intern((True)predicate);
} else
if(predicate instanceof False){
return intern((False)predicate);
}
return predicate;
}
示例4: handleNodePop
import org.dmg.pmml.Predicate; //导入依赖的package包/类
private void handleNodePop(Node node){
Double recordCount = node.getRecordCount();
String score = node.getScore();
Predicate predicate = node.getPredicate();
if(recordCount != null){
node.setRecordCount(null);
} // End if
if(predicate instanceof True){
Node parentNode = getParentNode();
if(parentNode == null){
return;
}
String parentScore = parentNode.getScore();
if(parentScore != null){
throw new IllegalArgumentException();
}
parentNode.setScore(score);
List<Node> parentChildren = parentNode.getNodes();
boolean success = parentChildren.remove(node);
if(!success){
throw new IllegalArgumentException();
} // End if
if(node.hasNodes()){
List<Node> children = node.getNodes();
parentChildren.addAll(children);
}
}
}
示例5: buildPredicate
import org.dmg.pmml.Predicate; //导入依赖的package包/类
private Predicate buildPredicate(Split split,
CategoricalValueEncodings categoricalValueEncodings) {
if (split == null) {
// Left child always applies, but is evaluated second
return new True();
}
int featureIndex = inputSchema.predictorToFeatureIndex(split.feature());
FieldName fieldName = FieldName.create(inputSchema.getFeatureNames().get(featureIndex));
if (split.featureType().equals(FeatureType.Categorical())) {
// Note that categories in MLlib model select the *left* child but the
// convention here will be that the predicate selects the *right* child
// So the predicate will evaluate "not in" this set
// More ugly casting
@SuppressWarnings("unchecked")
List<Double> javaCategories = (List<Double>) (List<?>)
JavaConversions.seqAsJavaList(split.categories());
Set<Integer> negativeEncodings = javaCategories.stream().map(Double::intValue).collect(Collectors.toSet());
Map<Integer,String> encodingToValue =
categoricalValueEncodings.getEncodingValueMap(featureIndex);
List<String> negativeValues = negativeEncodings.stream().map(encodingToValue::get).collect(Collectors.toList());
String joinedValues = TextUtils.joinPMMLDelimited(negativeValues);
return new SimpleSetPredicate(fieldName,
SimpleSetPredicate.BooleanOperator.IS_NOT_IN,
new Array(Array.Type.STRING, joinedValues));
} else {
// For MLlib, left means <= threshold, so right means >
return new SimplePredicate(fieldName, SimplePredicate.Operator.GREATER_THAN)
.setValue(Double.toString(split.threshold()));
}
}
示例6: handleNodePop
import org.dmg.pmml.Predicate; //导入依赖的package包/类
private void handleNodePop(Node node){
String score = node.getScore();
Predicate predicate = node.getPredicate();
if(predicate instanceof True){
Node parentNode = getParentNode();
if(parentNode == null){
return;
}
String parentScore = parentNode.getScore();
if(parentScore != null){
throw new IllegalArgumentException();
}
parentNode.setScore(score);
List<Node> parentChildren = parentNode.getNodes();
boolean success = parentChildren.remove(node);
if(!success){
throw new IllegalArgumentException();
} // End if
if(node.hasNodes()){
List<Node> children = node.getNodes();
parentChildren.addAll(children);
}
}
}
示例7: encodePredicate
import org.dmg.pmml.Predicate; //导入依赖的package包/类
static
private Predicate encodePredicate(Feature feature, Node node, boolean left){
FieldName name = feature.getName();
SimplePredicate.Operator operator;
String value;
if(feature instanceof BinaryFeature){
BinaryFeature binaryFeature = (BinaryFeature)feature;
operator = (left ? SimplePredicate.Operator.NOT_EQUAL : SimplePredicate.Operator.EQUAL);
value = binaryFeature.getValue();
} else
{
ContinuousFeature continuousFeature = feature.toContinuousFeature();
Number splitValue = Float.intBitsToFloat(node.split_cond());
DataType dataType = continuousFeature.getDataType();
switch(dataType){
case INTEGER:
splitValue = (int)(splitValue.floatValue() + 1f);
break;
case FLOAT:
break;
default:
throw new IllegalArgumentException();
}
operator = (left ? SimplePredicate.Operator.LESS_THAN : SimplePredicate.Operator.GREATER_OR_EQUAL);
value = ValueUtil.formatValue(splitValue);
}
SimplePredicate simplePredicate = new SimplePredicate(name, operator)
.setValue(value);
return simplePredicate;
}
示例8: getFieldNamesFromNode
import org.dmg.pmml.Predicate; //导入依赖的package包/类
protected static void getFieldNamesFromNode(Set<String> fieldNames, Node startNode) {
Predicate predicate = startNode.getPredicate();
getFieldNamesFromPredicate(fieldNames, predicate);
for (Node node : startNode.getNodes()) {
getFieldNamesFromNode(fieldNames, node);
}
}
示例9: getFieldNamesFromPredicate
import org.dmg.pmml.Predicate; //导入依赖的package包/类
protected static void getFieldNamesFromPredicate(Set<String> fieldNames, Predicate predicate) {
if (predicate instanceof CompoundPredicate) {
List<Predicate> predicates = ((CompoundPredicate) predicate).getPredicates();
for (Predicate predicate1 : predicates) {
getFieldNamesFromPredicate(fieldNames, predicate1);
}
} else {
if (predicate instanceof SimplePredicate) {
fieldNames.add(((SimplePredicate) predicate).getField().getValue());
} else if (predicate instanceof SimpleSetPredicate) {
fieldNames.add(((SimpleSetPredicate) predicate).getField().getValue());
}
}
}
示例10: createSimpleSetPredicate
import org.dmg.pmml.Predicate; //导入依赖的package包/类
public Predicate createSimpleSetPredicate(Feature feature, List<String> values){
if(values.size() == 1){
String value = values.get(0);
return createSimplePredicate(feature, SimplePredicate.Operator.EQUAL, value);
}
Predicate predicate = new InternableSimpleSetPredicate()
.setField(feature.getName())
.setBooleanOperator(SimpleSetPredicate.BooleanOperator.IS_IN)
.setArray(createArray(feature.getDataType(), values));
return intern(predicate);
}
示例11: createSimplePredicate
import org.dmg.pmml.Predicate; //导入依赖的package包/类
public Predicate createSimplePredicate(Feature feature, SimplePredicate.Operator operator, String value){
Predicate predicate = new InternableSimplePredicate()
.setField(feature.getName())
.setOperator(operator)
.setValue(value);
return intern(predicate);
}
示例12: getChildren
import org.dmg.pmml.Predicate; //导入依赖的package包/类
static
private Iterator<Node> getChildren(Node node){
Predicate predicate = node.getPredicate();
if(!(predicate instanceof SimplePredicate)){
return null;
}
SimplePredicate simplePredicate = (SimplePredicate)predicate;
FieldName name = simplePredicate.getField();
SimplePredicate.Operator operator = simplePredicate.getOperator();
if(!(SimplePredicate.Operator.LESS_OR_EQUAL).equals(operator)){
return null;
} // End if
if(node.hasNodes()){
List<Node> children = node.getNodes();
int endPos = 0;
for(Node child : children){
if(!checkPredicate(child, name, operator)){
break;
}
endPos++;
}
if(endPos > 0){
return (children.subList(0, endPos)).iterator();
}
return null;
}
return null;
}
示例13: checkPredicate
import org.dmg.pmml.Predicate; //导入依赖的package包/类
static
private boolean checkPredicate(Node node, FieldName name, SimplePredicate.Operator operator){
Predicate predicate = node.getPredicate();
if(predicate instanceof SimplePredicate){
SimplePredicate simplePredicate = (SimplePredicate)predicate;
return (simplePredicate.getField()).equals(name) && (simplePredicate.getOperator()).equals(operator);
}
return false;
}
示例14: encodePredicate
import org.dmg.pmml.Predicate; //导入依赖的package包/类
static
private Predicate encodePredicate(Feature feature, Node node, boolean left){
FieldName name = feature.getName();
SimplePredicate.Operator operator;
String value;
if(feature instanceof BinaryFeature){
BinaryFeature binaryFeature = (BinaryFeature)feature;
operator = (left ? SimplePredicate.Operator.NOT_EQUAL : SimplePredicate.Operator.EQUAL);
value = binaryFeature.getValue();
} else
{
ContinuousFeature continuousFeature = feature.toContinuousFeature();
Number splitValue = node.getThreshold();
DataType dataType = continuousFeature.getDataType();
switch(dataType){
case INTEGER:
splitValue = (int)(splitValue.floatValue() + 1f);
break;
case FLOAT:
break;
default:
throw new IllegalArgumentException();
}
operator = (left ? SimplePredicate.Operator.LESS_OR_EQUAL : SimplePredicate.Operator.GREATER_THAN);
value = ValueUtil.formatValue(splitValue);
}
SimplePredicate simplePredicate = new SimplePredicate(name, operator)
.setValue(value);
return simplePredicate;
}
示例15: ensurePredicate
import org.dmg.pmml.Predicate; //导入依赖的package包/类
static
public <E extends PMMLObject & HasPredicate<E>> Predicate ensurePredicate(E hasPredicate){
Predicate predicate = hasPredicate.getPredicate();
if(predicate == null){
throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(hasPredicate.getClass()) + "/<Predicate>"), hasPredicate);
}
return predicate;
}