Java Code Examples for org.dmg.pmml.DerivedField#getDataType()

The following examples show how to use org.dmg.pmml.DerivedField#getDataType() . 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 5 votes vote down vote up
@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 2
Source File: ImputerUtil.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
static
public Feature encodeFeature(Feature feature, Boolean addIndicator, Object missingValue, Object replacementValue, MissingValueTreatmentMethod missingValueTreatmentMethod, SkLearnEncoder encoder){
	Field<?> field = feature.getField();

	if(field instanceof DataField && !addIndicator){
		DataField dataField = (DataField)field;

		encoder.addDecorator(dataField, new MissingValueDecorator(missingValueTreatmentMethod, replacementValue));

		if(missingValue != null){
			PMMLUtil.addValues(dataField, Collections.singletonList(missingValue), Value.Property.MISSING);
		}

		return feature;
	} // End if

	if((field instanceof DataField) || (field instanceof DerivedField)){
		Expression expression = feature.ref();

		if(missingValue != null){
			expression = PMMLUtil.createApply(PMMLFunctions.EQUAL, expression, PMMLUtil.createConstant(missingValue, feature.getDataType()));
		} else

		{
			expression = PMMLUtil.createApply(PMMLFunctions.ISMISSING, expression);
		}

		expression = PMMLUtil.createApply(PMMLFunctions.IF)
			.addExpressions(expression)
			.addExpressions(PMMLUtil.createConstant(replacementValue, feature.getDataType()), feature.ref());

		DerivedField derivedField = encoder.createDerivedField(FeatureUtil.createName("imputer", feature), field.getOpType(), field.getDataType(), expression);

		DataType dataType = derivedField.getDataType();
		switch(dataType){
			case INTEGER:
			case FLOAT:
			case DOUBLE:
				return new ContinuousFeature(encoder, derivedField);
			case STRING:
				return new StringFeature(encoder, derivedField);
			default:
				return new ObjectFeature(encoder, derivedField.getName(), derivedField.getDataType());
		}
	} else

	{
		throw new IllegalArgumentException();
	}
}
 
Example 3
Source File: NearestNeighborModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue prepare(Object value){
	DerivedField derivedField = getDerivedField();
	MiningField miningField = getMiningField();

	if(miningField != null){
		return InputFieldUtil.prepareInputValue(derivedField, miningField, value);
	}

	TypeInfo typeInfo = new TypeInfo(){

		@Override
		public DataType getDataType(){
			DataType dataType = derivedField.getDataType();
			if(dataType == null){
				throw new MissingAttributeException(derivedField, org.dmg.pmml.PMMLAttributes.DERIVEDFIELD_DATATYPE);
			}

			return dataType;
		}

		@Override
		public OpType getOpType(){
			OpType opType = derivedField.getOpType();
			if(opType == null){
				throw new MissingAttributeException(derivedField, org.dmg.pmml.PMMLAttributes.DERIVEDFIELD_OPTYPE);
			}

			return opType;
		}

		@Override
		public List<?> getOrdering(){
			List<?> ordering = FieldUtil.getValidValues(derivedField);

			return ordering;
		}
	};

	return FieldValueUtil.create(typeInfo, value);
}