use of org.knime.core.data.BooleanValue in project knime-core by knime.
the class ExpressionFactory method and.
/**
* {@inheritDoc}
*/
@Override
public Expression and(final List<Expression> boolExpressions) {
final boolean allIsConstant = checkBooleansAndConstant(boolExpressions);
return new Expression.Base(boolExpressions) {
/**
* {@inheritDoc}
*/
@Override
public DataType getOutputType() {
return BooleanCell.TYPE;
}
/**
* {@inheritDoc}
*/
@Override
public List<DataType> getInputArgs() {
return Collections.singletonList(BooleanCell.TYPE);
}
/**
* {@inheritDoc}
*/
@Override
public ExpressionValue evaluate(final DataRow row, final VariableProvider provider) {
DataCell ret = BooleanCell.TRUE;
Map<String, Map<String, String>> matchedObjects = new HashMap<String, Map<String, String>>();
for (Expression boolExpression : boolExpressions) {
ExpressionValue v = boolExpression.evaluate(row, provider);
DataCell cell = v.getValue();
assert !cell.isMissing();
if (cell instanceof BooleanValue) {
BooleanValue bool = (BooleanValue) cell;
if (bool.getBooleanValue()) {
matchedObjects = Util.mergeObjects(matchedObjects, v.getMatchedObjects());
} else {
return new ExpressionValue(BooleanCell.FALSE, EMPTY_MAP);
}
} else if (cell.isMissing()) {
ret = DataType.getMissingCell();
} else {
throw new IllegalStateException("Not boolean: " + v.getValue());
}
}
return new ExpressionValue(ret, matchedObjects);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isConstant() {
return allIsConstant;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "and(" + boolExpressions + ")";
}
/**
* {@inheritDoc}
*/
@Override
public ASTType getTreeType() {
return ASTType.And;
}
};
}
use of org.knime.core.data.BooleanValue in project knime-core by knime.
the class RuleEngineFilterNodeModel method execute.
/**
* The real worker.
* @param inData The input data as {@link RowInput}.
* @param outputs The output tables.
* @param rowCount The row count (if available, else {@code -1} is fine).
* @param exec The {@link ExecutionContext}.
* @throws ParseException Parsing of rules failed.
* @throws CanceledExecutionException Execution cancelled.
* @throws InterruptedException Streaming failed.
*/
private void execute(final RowInput inData, final RowOutput[] outputs, final long rowCount, final ExecutionContext exec) throws ParseException, CanceledExecutionException, InterruptedException {
final List<Rule> rules = parseRules(inData.getDataTableSpec(), RuleNodeSettings.RuleFilter);
final int matchIndex = m_includeOnMatch.getBooleanValue() ? 0 : 1;
final int otherIndex = 1 - matchIndex;
try {
final long[] rowIdx = new long[] { 0L };
final long rows = rowCount;
final VariableProvider provider = new VariableProvider() {
@Override
public Object readVariable(final String name, final Class<?> type) {
return RuleEngineFilterNodeModel.this.readVariable(name, type);
}
@Override
public long getRowCountLong() {
return rows;
}
@Deprecated
@Override
public int getRowCount() {
return KnowsRowCountTable.checkRowCount(rows);
}
@Override
@Deprecated
public int getRowIndex() {
return (int) rowIdx[0];
}
@Override
public long getRowIndexLong() {
return rowIdx[0];
}
};
DataRow row;
while ((row = inData.poll()) != null) {
rowIdx[0]++;
exec.setProgress(rowIdx[0] / (double) rows, () -> "Adding row " + rowIdx[0] + " of " + rows);
exec.checkCanceled();
boolean wasMatch = false;
for (Rule r : rules) {
if (r.getCondition().matches(row, provider).getOutcome() == MatchState.matchedAndStop) {
// r.getSideEffect().perform(row, provider);
DataValue value = r.getOutcome().getComputedResult(row, provider);
final int index;
if (value instanceof BooleanValue) {
final BooleanValue bv = (BooleanValue) value;
index = bv.getBooleanValue() ? matchIndex : otherIndex;
} else {
index = matchIndex;
}
if (index < outputs.length) {
outputs[index].push(row);
}
wasMatch = true;
break;
}
}
if (!wasMatch) {
if (otherIndex < outputs.length) {
outputs[otherIndex].push(row);
}
}
}
} finally {
outputs[0].close();
if (outputs.length > 1) {
outputs[1].close();
}
}
}
Aggregations