The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
"Getting Results from Exampleset in Java"
Hi,
I created a Process which calculates the Crossdistance between 1 single document and an Excelfile. The Process works fine and is properly executed in my Javaprogramm. Now i would like to get the Results or the Values of the 5 closest Documents to my Document out of the Exampleset. I understood that by the following code I can get the Examplesetresults. But how do i get the Values.

Thank you very much for you Help !
I created a Process which calculates the Crossdistance between 1 single document and an Excelfile. The Process works fine and is properly executed in my Javaprogramm. Now i would like to get the Results or the Values of the 5 closest Documents to my Document out of the Exampleset. I understood that by the following code I can get the Examplesetresults. But how do i get the Values.
I attached a picture of which values i would like to get in my Program.
IOContainer ioResult = rm5.run();
ExampleSet resultSet = (ExampleSet) ioResult.getElementAt(1);
Thank you very much for you Help !
0
Contributor II
Answers
Just in case it will move along here is a copy of it:
for (Example example : result) {
final DataRow row = example.getDataRow();
++i;
if (i > result.size()) {
break;
}
final Function<Attribute, DataCell> transformFunction = new Function<Attribute, DataCell>() {
@Override
public DataCell apply(final Attribute a) {
final double d = row.get(a);
if (a.isNominal()) {
return Double.isNaN(d) ? DataType.getMissingCell()
: new StringCell(a.getMapping().mapIndex(
(int) d));
}
if (a.getValueType() == Ontology.INTEGER) {
return Double.isNaN(d) ? DataType.getMissingCell()
: new IntCell((int) d);
}
if (a.getValueType() == Ontology.DATE) {
return new DateAndTimeCell((long) d, true, false,
false);
}
if (a.getValueType() == Ontology.DATE_TIME) {
final long utc = (long) d;
final boolean hasDate = utc >= 24L * 3600 * 1000
|| utc < 0;
return new DateAndTimeCell(utc, hasDate, !hasDate,
!hasDate);
}
if (a.getValueType() == Ontology.TIME) {
return new DateAndTimeCell((long) d, false, true,
true);
}
if (a.isNumerical()) {
return new DoubleCell(d);
}
return DataType.getMissingCell();
}
};
dataContainer.addRowToTable(new DefaultRow(attribsEntry
.getValue() == null ? String.valueOf(i)
: ((org.knime.core.data.StringValue) transformFunction
.apply(attribsEntry.getValue()))
.getStringValue(), Iterables.toArray(
Iterables.transform(attribs, transformFunction),
DataCell.class)));
}
thank you very much
I am sure there must be an easy way to do it since its an common idea to further use the results calculated with rapidminer.
Thank you very much for your help !
you can sort ExampleSet by operator "Sort" and that select only the first five by operator "Filter Example Range".
You can get values in java this way: Best,
Václav
THis was exactly what I needed thx !! ;D