当前位置: 首页>>代码示例>>Java>>正文


Java IOObject.getAnnotations方法代码示例

本文整理汇总了Java中com.rapidminer.operator.IOObject.getAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java IOObject.getAnnotations方法的具体用法?Java IOObject.getAnnotations怎么用?Java IOObject.getAnnotations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.rapidminer.operator.IOObject的用法示例。


在下文中一共展示了IOObject.getAnnotations方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doWork

import com.rapidminer.operator.IOObject; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
	IOObject data = inputPort.getData(IOObject.class);
	Annotations annotations = data.getAnnotations();
	Attribute annotationAttr = AttributeFactory.createAttribute(ANNOTATION_ATTRIBUTE, Ontology.POLYNOMINAL);
	Attribute valueAttr = AttributeFactory.createAttribute(VALUE_ATTRIBUTE, Ontology.POLYNOMINAL);

	MemoryExampleTable table = new MemoryExampleTable(annotationAttr, valueAttr);

	for (String annotation : annotations.getDefinedAnnotationNames()) {
		double[] rowData = new double[2];
		rowData[0] = annotationAttr.getMapping().mapString(annotation);
		rowData[1] = valueAttr.getMapping().mapString(annotations.getAnnotation(annotation));
		table.addDataRow(new DoubleArrayDataRow(rowData));
	}

	ExampleSet exampleSet = table.createExampleSet();
	exampleSet.getAttributes().setSpecialAttribute(annotationAttr, Attributes.ID_NAME);
	outputPort.deliver(data);
	annotationsOutputPort.deliver(exampleSet);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:22,代码来源:AnnotationsToData.java

示例2: assertEquals

import com.rapidminer.operator.IOObject; //导入方法依赖的package包/类
/**
 * Tests if the two IOObjects are equal and appends the given message.
 *
 * @param assertEqualAnnotations
 *            if true, annotations will be compared. If false, they will be ignored.
 * @param expectedIOO
 * @param actualIOO
 */
public static void assertEquals(String message, IOObject expectedIOO, IOObject actualIOO, boolean assertEqualAnnotations) {

	/*
	 * Do not forget to add a newly supported class to the ASSERTER_REGISTRY!!!
	 */
	List<Asserter> asserterList = ASSERTER_REGISTRY.getAsserterForObjects(expectedIOO, actualIOO);
	if (asserterList != null) {
		for (Asserter asserter : asserterList) {
			asserter.assertEquals(message, expectedIOO, actualIOO);
		}
	} else {
		throw new ComparisonFailure("Comparison of the two given IOObject classes " + expectedIOO.getClass() + " and "
				+ actualIOO.getClass() + " is not supported. ", expectedIOO.toString(), actualIOO.toString());
	}

	// last, compare annotations:
	if (assertEqualAnnotations) {
		Annotations expectedAnnotations = expectedIOO.getAnnotations();
		Annotations actualAnnotations = actualIOO.getAnnotations();

		if (ignoreRepositoryNameForSourceAnnotation) {
			// compare annotations one by one. For the Source annotation, ignore the repository
			// name
			// (that's what all the regular expressions here are for)
			for (String key : expectedAnnotations.getKeys()) {
				String expectedValue = expectedAnnotations.getAnnotation(key);
				String actualValue = actualAnnotations.getAnnotation(key);

				if (expectedValue != null) {
					Assert.assertNotNull(message + "objects are equal, but annotation '" + key + "' is missing",
							actualValue);
				}

				if (Annotations.KEY_SOURCE.equals(key)) {
					if (expectedValue != null && expectedValue.startsWith("//") && expectedValue.matches("//[^/]+/.*")) {
						expectedValue = expectedValue.replaceAll("^//[^/]+/", "//repository/");
						if (actualValue != null) {
							actualValue = actualValue.replaceAll("^//[^/]+/", "//repository/");
						}
					}
				}
				Assert.assertEquals(message + "objects are equal, but annotation '" + key + "' differs: ",
						expectedValue, actualValue);
			}
		} else {
			Assert.assertEquals(message + "objects are equal, but annotations differ: ", expectedAnnotations,
					actualAnnotations);
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:59,代码来源:RapidAssert.java

示例3: doWork

import com.rapidminer.operator.IOObject; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
	IOObject data = inputPort.getData(IOObject.class);
	Annotations annotations = data.getAnnotations();

	// get index of action for duplicate annotations
	String duplicateActionString = getParameterAsString(PARAMETER_DUPLICATE_HANDLING);
	int duplicateAction = ERROR_ON_DUPLICATES;
	for (int i = 0; i < DUPLICATE_HANDLING_LIST.length; ++i) {
		if (DUPLICATE_HANDLING_LIST[i].equals(duplicateActionString)) {
			duplicateAction = i;
			break;
		}
	}

	// just set annotations without any checks
	List<String[]> parameterList = getParameterList(PARAMETER_ANNOTATIONS);
	for (String[] nameValuePair : parameterList) {
		String key = nameValuePair[0];
		String value = nameValuePair[1];
		if (value == null || "".equals(value)) {
			annotations.removeAnnotation(key);
		} else if (annotations.containsKey(key)) {
			switch (duplicateAction) {
				case OVERWRITE_DUPLICATES:
					// overwrite annotations
					annotations.setAnnotation(key, value);
					break;
				case IGNORE_DUPLICATES:
					// do nothing
					break;
				case ERROR_ON_DUPLICATES:
					// throw user error
					throw new UserError(this, "annotate.duplicate_annotation", key);
			}
		} else {
			annotations.setAnnotation(key, value);
		}
	}
	outputPort.deliver(data);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:42,代码来源:AnnotateOperator.java

示例4: doWork

import com.rapidminer.operator.IOObject; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
	IOObject object = objectInputPort.getData(IOObject.class);
	ExampleSet annotationData = annotationsInputPort.getData(ExampleSet.class);

	String keyAttributeName = getParameterAsString(PARAMETER_KEY_ATTRIBUTE);
	String valueAttributeName = getParameterAsString(PARAMETER_VALUE_ATTRIBUTE);

	Attribute keyAttribute = annotationData.getAttributes().get(keyAttributeName);
	Attribute valueAttribute = annotationData.getAttributes().get(valueAttributeName);

	// null checks, type checks on attributes
	if (keyAttribute == null) {
		throw new AttributeNotFoundError(this, PARAMETER_KEY_ATTRIBUTE, keyAttributeName);
	} else if (valueAttribute == null) {
		throw new AttributeNotFoundError(this, PARAMETER_VALUE_ATTRIBUTE, valueAttributeName);
	} else if (!keyAttribute.isNominal()) {
		throw new UserError(this, 103, "Data to Annotations", keyAttributeName);
	} else if (!valueAttribute.isNominal()) {
		throw new UserError(this, 103, "Data to Annotations", valueAttributeName);
	}

	// get index of action for duplicate annotations
	String duplicateActionString = getParameterAsString(PARAMETER_DUPLICATE_HANDLING);
	int duplicateAction = ERROR_ON_DUPLICATES;
	for (int i = 0; i < DUPLICATE_HANDLING_LIST.length; ++i) {
		if (DUPLICATE_HANDLING_LIST[i].equals(duplicateActionString)) {
			duplicateAction = i;
			break;
		}
	}

	// loop all examples and add key/value pairs as annotation
	Annotations annotations = object.getAnnotations();
	for (Example example : annotationData) {
		String key = example.getNominalValue(keyAttribute);
		String value = example.getNominalValue(valueAttribute);
		boolean missingValue = Double.isNaN(example.getValue(valueAttribute));

		if (annotations.containsKey(key)) {
			if (missingValue) {
				annotations.remove(key);
			} else {
				switch (duplicateAction) {
					case OVERWRITE_DUPLICATES:
						// overwrite annotations
						annotations.setAnnotation(key, value);
						break;
					case IGNORE_DUPLICATES:
						// do nothing
						break;
					case ERROR_ON_DUPLICATES:
						// throw user error
						throw new UserError(this, "annotate.duplicate_annotation", key);
				}
			}
		} else if (!missingValue) {
			// add annotation
			annotations.setAnnotation(key, value);
		}
	}

	annotationsOutputPort.deliver(annotationData);
	objectOutputPort.deliver(object);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:66,代码来源:DataToAnnotations.java


注:本文中的com.rapidminer.operator.IOObject.getAnnotations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。