Java Code Examples for org.dmg.pmml.MiningField#getName()

The following examples show how to use org.dmg.pmml.MiningField#getName() . 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: ValueParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(MiningField miningField){
	FieldName name = miningField.getName();
	if(name == null){
		throw new MissingAttributeException(miningField, PMMLAttributes.MININGFIELD_NAME);
	}

	DataType dataType = resolveDataType(name);
	if(dataType != null){
		Object missingValueReplacement = miningField.getMissingValueReplacement();
		if(missingValueReplacement != null){
			missingValueReplacement = safeParseOrCast(dataType, missingValueReplacement);

			miningField.setMissingValueReplacement(missingValueReplacement);
		}

		Object invalidValueReplacement = miningField.getInvalidValueReplacement();
		if(invalidValueReplacement != null){
			invalidValueReplacement = safeParseOrCast(dataType, invalidValueReplacement);

			miningField.setInvalidValueReplacement(invalidValueReplacement);
		}
	}

	return super.visit(miningField);
}
 
Example 2
Source File: ModelManager.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
protected List<InputField> createInputFields(MiningField.UsageType usageType){
	M model = getModel();

	MiningSchema miningSchema = model.getMiningSchema();

	List<InputField> inputFields = new ArrayList<>();

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

		for(MiningField miningField : miningFields){
			FieldName name = miningField.getName();

			if(!(miningField.getUsageType()).equals(usageType)){
				continue;
			}

			Field<?> field = getDataField(name);
			if(field == null){
				field = new VariableField(name);
			}

			InputField inputField = new InputField(field, miningField);

			inputFields.add(inputField);
		}
	}

	return ImmutableList.copyOf(inputFields);
}
 
Example 3
Source File: TargetCategoryParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private void processModel(Model model){
	MiningSchema miningSchema = model.getMiningSchema();
	if(miningSchema == null){
		throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(model.getClass()) + "/" + XPathUtil.formatElement(MiningSchema.class)), model);
	}

	Map<FieldName, DataType> targetDataTypes = new LinkedHashMap<>();

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

		for(MiningField miningField : miningFields){
			FieldName name = miningField.getName();
			if(name == null){
				throw new MissingAttributeException(miningField, PMMLAttributes.MININGFIELD_NAME);
			}

			MiningField.UsageType usageType = miningField.getUsageType();
			switch(usageType){
				case PREDICTED:
				case TARGET:
					DataType dataType = resolveTargetDataType(name);

					targetDataTypes.put(name, dataType);
					break;
				default:
					break;
			}
		}
	}

	this.targetDataTypes.push(targetDataTypes);

	this.dataType = getDataType();
}
 
Example 4
Source File: ModelManager.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
protected ModelManager(PMML pmml, M model){
	setPMML(Objects.requireNonNull(pmml));
	setModel(Objects.requireNonNull(model));

	DataDictionary dataDictionary = pmml.getDataDictionary();
	if(dataDictionary == null){
		throw new MissingElementException(pmml, PMMLElements.PMML_DATADICTIONARY);
	} // End if

	if(dataDictionary.hasDataFields()){
		this.dataFields = CacheUtil.getValue(dataDictionary, ModelManager.dataFieldCache);
	}

	TransformationDictionary transformationDictionary = pmml.getTransformationDictionary();
	if(transformationDictionary != null && transformationDictionary.hasDerivedFields()){
		this.derivedFields = CacheUtil.getValue(transformationDictionary, ModelManager.derivedFieldCache);
	} // End if

	if(transformationDictionary != null && transformationDictionary.hasDefineFunctions()){
		this.defineFunctions = CacheUtil.getValue(transformationDictionary, ModelManager.defineFunctionCache);
	}

	MiningFunction miningFunction = model.getMiningFunction();
	if(miningFunction == null){
		throw new MissingAttributeException(MissingAttributeException.formatMessage(XPathUtil.formatElement(model.getClass()) + "@miningFunction"), model);
	}

	MiningSchema miningSchema = model.getMiningSchema();
	if(miningSchema == null){
		throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(model.getClass()) + "/" + XPathUtil.formatElement(MiningSchema.class)), model);
	} // End if

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

		for(MiningField miningField : miningFields){
			FieldName name = miningField.getName();
			if(name == null){
				throw new MissingAttributeException(miningField, PMMLAttributes.MININGFIELD_NAME);
			}
		}

		this.miningFields = CacheUtil.getValue(miningSchema, ModelManager.miningFieldCache);
	}

	LocalTransformations localTransformations = model.getLocalTransformations();
	if(localTransformations != null && localTransformations.hasDerivedFields()){
		this.localDerivedFields = CacheUtil.getValue(localTransformations, ModelManager.localDerivedFieldCache);
	}

	Targets targets = model.getTargets();
	if(targets != null && targets.hasTargets()){
		this.targets = CacheUtil.getValue(targets, ModelManager.targetCache);
	}

	Output output = model.getOutput();
	if(output != null && output.hasOutputFields()){
		this.outputFields = CacheUtil.getValue(output, ModelManager.outputFieldCache);
		this.resultFeatures = CacheUtil.getValue(output, ModelManager.resultFeaturesCache);
	}
}
 
Example 5
Source File: MiningFieldInterner.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public ElementKey createKey(MiningField miningField){
	Object[] content = {miningField.getName()};

	return new ElementKey(content);
}