@Override public VisitorAction visit(Node node){ MathContext mathContext = this.mathContext; if(mathContext != null && node.hasScore()){ Object score = node.getScore(); if(score instanceof String){ String stringScore = (String)score; try { switch(mathContext){ case DOUBLE: node.setScore(Double.parseDouble(stringScore)); break; case FLOAT: node.setScore(Float.parseFloat(stringScore)); break; default: break; } } catch(NumberFormatException nfe){ // Ignored } } } return super.visit(node); } }
@Override public VisitorAction visit(Node node){ MathContext mathContext = this.mathContext; if(mathContext != null && node.hasScore()){ Object score = node.getScore(); if(score instanceof String){ String stringScore = (String)score; try { switch(mathContext){ case DOUBLE: node.setScore(Double.parseDouble(stringScore)); break; case FLOAT: node.setScore(Float.parseFloat(stringScore)); break; default: break; } } catch(NumberFormatException nfe){ // Ignored } } } return super.visit(node); } }
private Node evaluateTree(Trail trail, EvaluationContext context){ TreeModel treeModel = getModel(); Node root = treeModel.getNode(); Boolean status = evaluateNode(trail, root, context); if(status != null && status.booleanValue()){ trail = handleTrue(trail, root, context); Node node = trail.getResult(); // "It is not possible that the scoring process ends in a Node which does not have a score attribute" if(node != null && !node.hasScore()){ throw new MissingAttributeException(node, PMMLAttributes.NODE_SCORE); } return node; } return null; }
private Trail handleNoTrueChild(Trail trail){ TreeModel treeModel = getModel(); TreeModel.NoTrueChildStrategy noTrueChildStrategy = treeModel.getNoTrueChildStrategy(); switch(noTrueChildStrategy){ case RETURN_NULL_PREDICTION: return trail.selectNull(); case RETURN_LAST_PREDICTION: Node lastPrediction = trail.getLastPrediction(); // "Return the parent Node only if it specifies a score attribute" if(lastPrediction.hasScore()){ return trail.selectLastPrediction(); } return trail.selectNull(); default: throw new UnsupportedAttributeException(treeModel, noTrueChildStrategy); } }