當前位置: 首頁>>代碼示例>>Java>>正文


Java SparseFormatDataRowReader類代碼示例

本文整理匯總了Java中com.rapidminer.example.table.SparseFormatDataRowReader的典型用法代碼示例。如果您正苦於以下問題:Java SparseFormatDataRowReader類的具體用法?Java SparseFormatDataRowReader怎麽用?Java SparseFormatDataRowReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SparseFormatDataRowReader類屬於com.rapidminer.example.table包,在下文中一共展示了SparseFormatDataRowReader類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toSparseString

import com.rapidminer.example.table.SparseFormatDataRowReader; //導入依賴的package包/類
/**
 * Returns regular and some special attributes (label, id, and example weight) in sparse format.
 * 
 * @param format
 *            one of the formats specified in {@link SparseFormatDataRowReader}
 */
public String toSparseString(int format, int fractionDigits, boolean quoteNominal) {
	StringBuffer str = new StringBuffer();
	// label
	Attribute labelAttribute = getAttributes().getSpecial(Attributes.LABEL_NAME);
	if ((format == SparseFormatDataRowReader.FORMAT_YX) && (labelAttribute != null)) {
		str.append(getValueAsString(labelAttribute, fractionDigits, quoteNominal) + " ");
	}

	// id
	Attribute idAttribute = getAttributes().getSpecial(Attributes.ID_NAME);
	if (idAttribute != null) {
		str.append("id:" + getValueAsString(idAttribute, fractionDigits, quoteNominal) + " ");
	}

	// weight
	Attribute weightAttribute = getAttributes().getSpecial(Attributes.WEIGHT_NAME);
	if (weightAttribute != null) {
		str.append("w:" + getValueAsString(weightAttribute, fractionDigits, quoteNominal) + " ");
	}

	// batch
	Attribute batchAttribute = getAttributes().getSpecial(Attributes.BATCH_NAME);
	if (batchAttribute != null) {
		str.append("b:" + getValueAsString(batchAttribute, fractionDigits, quoteNominal) + " ");
	}

	// attributes
	str.append(getAttributesAsSparseString(SEPARATOR, SPARSE_SEPARATOR, fractionDigits, quoteNominal) + " ");

	// label (format xy & prefix)
	if ((format == SparseFormatDataRowReader.FORMAT_PREFIX) && (labelAttribute != null)) {
		str.append("l:" + getValueAsString(labelAttribute, fractionDigits, quoteNominal));
	}
	if ((format == SparseFormatDataRowReader.FORMAT_XY) && (labelAttribute != null)) {
		str.append(getValueAsString(labelAttribute, fractionDigits, quoteNominal));
	}
	return str.toString();
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:45,代碼來源:Example.java

示例2: testFormatXY

import com.rapidminer.example.table.SparseFormatDataRowReader; //導入依賴的package包/類
@Test
public void testFormatXY() throws Exception {
	StringBuffer input = new StringBuffer("# comment" + Tools.getLineSeparator());
	for (int i = 0; i < ATTRIBUTE_STRINGS.length; i++) {
		input.append(ATTRIBUTE_STRINGS[i] + " " + LABEL[i] + Tools.getLineSeparator());
	}
	readerTest(SparseFormatDataRowReader.FORMAT_XY, new StringReader(input.toString()), null);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:9,代碼來源:SparseReaderTest.java

示例3: testFormatYX

import com.rapidminer.example.table.SparseFormatDataRowReader; //導入依賴的package包/類
@Test
public void testFormatYX() throws Exception {
	StringBuffer input = new StringBuffer("# comment" + Tools.getLineSeparator());
	for (int i = 0; i < ATTRIBUTE_STRINGS.length; i++) {
		input.append(LABEL[i] + " " + ATTRIBUTE_STRINGS[i] + Tools.getLineSeparator());
	}
	readerTest(SparseFormatDataRowReader.FORMAT_YX, new StringReader(input.toString()), null);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:9,代碼來源:SparseReaderTest.java

示例4: testFormatPrefix

import com.rapidminer.example.table.SparseFormatDataRowReader; //導入依賴的package包/類
@Test
public void testFormatPrefix() throws Exception {
	StringBuffer input = new StringBuffer("# comment" + Tools.getLineSeparator());
	for (int i = 0; i < ATTRIBUTE_STRINGS.length; i++) {
		input.append("l:" + LABEL[i] + " " + ATTRIBUTE_STRINGS[i] + Tools.getLineSeparator());
	}
	readerTest(SparseFormatDataRowReader.FORMAT_PREFIX, new StringReader(input.toString()), null);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:9,代碼來源:SparseReaderTest.java

示例5: testFormatSeparate

import com.rapidminer.example.table.SparseFormatDataRowReader; //導入依賴的package包/類
@Test
public void testFormatSeparate() throws Exception {
	StringBuffer input = new StringBuffer("# comment" + Tools.getLineSeparator());
	StringBuffer label = new StringBuffer();
	for (int i = 0; i < ATTRIBUTE_STRINGS.length; i++) {
		label.append(LABEL[i] + Tools.getLineSeparator());
		input.append(ATTRIBUTE_STRINGS[i] + Tools.getLineSeparator());
	}
	readerTest(SparseFormatDataRowReader.FORMAT_SEPARATE_FILE, new StringReader(input.toString()), new StringReader(label.toString()));
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:11,代碼來源:SparseReaderTest.java

示例6: toSparseString

import com.rapidminer.example.table.SparseFormatDataRowReader; //導入依賴的package包/類
/**
 * Returns regular and some special attributes (label, id, and example
 * weight) in sparse format.
 * 
 * @param format
 *            one of the formats specified in
 *            {@link SparseFormatDataRowReader}
 */
public String toSparseString(int format, int fractionDigits, boolean quoteNominal) {
	StringBuffer str = new StringBuffer();
	// label
	Attribute labelAttribute = getAttributes().getSpecial(Attributes.LABEL_NAME);
	if ((format == SparseFormatDataRowReader.FORMAT_YX) && (labelAttribute != null)) {
		str.append(getValueAsString(labelAttribute, fractionDigits, quoteNominal) + " ");
	}
	
	// id
	Attribute idAttribute = getAttributes().getSpecial(Attributes.ID_NAME);
	if (idAttribute != null) {
		str.append("id:" + getValueAsString(idAttribute, fractionDigits, quoteNominal) + " ");
	}
	
	// weight
	Attribute weightAttribute = getAttributes().getSpecial(Attributes.WEIGHT_NAME);
	if (weightAttribute != null) {
		str.append("w:" + getValueAsString(weightAttribute, fractionDigits, quoteNominal) + " ");
	}
	
	// batch
	Attribute batchAttribute = getAttributes().getSpecial(Attributes.BATCH_NAME);
	if (batchAttribute != null) {
		str.append("b:" + getValueAsString(batchAttribute, fractionDigits, quoteNominal) + " ");
	}
	
	// attributes
	str.append(getAttributesAsSparseString(SEPARATOR, SPARSE_SEPARATOR, fractionDigits, quoteNominal) + " ");
	
	// label (format xy & prefix)
	if ((format == SparseFormatDataRowReader.FORMAT_PREFIX) && (labelAttribute != null)) {
		str.append("l:" + getValueAsString(labelAttribute, fractionDigits, quoteNominal));
	}
	if ((format == SparseFormatDataRowReader.FORMAT_XY) && (labelAttribute != null)) {
		str.append(getValueAsString(labelAttribute, fractionDigits, quoteNominal));
	}
	return str.toString();
}
 
開發者ID:rapidminer,項目名稱:rapidminer-5,代碼行數:47,代碼來源:Example.java

示例7: readerTest

import com.rapidminer.example.table.SparseFormatDataRowReader; //導入依賴的package包/類
public void readerTest(int format, Reader input, Reader labelInput) throws Exception {
	AttributeSet attributeSet = new AttributeSet();
	Attribute att1 = ExampleTestTools.attributeDogCatMouse();
	Attribute att2 = ExampleTestTools.attributeReal(1);
	Attribute att3 = ExampleTestTools.attributeReal(2);
	Attribute att4 = ExampleTestTools.attributeReal(3);
	Attribute att5 = ExampleTestTools.attributeReal(4);
	Attribute att6 = ExampleTestTools.attributeYesNo();
		
	attributeSet.addAttribute(att1);
	attributeSet.addAttribute(att2);
	attributeSet.addAttribute(att3);
	attributeSet.addAttribute(att4);
	attributeSet.addAttribute(att5);
	attributeSet.setSpecialAttribute("label", att6);
	
	java.util.Map<String, String> prefixMap = new java.util.HashMap<String, String>();
	prefixMap.put("l", "label");
	SparseFormatDataRowReader reader = new SparseFormatDataRowReader(new DataRowFactory(DataRowFactory.TYPE_SPARSE_MAP, '.'), 
			format, prefixMap, attributeSet, input, labelInput, -1, false, '"');
	MemoryExampleTable table = new MemoryExampleTable(attributeSet.getAllAttributes());
	table.readExamples(reader);
	ExampleSet exampleSet = table.createExampleSet(attributeSet);
	Iterator<Example> r = exampleSet.iterator();
	Example e = r.next();
	assertEquals("example 1, column 1", "dog", e.getValueAsString(att1));
	assertEquals("example 1, column 2", 8.0, e.getValue(att2), 0.00000001);
	assertEquals("example 1, column 3", 0.0, e.getValue(att3), 0.00000001);
	assertEquals("example 1, column 4", 0.0, e.getValue(att4), 0.00000001);
	assertEquals("example 1, column 5", 3.0, e.getValue(att5), 0.00000001);
	assertEquals("example 1, label", "yes", e.getValueAsString(att6));

	e = r.next();
	assertEquals("example 2, column 1", "cat", e.getValueAsString(att1));
	assertEquals("example 2, column 2", 0.0, e.getValue(att2), 0.00000001);
	assertEquals("example 2, column 3", 2.5, e.getValue(att3), 0.00000001);
	assertEquals("example 2, column 4", 0.15, e.getValue(att4), 0.00000001);
	assertEquals("example 2, column 5", 0.0, e.getValue(att5), 0.00000001);
	assertEquals("example 2, label", "no", e.getValueAsString(att6));

	e = r.next();
	assertEquals("example 3, column 1", "dog", e.getValueAsString(att1));
	assertEquals("example 3, column 2", 0.0, e.getValue(att2), 0.00000001);
	assertEquals("example 3, column 3", 0.0, e.getValue(att3), 0.00000001);
	assertEquals("example 3, column 4", 0.0, e.getValue(att4), 0.00000001);
	assertEquals("example 3, column 5", 1.0, e.getValue(att5), 0.00000001);
	assertEquals("example 3, label", "no", e.getValueAsString(att6));

	e = r.next();
	assertEquals("example 4, column 1", "dog", e.getValueAsString(att1));
	assertEquals("example 4, column 2", 0.0, e.getValue(att2), 0.00000001);
	assertEquals("example 4, column 3", 0.0, e.getValue(att3), 0.00000001);
	assertEquals("example 4, column 4", 73, e.getValue(att4), 0.00000001);
	assertEquals("example 4, column 5", 0.0, e.getValue(att5), 0.00000001);
	assertEquals("example 4, label", "yes", e.getValueAsString(att6));
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:57,代碼來源:SparseReaderTest.java

示例8: readerTest

import com.rapidminer.example.table.SparseFormatDataRowReader; //導入依賴的package包/類
public void readerTest(int format, Reader input, Reader labelInput) throws Exception {
	AttributeSet attributeSet = new AttributeSet();
	Attribute att1 = ExampleTestTools.attributeDogCatMouse();
	Attribute att2 = ExampleTestTools.attributeReal(1);
	Attribute att3 = ExampleTestTools.attributeReal(2);
	Attribute att4 = ExampleTestTools.attributeReal(3);
	Attribute att5 = ExampleTestTools.attributeReal(4);
	Attribute att6 = ExampleTestTools.attributeYesNo();

	attributeSet.addAttribute(att1);
	attributeSet.addAttribute(att2);
	attributeSet.addAttribute(att3);
	attributeSet.addAttribute(att4);
	attributeSet.addAttribute(att5);
	attributeSet.setSpecialAttribute("label", att6);

	java.util.Map<String, String> prefixMap = new java.util.HashMap<String, String>();
	prefixMap.put("l", "label");
	SparseFormatDataRowReader reader = new SparseFormatDataRowReader(
			new DataRowFactory(DataRowFactory.TYPE_SPARSE_MAP, '.'), format, prefixMap, attributeSet, input, labelInput,
			-1, false, '"');
	ExampleSet exampleSet = ExampleSets.from(attributeSet.getAllAttributes()).withDataRowReader(reader)
			.withRole(att6, Attributes.LABEL_NAME).build();
	Iterator<Example> r = exampleSet.iterator();
	Example e = r.next();
	assertEquals("example 1, column 1", "dog", e.getValueAsString(att1));
	assertEquals("example 1, column 2", 8.0, e.getValue(att2), 0.00000001);
	assertEquals("example 1, column 3", 0.0, e.getValue(att3), 0.00000001);
	assertEquals("example 1, column 4", 0.0, e.getValue(att4), 0.00000001);
	assertEquals("example 1, column 5", 3.0, e.getValue(att5), 0.00000001);
	assertEquals("example 1, label", "yes", e.getValueAsString(att6));

	e = r.next();
	assertEquals("example 2, column 1", "cat", e.getValueAsString(att1));
	assertEquals("example 2, column 2", 0.0, e.getValue(att2), 0.00000001);
	assertEquals("example 2, column 3", 2.5, e.getValue(att3), 0.00000001);
	assertEquals("example 2, column 4", 0.15, e.getValue(att4), 0.00000001);
	assertEquals("example 2, column 5", 0.0, e.getValue(att5), 0.00000001);
	assertEquals("example 2, label", "no", e.getValueAsString(att6));

	e = r.next();
	assertEquals("example 3, column 1", "dog", e.getValueAsString(att1));
	assertEquals("example 3, column 2", 0.0, e.getValue(att2), 0.00000001);
	assertEquals("example 3, column 3", 0.0, e.getValue(att3), 0.00000001);
	assertEquals("example 3, column 4", 0.0, e.getValue(att4), 0.00000001);
	assertEquals("example 3, column 5", 1.0, e.getValue(att5), 0.00000001);
	assertEquals("example 3, label", "no", e.getValueAsString(att6));

	e = r.next();
	assertEquals("example 4, column 1", "dog", e.getValueAsString(att1));
	assertEquals("example 4, column 2", 0.0, e.getValue(att2), 0.00000001);
	assertEquals("example 4, column 3", 0.0, e.getValue(att3), 0.00000001);
	assertEquals("example 4, column 4", 73, e.getValue(att4), 0.00000001);
	assertEquals("example 4, column 5", 0.0, e.getValue(att5), 0.00000001);
	assertEquals("example 4, label", "yes", e.getValueAsString(att6));
}
 
開發者ID:rapidminer,項目名稱:rapidminer-studio,代碼行數:57,代碼來源:SparseReaderTest.java


注:本文中的com.rapidminer.example.table.SparseFormatDataRowReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。