use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class RuleEngineNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec spec = (DataTableSpec) inSpecs[0];
final List<Rule> parsedRules;
try {
parsedRules = parseRules(spec, RuleNodeSettings.RuleEngine);
} catch (final ParseException e) {
throw new InvalidSettingsException(e);
}
return new StreamableOperator() {
private SimpleStreamableOperatorInternals m_internals;
/**
* {@inheritDoc}
*/
@Override
public void loadInternals(final StreamableOperatorInternals internals) {
m_internals = (SimpleStreamableOperatorInternals) internals;
}
/**
* {@inheritDoc}
*/
@Override
public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
// count number of rows
long count = 0;
RowInput rowInput = (RowInput) inputs[0];
while (rowInput.poll() != null) {
count++;
}
m_internals.getConfig().addLong(CFG_ROW_COUNT, count);
}
/**
* {@inheritDoc}
*/
@Override
public StreamableOperatorInternals saveInternals() {
return m_internals;
}
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
long rowCount = -1L;
if (m_internals.getConfig().containsKey(CFG_ROW_COUNT)) {
rowCount = m_internals.getConfig().getLong(CFG_ROW_COUNT);
}
createRearranger(((RowInput) inputs[0]).getDataTableSpec(), parsedRules, rowCount, false).createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
}
};
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class StreamingUtil method checkRules.
private static boolean checkRules(final RuleFactory ruleFactory, final Iterable<String> rules, final Predicate<Rule> ruleIsGood) {
final RuleFactory proper = ruleFactory.cloned();
proper.disableColumnChecks();
proper.disableFlowVariableChecks();
final DataTableSpec empty = new DataTableSpec();
return StreamSupport.stream(rules.spliterator(), true).anyMatch(ruleAsString -> {
try {
return !ruleIsGood.test(proper.parse(ruleAsString, empty, Collections.emptyMap()));
} catch (ParseException e) {
return true;
}
});
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class PMMLRuleEditorNodeModel method computeFinalOutputSpecs.
/**
* {@inheritDoc}
*/
@Override
public PortObjectSpec[] computeFinalOutputSpecs(final StreamableOperatorInternals internals, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final PortObjectSpec[] computeFinalOutputSpecs = super.computeFinalOutputSpecs(internals, inSpecs);
// TODO should this be done some place else (finish)?
StreamInternalForPMMLPortObject poInternals = (StreamInternalForPMMLPortObject) internals;
try {
DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
RearrangerAndPMMLModel m = createRearrangerAndPMMLModel(tableSpec);
poInternals.setObject(m.getPMMLPortObject());
} catch (ParseException e) {
throw new InvalidSettingsException(e);
}
return computeFinalOutputSpecs;
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class PMMLRuleEditorNodeModel method computeSpecs.
/**
* Computes the specs after applying the derived fields.
*
* @param specs The input table and the possible preprocessing port.
* @return The computed (original+preproc) input table's specification.
*/
@Deprecated
static DataTableSpec computeSpecs(final PortObjectSpec[] specs) {
final DataTableSpec tableSpec = (DataTableSpec) specs[0];
if (specs[1] == null) {
return tableSpec;
}
PMMLPortObjectSpec portObjectSpec = (PMMLPortObjectSpec) specs[1];
List<DataColumnSpec> preprocessingCols = portObjectSpec.getPreprocessingCols();
DataTableSpecCreator creator = new DataTableSpecCreator(tableSpec);
for (DataColumnSpec spec : preprocessingCols) {
creator.addColumns(spec);
}
return creator.createSpec();
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class PMMLRuleEditorNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
return new StreamableOperator() {
private ColumnRearranger m_rearrangerx;
private PMMLPortObject m_portObject;
{
try {
final PMMLDocument doc = PMMLDocument.Factory.newInstance();
final PMML pmml = doc.addNewPMML();
RuleSetModel ruleSetModel = pmml.addNewRuleSetModel();
RuleSet ruleSet = ruleSetModel.addNewRuleSet();
PMMLRuleParser parser = new PMMLRuleParser(tableSpec, getAvailableInputFlowVariables());
m_rearrangerx = createRearranger(tableSpec, ruleSet, parser);
} catch (ParseException e) {
throw new InvalidSettingsException(e);
}
}
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
m_rearrangerx.createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
}
/**
* {@inheritDoc}
*/
@Override
public void loadInternals(final StreamableOperatorInternals internals) {
super.loadInternals(internals);
m_portObject = ((StreamInternalForPMMLPortObject) internals).getObject();
}
/**
* {@inheritDoc}
*/
@Override
public StreamableOperatorInternals saveInternals() {
return createInitialStreamableOperatorInternals().setObject(m_portObject);
}
};
}
Aggregations