use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class OpTriple method equivalent.
public boolean equivalent(OpBGP opBGP) {
BasicPattern bgp = opBGP.getPattern();
if (bgp.size() != 1)
return false;
Triple t = bgp.get(0);
return triple.equals(t);
}
use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class TestFmtUtils method testFormatBGP_1.
@Test
public void testFormatBGP_1() {
IndentedLineBuffer b = new IndentedLineBuffer();
BasicPattern bgp = SSE.parseBGP("(prefix ((zz: <" + aUri + ">)) (bgp (zz:s zz:p zz:o)))");
FmtUtils.formatPattern(b, bgp, getContext());
assertEquals("zz:s zz:p zz:o .", b.toString());
}
use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class TestFmtUtils method testFormatBGP_2.
@Test
public void testFormatBGP_2() {
IndentedLineBuffer b = new IndentedLineBuffer();
BasicPattern bgp = SSE.parseBGP("(prefix ((zz: <" + aUri + ">)) (bgp (zz:s zz:p zz:o) (zz:s zz:p 123) ))");
FmtUtils.formatPattern(b, bgp, getContext());
assertEquals("zz:s zz:p zz:o .\nzz:s zz:p 123 .", b.toString());
}
use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class TestFmtUtils method formatPattern_2_triples.
@Test
public void formatPattern_2_triples() {
BasicPattern basicPattern = new BasicPattern();
basicPattern.add(getTriple());
basicPattern.add(getTriple2());
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (IndentedWriter iw = new IndentedWriter(os)) {
SerializationContext sc = new SerializationContext();
FmtUtils.formatPattern(iw, basicPattern, sc);
}
assertEquals("<n1> <n2> \"l3\" .\n" + "<nb1> <nb2> \"lb3\" .", new String(os.toByteArray()));
}
use of org.apache.jena.sparql.core.BasicPattern 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