[SOLVED] build an example set object in JAVA and pass it to operator

MaGe
MaGe New Altair Community Member
edited November 5 in Community Q&A
Hi folks,

I've build up a decision tree model and saved it. Now, I want to use this model within my JAVA code. I use another process for this, where I load the model again, and where I want to pass unlabeled data to it. The thing is, that the unlabeled data is generated within my JAVA code, there is no existing file or database or whatever where the unlabeled data is read from.

In short, the tree-model shall classify a String, that is going to be passed to it. My question is now, how can i pass any String to an Operator input?
Will it have to be an IOObject (have not seen how to transform a String to it,yet..)? Or am I wrong with my plans some steps before already?

I am really thankful for every help from you

Answers

  • Skirzynski
    Skirzynski New Altair Community Member
    How to create an ExampleSet:

    // create a table
    MemoryExampleTable table = new MemoryExampleTable();

    // create and add attributes
    nominalAttr = AttributeFactory.createAttribute("att1", Ontology.NOMINAL);
    integerAttr = AttributeFactory.createAttribute("att2", Ontology.INTEGER);
    ...
    table.addAttribute(nominalAttr);
    table.addAttribute(integerAttr);
    ...

    // create a data row
    DataRow row = new DoubleSparseArrayDataRow();

    // For nominal attributes use the mapping class to insert a value "TEST"
    row.set(nominalAttr, nominalAttr.getMapping().mapString("TEST"));
    // For numerical nothing special to do
    row.set(integerAttr, 1);

    // add the row to the table
    table.addDataRow(row);

    // create an ExampleSet from the underlying table
    ExampleSet exampleSet = table.createExampleSet();
    I haven't tested this code, but this should be the way to go. After this code you should have an ExampleSet with two regular attributes and one example with the values 1 for the integer attribute and "TEST" for the nominal attribute.
  • MaGe
    MaGe New Altair Community Member
    Hi Marcin,

    thank you very much for your help. This worked perfect for my case!

    kind regards,
    Markus