Java Code Examples for org.dmg.pmml.VisitorAction

The following examples show how to use org.dmg.pmml.VisitorAction. These examples are extracted from open source projects. 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
@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 2
@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 3
@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 4
@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 5
@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 6
@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 7
@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 8
@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 9
@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 10
@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 11
@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 12
@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 13
@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 14
@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 15
@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 16
@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 17
@Override
public VisitorAction visit(DataField dataField){
	DataType dataType = dataField.getDataType();

	switch(dataType){
		case FLOAT:
		case DOUBLE:
			PMMLUtil.addValues(dataField, Collections.singletonList("NaN"), Property.MISSING);
			break;
		default:
			break;
	}

	return super.visit(dataField);
}
 
Example 18
@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 19
@Override
public VisitorAction visit(BayesInputs bayesInputs){

	if(bayesInputs.hasBayesInputs()){
		List<BayesInput> content = bayesInputs.getBayesInputs();

		for(ListIterator<BayesInput> it = content.listIterator(); it.hasNext(); ){
			BayesInput bayesInput = it.next();

			FieldName name = bayesInput.getField();
			if(name == null){
				throw new MissingAttributeException(bayesInput, org.dmg.pmml.naive_bayes.PMMLAttributes.BAYESINPUT_FIELD);
			}

			DataType dataType;

			DerivedField derivedField = bayesInput.getDerivedField();
			if(derivedField != null){
				dataType = derivedField.getDataType();

				if(dataType == null){
					throw new MissingAttributeException(derivedField, PMMLAttributes.DERIVEDFIELD_DATATYPE);
				}
			} else

			{
				dataType = resolveDataType(name);
			} // End if

			if(dataType != null){
				it.set(new RichBayesInput(dataType, bayesInput));
			}
		}
	}

	return super.visit(bayesInputs);
}
 
Example 20
@Override
public VisitorAction visit(LocalTransformations localTransformations){
	Model model = (Model)getParent();

	if(localTransformations.hasDerivedFields()){
		declareLocalFields(model, false);

		suppressFields(localTransformations);
	}

	return super.visit(localTransformations);
}
 
Example 21
@Override
public VisitorAction visit(Output output){

	if(output.hasOutputFields()){
		declareFields(output, output.getOutputFields());

		suppressFields(output);
	}

	return super.visit(output);
}
 
Example 22
@Override
public VisitorAction visit(TreeModel treeModel){
	TreeModel.MissingValueStrategy missingValueStrategy = treeModel.getMissingValueStrategy();

	switch(missingValueStrategy){
		case AGGREGATE_NODES:
		case WEIGHTED_CONFIDENCE:
			report(new UnsupportedAttributeException(treeModel, missingValueStrategy));
			break;
		default:
			break;
	}

	return super.visit(treeModel);
}
 
Example 23
@Override
public VisitorAction visit(ClusteringModel clusteringModel){
	ClusteringModel.ModelClass modelClass = clusteringModel.getModelClass();

	switch(modelClass){
		case DISTRIBUTION_BASED:
			report(new UnsupportedAttributeException(clusteringModel, modelClass));
			break;
		default:
			break;
	}

	return super.visit(clusteringModel);
}
 
Example 24
@Override
public VisitorAction visit(Node node){

	if(node.hasNodes()){
		filterAll(node.getNodes());
	}

	return super.visit(node);
}
 
Example 25
@Override
public VisitorAction visit(NormDiscrete normDiscrete){
	FieldName name = normDiscrete.getField();
	if(name == null){
		throw new MissingAttributeException(normDiscrete, PMMLAttributes.NORMDISCRETE_FIELD);
	}

	parseValue(name, normDiscrete);

	return super.visit(normDiscrete);
}
 
Example 26
@Override
public VisitorAction visit(PMMLObject object){

	if(object instanceof HasPredicate){
		HasPredicate<?> hasPredicate = (HasPredicate<?>)object;

		hasPredicate.setPredicate(filter(hasPredicate.getPredicate()));
	}

	return super.visit(object);
}
 
Example 27
@Override
public VisitorAction visit(CompoundPredicate compoundPredicate){

	if(compoundPredicate.hasPredicates()){
		filterAll(compoundPredicate.getPredicates());
	}

	return super.visit(compoundPredicate);
}
 
Example 28
@Override
public VisitorAction visit(IntSparseArray intSparseArray){

	if(intSparseArray.hasEntries()){
		internAll(intSparseArray.getEntries());
	} // End if

	if(intSparseArray.hasIndices()){
		internAll(intSparseArray.getIndices());
	}

	return super.visit(intSparseArray);
}
 
Example 29
@Override
public VisitorAction visit(RealSparseArray realSparseArray){

	if(realSparseArray.hasIndices()){
		internAll(realSparseArray.getIndices());
	}

	return super.visit(realSparseArray);
}
 
Example 30
@Override
public VisitorAction visit(MiningSchema miningSchema){

	if(miningSchema.hasMiningFields()){
		List<MiningField> miningFields = miningSchema.getMiningFields();

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

	return super.visit(miningSchema);
}