Search in sources :

Example 1 with OutputCell

use of org.jpmml.model.inlinetable.OutputCell in project drools by kiegroup.

the class ModelUtilsTest method getRowDataMap.

@Test
public void getRowDataMap() {
    Row source = getRandomRowWithCells();
    Map<String, Object> retrieved = ModelUtils.getRowDataMap(source);
    InputCell inputCell = source.getContent().stream().filter(InputCell.class::isInstance).map(InputCell.class::cast).findFirst().get();
    OutputCell outputCell = source.getContent().stream().filter(OutputCell.class::isInstance).map(OutputCell.class::cast).findFirst().get();
    assertEquals(2, retrieved.size());
    String expected = getPrefixedName(inputCell.getName());
    assertTrue(retrieved.containsKey(expected));
    assertEquals(inputCell.getValue(), retrieved.get(expected));
    expected = getPrefixedName(outputCell.getName());
    assertTrue(retrieved.containsKey(expected));
    assertEquals(outputCell.getValue(), retrieved.get(expected));
}
Also used : InputCell(org.jpmml.model.inlinetable.InputCell) Row(org.dmg.pmml.Row) PMMLModelTestUtils.getRandomRow(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomRow) OutputCell(org.jpmml.model.inlinetable.OutputCell) Test(org.junit.Test)

Example 2 with OutputCell

use of org.jpmml.model.inlinetable.OutputCell in project drools by kiegroup.

the class ModelUtils method getRowDataMap.

public static Map<String, Object> getRowDataMap(Row source) {
    Map<String, Object> toReturn = new HashMap<>();
    List<Element> elements = source.getContent().stream().filter(Element.class::isInstance).map(Element.class::cast).collect(Collectors.toList());
    if (!elements.isEmpty()) {
        elements.forEach(el -> populateWithElement(toReturn, el));
    } else {
        InputCell inputCell = source.getContent().stream().filter(InputCell.class::isInstance).map(InputCell.class::cast).findFirst().orElse(null);
        OutputCell outputCell = source.getContent().stream().filter(OutputCell.class::isInstance).map(OutputCell.class::cast).findFirst().orElse(null);
        populateWithCells(toReturn, inputCell, outputCell);
    }
    return toReturn;
}
Also used : InputCell(org.jpmml.model.inlinetable.InputCell) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Element(org.w3c.dom.Element) OutputCell(org.jpmml.model.inlinetable.OutputCell)

Example 3 with OutputCell

use of org.jpmml.model.inlinetable.OutputCell in project drools by kiegroup.

the class PMMLModelTestUtils method getRandomRowWithCells.

public static Row getRandomRowWithCells() {
    Row toReturn = new Row();
    toReturn.addContent(new InputCell(RandomStringUtils.random(6, true, false)));
    toReturn.addContent(new OutputCell(RandomStringUtils.random(6, true, false)));
    return toReturn;
}
Also used : InputCell(org.jpmml.model.inlinetable.InputCell) Row(org.dmg.pmml.Row) OutputCell(org.jpmml.model.inlinetable.OutputCell)

Aggregations

InputCell (org.jpmml.model.inlinetable.InputCell)3 OutputCell (org.jpmml.model.inlinetable.OutputCell)3 Row (org.dmg.pmml.Row)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.Test)1 PMMLModelTestUtils.getRandomRow (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomRow)1 Element (org.w3c.dom.Element)1