org.dmg.pmml.HasFieldReference Java Examples

The following examples show how to use org.dmg.pmml.HasFieldReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NeuralNetworkEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private Map<FieldName, List<NeuralOutput>> parseNeuralOutputs(){
	NeuralNetwork neuralNetwork = getModel();

	ListMultimap<FieldName, NeuralOutput> result = ArrayListMultimap.create();

	NeuralOutputs neuralOutputs = neuralNetwork.getNeuralOutputs();
	for(NeuralOutput neuralOutput : neuralOutputs){
		FieldName name;

		Expression expression = getOutputExpression(neuralOutput);

		if(expression instanceof HasFieldReference){
			HasFieldReference<?> hasFieldReference = (HasFieldReference<?>)expression;

			name = hasFieldReference.getField();
			if(name == null){
				throw new MissingAttributeException(MissingAttributeException.formatMessage(XPathUtil.formatElement((Class)hasFieldReference.getClass()) + "@field"), expression);
			}
		} else

		{
			throw new MisplacedElementException(expression);
		}

		result.put(name, neuralOutput);
	}

	return (Map)result.asMap();
}
 
Example #2
Source File: ExpressionUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
public <E extends Expression & HasFieldReference<E>> FieldName ensureField(E hasField){
	FieldName name = hasField.getField();
	if(name == null){
		throw new MissingAttributeException(MissingAttributeException.formatMessage(XPathUtil.formatElement(hasField.getClass()) + "@field"), hasField);
	}

	return name;
}
 
Example #3
Source File: RandomForestCompactor.java    From jpmml-r with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void enterNode(Node node){
	Object id = node.getId();
	Object score = node.getScore();

	if(id == null){
		throw new IllegalArgumentException();
	} // End if

	if(node.hasNodes()){
		List<Node> children = node.getNodes();

		if(children.size() != 2 || score != null){
			throw new IllegalArgumentException();
		}

		Node firstChild = children.get(0);
		Node secondChild = children.get(1);

		Predicate firstPredicate = firstChild.getPredicate();
		Predicate secondPredicate = secondChild.getPredicate();

		checkFieldReference(firstPredicate, secondPredicate);

		boolean update = isDefinedField((HasFieldReference<?>)firstPredicate);

		if(hasOperator(firstPredicate, SimplePredicate.Operator.EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.EQUAL)){
			// Ignored
		} else

		if(hasOperator(firstPredicate, SimplePredicate.Operator.LESS_OR_EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.GREATER_THAN)){
			update = true;
		} else

		if(hasOperator(firstPredicate, SimplePredicate.Operator.EQUAL) && hasBooleanOperator(secondPredicate, SimpleSetPredicate.BooleanOperator.IS_IN)){
			// Ignored
		} else

		if(hasBooleanOperator(firstPredicate, SimpleSetPredicate.BooleanOperator.IS_IN) && hasOperator(secondPredicate, SimplePredicate.Operator.EQUAL)){

			if(update){
				children = swapChildren(node);

				firstChild = children.get(0);
				secondChild = children.get(1);
			}
		} else

		if(hasBooleanOperator(firstPredicate, SimpleSetPredicate.BooleanOperator.IS_IN) && hasBooleanOperator(secondPredicate, SimpleSetPredicate.BooleanOperator.IS_IN)){
			// Ignored
		} else

		{
			throw new IllegalArgumentException();
		} // End if

		if(update){
			secondChild.setPredicate(True.INSTANCE);
		}
	} else

	{
		if(score == null){
			throw new IllegalArgumentException();
		}
	}

	node.setId(null);
}
 
Example #4
Source File: RandomForestCompactor.java    From jpmml-r with GNU Affero General Public License v3.0 3 votes vote down vote up
private boolean isDefinedField(HasFieldReference<?> hasFieldReference){
	FieldName name = hasFieldReference.getField();

	Node ancestorNode = getAncestorNode(node -> hasFieldReference(node.getPredicate(), name));

	return (ancestorNode != null);
}