use of org.apache.jena.sparql.algebra.Table in project jena by apache.
the class NodeTransformOp method transform.
@Override
public Op transform(OpTable opTable) {
if (opTable.isJoinIdentity())
return opTable;
Table table = opTable.getTable();
if (table.isEmpty())
return opTable;
if (TableUnit.isTableUnit(table))
return opTable;
if (table.getVars().size() == 0)
return opTable;
Table table2 = NodeTransformLib.transform(table, transform);
return OpTable.create(table2);
}
use of org.apache.jena.sparql.algebra.Table in project jena by apache.
the class labelSearch method exec.
/* This be called once, with unevaluated arguments.
* To do a rewrite of part of a query, we must use the fundamental PropertyFunction
* interface to be called once with the input iterator.
* Must not return null nor throw an exception. Instead, return a QueryIterNullIterator
* indicating no matches.
*/
@Override
public QueryIterator exec(QueryIterator input, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
// No real need to check the pattern arguments because
// the replacement triple pattern and regex will cope
// but we illustrate testing here.
Node nodeVar = argSubject.getArg();
String pattern = NodeUtils.stringLiteral(argObject.getArg());
if (pattern == null) {
Log.warn(this, "Pattern must be a plain literal or xsd:string: " + argObject.getArg());
return QueryIterNullIterator.create(execCxt);
}
if (false)
// Old (ARQ 1) way - not recommended.
return buildSyntax(input, nodeVar, pattern, execCxt);
// Better
// Build a SPARQL algebra expression
// Hidden variable
Var var2 = createNewVar();
BasicPattern bp = new BasicPattern();
Triple t = new Triple(nodeVar, RDFS.label.asNode(), var2);
bp.add(t);
OpBGP op = new OpBGP(bp);
Expr regex = new E_Regex(new ExprVar(var2.getName()), pattern, "i");
Op filter = OpFilter.filter(regex, op);
// ---- Evaluation
if (true) {
// Use the reference query engine
// Create a table for the input stream (so it uses working memory at this point,
// which is why this is not the preferred way).
// Then join to expression for this stage.
Table table = TableFactory.create(input);
Op op2 = OpJoin.create(OpTable.create(table), filter);
return Algebra.exec(op2, execCxt.getDataset());
}
// Use the default, optimizing query engine.
return QC.execute(filter, input, execCxt);
}
Aggregations