org.dmg.pmml.VisitorAction Java Examples

The following examples show how to use org.dmg.pmml.VisitorAction. 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: MapHolderParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(GeneralRegressionModel generalRegressionModel){
	BaseCumHazardTables baseCumHazardTables = generalRegressionModel.getBaseCumHazardTables();

	if(baseCumHazardTables != null){
		FieldName baselineStrataVariable = generalRegressionModel.getBaselineStrataVariable();

		if(baselineStrataVariable != null){
			DataType dataType = resolveDataType(baselineStrataVariable);

			if(dataType != null){
				generalRegressionModel.setBaseCumHazardTables(new RichBaseCumHazardTables(dataType, baseCumHazardTables));
			}
		}
	}

	return super.visit(generalRegressionModel);
}
 
Example #2
Source File: MapHolderParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(DataDictionary dataDictionary){

	if(dataDictionary.hasDataFields()){
		List<DataField> dataFields = dataDictionary.getDataFields();

		for(ListIterator<DataField> it = dataFields.listIterator(); it.hasNext(); ){
			DataField dataField = it.next();

			if(dataField.hasValues()){
				it.set(new RichDataField(dataField));
			}
		}
	}

	return super.visit(dataDictionary);
}
 
Example #3
Source File: TargetCategoryParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(Node node){
	PMMLObject parent = getParent();

	if(parent instanceof TreeModel){
		TreeModel treeModel = (TreeModel)parent;

		MiningFunction miningFunction = treeModel.getMiningFunction();
		switch(miningFunction){
			case CLASSIFICATION:
				break;
			default:
				return VisitorAction.SKIP;
		}
	}

	node.setScore(parseTargetValue(node.getScore()));

	return super.visit(node);
}
 
Example #4
Source File: TargetCategoryParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(OutputField outputField){
	ResultFeature resultFeature = outputField.getResultFeature();

	switch(resultFeature){
		case PROBABILITY:
		case CONFIDENCE:
		case AFFINITY:
			{
				outputField.setValue(parseTargetValue(outputField.getTargetField(), outputField.getValue()));
			}
			break;
		default:
			break;
	}

	return super.visit(outputField);
}
 
Example #5
Source File: InvalidMarkupInspector.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(VectorDictionary vectorDictionary){
	check(new CollectionSize(vectorDictionary){

		@Override
		public Integer getSize(){
			return vectorDictionary.getNumberOfVectors();
		}

		@Override
		public Collection<?> getCollection(){
			return vectorDictionary.getVectorInstances();
		}
	});

	return super.visit(vectorDictionary);
}
 
Example #6
Source File: InvalidMarkupInspector.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(NeuralOutputs neuralOutputs){
	check(new CollectionSize(neuralOutputs){

		@Override
		public Integer getSize(){
			return neuralOutputs.getNumberOfOutputs();
		}

		@Override
		public Collection<?> getCollection(){
			return neuralOutputs.getNeuralOutputs();
		}
	});

	return super.visit(neuralOutputs);
}
 
Example #7
Source File: NodeResolver.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(Node node){
	Object defaultChild = node.getDefaultChild();

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

		for(int i = 0, max = children.size(); i < max; i++){
			Node child = children.get(i);

			Object id = child.getId();
			if(id != null && (id).equals(defaultChild)){
				node.setDefaultChild(child);

				break;
			}
		}
	}

	return super.visit(node);
}
 
Example #8
Source File: InvalidMarkupInspector.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(DataDictionary dataDictionary){
	check(new CollectionSize(dataDictionary){

		@Override
		public Integer getSize(){
			return dataDictionary.getNumberOfFields();
		}

		@Override
		public Collection<?> getCollection(){
			return dataDictionary.getDataFields();
		}
	});

	return super.visit(dataDictionary);
}
 
Example #9
Source File: NodeScoreParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(TreeModel treeModel){
	MiningFunction miningFunction = treeModel.getMiningFunction();
	if(miningFunction == null){
		throw new MissingAttributeException(treeModel, PMMLAttributes.TREEMODEL_MININGFUNCTION);
	}

	switch(miningFunction){
		case REGRESSION:
			break;
		default:
			return VisitorAction.SKIP;
	}

	return super.visit(treeModel);
}
 
Example #10
Source File: ValueParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(DiscretizeBin discretizeBin){
	Discretize discretize = (Discretize)getParent();

	DataType dataType = discretize.getDataType();
	if(dataType != null){
		Object binValue = discretizeBin.getBinValue();
		if(binValue != null){
			binValue = parseOrCast(dataType, binValue);

			discretizeBin.setBinValue(binValue);
		}
	}

	return super.visit(discretizeBin);
}
 
Example #11
Source File: ValueParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(Value value){
	PMMLObject parent = getParent();

	Object simpleValue = value.getValue();
	if(simpleValue == null){
		throw new MissingAttributeException(value, PMMLAttributes.VALUE_VALUE);
	} // End if

	if(parent instanceof Field){
		Field<?> field = (Field<?>)parent;

		DataType dataType = field.getDataType();
		if(dataType != null){
			simpleValue = safeParseOrCast(dataType, simpleValue);

			value.setValue(simpleValue);
		}
	}

	return super.visit(value);
}
 
Example #12
Source File: InvalidMarkupInspector.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(ClusteringModel clusteringModel){
	check(new CollectionSize(clusteringModel){

		@Override
		public Integer getSize(){
			return clusteringModel.getNumberOfClusters();
		}

		@Override
		public Collection<?> getCollection(){
			return clusteringModel.getClusters();
		}
	});

	return super.visit(clusteringModel);
}
 
Example #13
Source File: ValueParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(Constant constant){
	boolean missing = constant.isMissing();

	if(!missing){
		Object value = constant.getValue();

		if(!ExpressionUtil.isEmptyContent(value)){
			DataType dataType = constant.getDataType();
			if(dataType == null){
				dataType = TypeUtil.getConstantDataType(value);
			}

			value = parseOrCast(dataType, value);

			constant.setValue(value);
		}
	}

	return super.visit(constant);
}
 
Example #14
Source File: InvalidMarkupInspector.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(Coefficients coefficients){
	check(new CollectionSize(coefficients){

		@Override
		public Integer getSize(){
			return coefficients.getNumberOfCoefficients();
		}

		@Override
		public Collection<?> getCollection(){
			return coefficients.getCoefficients();
		}
	});

	return super.visit(coefficients);
}
 
Example #15
Source File: UnsupportedMarkupInspector.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(NeuralLayer neuralLayer){
	NeuralNetwork.ActivationFunction activationFunction = neuralLayer.getActivationFunction();

	if(activationFunction != null){

		switch(activationFunction){
			case RADIAL_BASIS:
				report(new UnsupportedAttributeException(neuralLayer, activationFunction));
				break;
			default:
				break;
		}
	}

	return super.visit(neuralLayer);
}
 
Example #16
Source File: InvalidMarkupInspector.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(Itemset itemset){
	check(new CollectionSize(itemset){

		@Override
		public Integer getSize(){
			return itemset.getNumberOfItems();
		}

		@Override
		public Collection<?> getCollection(){
			return itemset.getItemRefs();
		}
	});

	return super.visit(itemset);
}
 
Example #17
Source File: ScoreDistributionInterner.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction visit(Node node){

	if(node.hasScoreDistributions()){
		List<ScoreDistribution> scoreDistributions = node.getScoreDistributions();

		for(ListIterator<ScoreDistribution> it = scoreDistributions.listIterator(); it.hasNext(); ){
			it.set(intern(it.next()));
		}
	}

	return super.visit(node);
}
 
Example #18
Source File: TargetCategoryParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction visit(SupportVectorMachine supportVectorMachine){
	supportVectorMachine.setTargetCategory(parseTargetValue(supportVectorMachine.getTargetCategory()));
	supportVectorMachine.setAlternateTargetCategory(parseTargetValue(supportVectorMachine.getAlternateTargetCategory()));

	return super.visit(supportVectorMachine);
}
 
Example #19
Source File: TargetCategoryParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction visit(TargetValue targetValue){
	Target target = (Target)getParent();

	targetValue.setValue(parseTargetValue(target.getField(), targetValue.getValue()));

	return super.visit(targetValue);
}
 
Example #20
Source File: UnsupportedMarkupInspector.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction visit(Segmentation segmentation){
	LocalTransformations localTransformations = segmentation.getLocalTransformations();

	if(localTransformations != null){
		report(new UnsupportedElementException(localTransformations));
	}

	return super.visit(segmentation);
}
 
Example #21
Source File: FieldReferenceFinder.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public VisitorAction visit(TestDistributions testDistributions){
	process(testDistributions.getField());
	process(testDistributions.getWeightField());

	return super.visit(testDistributions);
}
 
Example #22
Source File: FieldNameFilterer.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public VisitorAction visit(OutputField outputField){
	ResultFeature resultFeature = outputField.getResultFeature();

	switch(resultFeature){
		case TRANSFORMED_VALUE:
		case DECISION:
			{
				String segmentId = outputField.getSegmentId();

				if(segmentId != null){
					Object value = outputField.getValue();

					if(value instanceof String){
						value = filter((String)value);
					}

					outputField.setValue(value);
				}
			}
			break;
		default:
			break;
	}

	return super.visit(outputField);
}
 
Example #23
Source File: FieldHasher.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public VisitorAction visit(Field<?> field){
	FieldName name = field.getName();

	if(name != null){
		this.mappings.put(name, hash(name));
	}

	return super.visit(field);
}
 
Example #24
Source File: JavaPredicate.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction accept(Visitor visitor){
	VisitorAction status = visitor.visit(this);

	if(status == VisitorAction.CONTINUE){
		visitor.pushParent(this);
		visitor.popParent();
	} // End if

	if(status == VisitorAction.TERMINATE){
		return VisitorAction.TERMINATE;
	}

	return VisitorAction.CONTINUE;
}
 
Example #25
Source File: NodeScoreParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction visit(Node node){

	if(node.hasScore()){
		Object score = node.getScore();

		if(score instanceof String){
			score = parseScore(score);

			node.setScore(score);
		}
	}

	return super.visit(node);
}
 
Example #26
Source File: FunctionExpression.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction accept(Visitor visitor){
	VisitorAction status = visitor.visit(this);

	if(status == VisitorAction.CONTINUE){
		visitor.pushParent(this);

		if(hasArguments()){
			List<Argument> arguments = getArguments();

			for(Argument argument : arguments){
				status = PMMLObject.traverse(visitor, argument.getExpression());

				if(status != VisitorAction.CONTINUE){
					break;
				}
			}
		}

		visitor.popParent();
	} // End if

	if(status == VisitorAction.TERMINATE){
		return VisitorAction.TERMINATE;
	}

	return VisitorAction.CONTINUE;
}
 
Example #27
Source File: TargetCategoryParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction visit(TargetValueCount targetValueCount){
	Object value = targetValueCount.getValue();
	if(value == null){
		throw new MissingAttributeException(targetValueCount, org.dmg.pmml.naive_bayes.PMMLAttributes.TARGETVALUECOUNT_VALUE);
	}

	targetValueCount.setValue(parseTargetValue(value));

	return super.visit(targetValueCount);
}
 
Example #28
Source File: ValueParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction visit(CategoricalPredictor categoricalPredictor){
	FieldName name = categoricalPredictor.getField();
	if(name == null){
		throw new MissingAttributeException(categoricalPredictor, org.dmg.pmml.regression.PMMLAttributes.CATEGORICALPREDICTOR_FIELD);
	}

	parseValue(name, categoricalPredictor);

	return super.visit(categoricalPredictor);
}
 
Example #29
Source File: JavaExpression.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction accept(Visitor visitor){
	VisitorAction status = visitor.visit(this);

	if(status == VisitorAction.CONTINUE){
		visitor.pushParent(this);
		visitor.popParent();
	} // End if

	if(status == VisitorAction.TERMINATE){
		return VisitorAction.TERMINATE;
	}

	return VisitorAction.CONTINUE;
}
 
Example #30
Source File: IntegrationTestBatch.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void validatePMML(PMML pmml) throws Exception {
	List<Visitor> visitors = Arrays.<Visitor>asList(
		new UnsupportedMarkupInspector(),
		new InvalidMarkupInspector(){

			@Override
			public VisitorAction visit(Application application){
				String name = application.getName();

				if(name == null){
					return VisitorAction.SKIP;
				}

				return super.visit(application);
			}

			@Override
			public VisitorAction visit(MiningSchema miningSchema){

				if(!miningSchema.hasMiningFields()){
					return VisitorAction.SKIP;
				}

				return super.visit(miningSchema);
			}
		}
	);

	for(Visitor visitor : visitors){
		visitor.applyTo(pmml);
	}
}