use of org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator in project knime-core by knime.
the class RuleSetToTable method execute.
/**
* Performs the conversion.
*
* @param exec An {@link ExecutionContext}.
* @param pmmlPo The input {@link PMMLPortObject}.
* @return The created {@link BufferedDataTable}.
* @throws CanceledExecutionException Execition was cancelled.
* @throws InvalidSettingsException No or more than one RuleSet model is in the PMML input.
*/
public BufferedDataTable execute(final ExecutionContext exec, final PMMLPortObject pmmlPo) throws CanceledExecutionException, InvalidSettingsException {
// TODO should the rule selection method be an output flow variable?
if (pmmlPo.getPMMLValue().getModels(PMMLModelType.RuleSetModel).size() != 1) {
throw new InvalidSettingsException("Only a single RuleSet model is supported.");
}
PMMLRuleTranslator ruleTranslator = new PMMLRuleTranslator();
pmmlPo.initializeModelTranslator(ruleTranslator);
List<Rule> rules = ruleTranslator.getRules();
final DataTableSpec confSpec = configure(pmmlPo.getSpec());
final List<String> scoreValues = new ArrayList<>();
final DataTableSpec properSpec = confSpec != null ? confSpec : properSpec(rules, scoreValues);
BufferedDataContainer container = exec.createDataContainer(properSpec);
List<DataColumnSpec> targetCols = pmmlPo.getSpec().getTargetCols();
DataType outcomeType = targetCols.get(0).getType();
long idx = 0L;
int rulesSize = rules.size();
Map<String, DataType> types = new LinkedHashMap<>();
for (DataColumnSpec col : pmmlPo.getSpec().getLearningCols()) {
types.put(col.getName(), col.getType());
}
for (Rule rule : rules) {
exec.checkCanceled();
exec.setProgress(1.0 * idx++ / rulesSize);
container.addRowToTable(new DefaultRow(RowKey.createRowKey(idx), createRow(rule, outcomeType, types, scoreValues)));
}
container.close();
return container.getTable();
}
use of org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator in project knime-core by knime.
the class RuleEngine2PortsNodeModel method setCondition.
/**
* Initializes the xml {@link SimpleRule} based on the {@code expression}. After this call, the predicate will be
* set.
*
* @param simpleRule An xml {@link SimpleRule}.
* @param expression A condition to set.
*/
private void setCondition(final SimpleRule simpleRule, final PMMLPredicate expression) {
PMMLRuleTranslator translator = new PMMLRuleTranslator();
translator.setPredicate(simpleRule, expression);
}
use of org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator in project knime-core by knime.
the class RulesToTableNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
PMMLPortObject ruleSetPo = (PMMLPortObject) inData[0];
PMMLRuleTranslator translator = new PMMLRuleTranslator();
BufferedDataTable table = new RuleSetToTable(m_settings).execute(exec, ruleSetPo);
ruleSetPo.initializeModelTranslator(translator);
List<RuleSelectionMethod> selectionMethodList = translator.getSelectionMethodList();
if (selectionMethodList.size() != 1 || (selectionMethodList.size() == 1 && !Objects.equals(selectionMethodList.get(0).getCriterion(), RuleSelectionMethod.Criterion.FIRST_HIT))) {
setWarningMessage("Only a single 'firstHit' rule selection method is supported properly, all others cannot be represented properly. Rule selection methods: " + selectionMethodList);
}
return new BufferedDataTable[] { table };
}
use of org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator in project knime-core by knime.
the class RuleEngine2PortsNodeModel method fillUsingDoc.
/**
* Fills the results obtained from {@code doc}.
*
* @param doc A {@link PMMLDocument}.
* @param ruleSetModel The {@link RuleSetModel}.
* @param pmml The {@link PMMLPortObject}.
*/
private void fillUsingDoc(final PMMLDocument doc, final RuleSetModel ruleSetModel, final PMMLPortObject pmml) {
PMMLRuleTranslator modelTranslator = new PMMLRuleTranslator(m_settings.isProvideStatistics());
PMMLMiningSchemaTranslator.writeMiningSchema(pmml.getSpec(), ruleSetModel);
PMMLDataDictionaryTranslator ddTranslator = new PMMLDataDictionaryTranslator();
ddTranslator.exportTo(doc, pmml.getSpec());
modelTranslator.initializeFrom(doc);
pmml.addModelTranslater(modelTranslator);
pmml.validate();
}
Aggregations