Java Code Examples for org.dmg.pmml.FieldName#getValue()

The following examples show how to use org.dmg.pmml.FieldName#getValue() . 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: Domain.java    From jpmml-sklearn with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public DataField updateDataField(DataField dataField, OpType opType, DataType dataType, SkLearnEncoder encoder){
	FieldName name = dataField.getName();

	if(encoder.isFrozen(name)){
		throw new IllegalArgumentException("Field " + name.getValue() + " is frozen for type information updates");
	}

	dataField
		.setDataType(dataType)
		.setOpType(opType);

	encoder.setDomain(name, this);

	return dataField;
}
 
Example 2
Source File: StreamlineJPMMLModelRunner.java    From streamline with Apache License 2.0 5 votes vote down vote up
private void putPmmlScoresInEvent(Map<FieldName, ?> predScores, Set<String> inserted,
        StreamlineEventImpl.Builder eventBuilder, List<FieldName> predOrOutFields, String msg) {

    for (FieldName predOrOutField : predOrOutFields) {
        final Object targetValue = predScores.get(predOrOutField);
        final String fieldName = predOrOutField.getValue();
        final Object predValue = EvaluatorUtil.decode(targetValue);
        eventBuilder.put(fieldName, predValue);
        LOG.debug(msg, fieldName, predValue);
        inserted.add(fieldName);
    }
}
 
Example 3
Source File: SkLearnEncoder.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void addDerivedField(DerivedField derivedField){

	try {
		super.addDerivedField(derivedField);
	} catch(RuntimeException re){
		FieldName name = derivedField.getName();

		String message = "Field " + name.getValue() + " is already defined. " +
			"Please refactor the pipeline so that it would not contain duplicate field declarations, " +
			"or use the " + (Alias.class).getName() + " wrapper class to override the default name with a custom name (eg. " + Alias.formatAliasExample() + ")";

		throw new IllegalArgumentException(message, re);
	}
}
 
Example 4
Source File: SkLearnEncoder.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
public void renameFeature(Feature feature, FieldName renamedName){
	FieldName name = feature.getName();

	org.dmg.pmml.Field<?> pmmlField = getField(name);

	if(pmmlField instanceof DataField){
		throw new IllegalArgumentException("User input field " + name.getValue() + " cannot be renamed");
	}

	DerivedField derivedField = removeDerivedField(name);

	try {
		Field field = Feature.class.getDeclaredField("name");

		if(!field.isAccessible()){
			field.setAccessible(true);
		}

		field.set(feature, renamedName);
	} catch(ReflectiveOperationException roe){
		throw new RuntimeException(roe);
	}

	derivedField.setName(renamedName);

	addDerivedField(derivedField);
}
 
Example 5
Source File: Formula.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
public Feature resolveFeature(FieldName name){
	Feature feature = getFeature(name);

	if(feature == null){
		throw new IllegalArgumentException(name.getValue());
	}

	return feature;
}
 
Example 6
Source File: FieldNameAdapter.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String marshal(FieldName value){

	// FieldName corresponds to a simple type in PMML XML Schema. Hence, it is possible to encounter a null instance.
	if(value == null){
		return null;
	}

	return value.getValue();
}
 
Example 7
Source File: PMMLException.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
public String formatKey(Object object){

	if(object instanceof FieldName){
		FieldName name = (FieldName)object;

		object = name.getValue();
	} // End if

	return format(object);
}
 
Example 8
Source File: ModelUtil.java    From openscoring with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private List<Field> encodeModelFields(List<? extends ModelField> modelFields){
	Function<ModelField, Field> function = new Function<ModelField, Field>(){

		@Override
		public Field apply(ModelField modelField){
			org.dmg.pmml.Field<?> pmmlField = modelField.getField();

			FieldName name = modelField.getName();

			Field field = new Field(name.getValue());
			field.setName(modelField.getDisplayName());
			field.setOpType(modelField.getOpType());
			field.setDataType(modelField.getDataType());

			List<String> values = new ArrayList<>();

			if(pmmlField instanceof HasContinuousDomain){
				values.addAll(encodeContinuousDomain((org.dmg.pmml.Field & HasContinuousDomain)pmmlField));
			} // End if

			if(pmmlField instanceof HasDiscreteDomain){
				values.addAll(encodeDiscreteDomain((org.dmg.pmml.Field & HasDiscreteDomain)pmmlField));
			}

			field.setValues(values);

			return field;
		}
	};

	return modelFields.stream()
		.map(function)
		.collect(Collectors.toList());
}
 
Example 9
Source File: FieldNameFilterer.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
private String filter(String value){
	FieldName name = FieldName.create(value);

	name = filter(name);

	return name.getValue();
}
 
Example 10
Source File: ModelResource.java    From openscoring with GNU Affero General Public License v3.0 3 votes vote down vote up
static
protected EvaluationResponse evaluate(Evaluator evaluator, EvaluationRequest request){
	logger.info("Received {}", request);

	Map<String, ?> requestArguments = request.getArguments();

	EvaluationResponse response = new EvaluationResponse(request.getId());

	Map<FieldName, FieldValue> arguments = new LinkedHashMap<>();

	List<InputField> inputFields = evaluator.getInputFields();
	for(InputField inputField : inputFields){
		FieldName inputName = inputField.getName();

		String key = inputName.getValue();

		Object value = requestArguments.get(key);
		if(value == null && !requestArguments.containsKey(key)){
			logger.warn("Evaluation request {} does not specify an input field {}", request.getId(), key);
		}

		FieldValue inputValue = inputField.prepare(value);

		arguments.put(inputName, inputValue);
	}

	logger.debug("Evaluation request {} has prepared arguments: {}", request.getId(), arguments);

	Map<FieldName, ?> results = evaluator.evaluate(arguments);

	logger.debug("Evaluation response {} has result: {}", response.getId(), results);

	response.setResults(EvaluatorUtil.decodeAll(results));

	logger.info("Returned {}", response);

	return response;
}