"Getting Results from Exampleset in Java"

maxfaxmaxfax Member Posts: 17 Contributor II
edited June 2019 in 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.

IOContainer ioResult = rm5.run();

ExampleSet resultSet = (ExampleSet) ioResult.getElementAt(1);
I attached a picture of which values i would like to get in my Program.


Thank you very much for you Help !


  • Options
    aborgaborg Member Posts: 66 Contributor II
    This might help: https://github.com/aborg0/rapidminer-integration-knime/blob/master/com.mind_era.knime_rapidminer.knime.nodes.local/src/com/mind_era/knime_rapidminer/knime/nodes/RapidMinerNodeModel.java#L273
    Just in case it will move along here is a copy of it:
    			for (Example example : result) {
    final DataRow row = example.getDataRow();
    if (i > result.size()) {
    final Function<Attribute, DataCell> transformFunction = new Function<Attribute, DataCell>() {
    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,
    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,
    if (a.getValueType() == Ontology.TIME) {
    return new DateAndTimeCell((long) d, false, 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
    .getStringValue(), Iterables.toArray(
    Iterables.transform(attribs, transformFunction),
  • Options
    maxfaxmaxfax Member Posts: 17 Contributor II
    Thank you very much ! But is there really now easier way to read Data out of Examplesets ? I know that the values are going to be doubles and i also know the Names of the Attributes . But right know I dont really know how to declare the Attributes correctly,

    thank you very much
  • Options
    maxfaxmaxfax Member Posts: 17 Contributor II
    So Basically what i am trying to get is a working method so i can store the data from the data view in the rapidminer gui into an integer value or string value in my java programm.

    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 ! :)
  • Options
    StaryVenaStaryVena Member Posts: 126 Contributor II
    Hello maxfax,
    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:

    ExampleSet es = (ExampleSet) ioResult.getElementAt(1);
    Attributes ats = es.getAttributes();
    double[] dataRow = new double[ats.size()];
    for (Example example : es) {
    int i = 0;
    for (Attribute attribute : ats) {
    dataRow = example.getValue(attribute);
    //TODO operation with one dataRow = example
  • Options
    maxfaxmaxfax Member Posts: 17 Contributor II
    Thank you very much !!

    THis was exactly what I needed thx !! ;D
Sign In or Register to comment.