本文整理汇总了Java中org.apache.jena.sparql.engine.QueryIterator类的典型用法代码示例。如果您正苦于以下问题:Java QueryIterator类的具体用法?Java QueryIterator怎么用?Java QueryIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryIterator类属于org.apache.jena.sparql.engine包,在下文中一共展示了QueryIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
@Override
public QueryIterator exec(Binding binding, PropFuncArg argSubject,
Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
argSubject = Substitute.substitute(argSubject, binding);
argObject = Substitute.substitute(argObject, binding);
if(!argObject.getArg().isVariable()) {
throw new ExprEvalException("Right hand side of tosh:targetContains must be a variable");
}
Node targetNode = argSubject.getArgList().get(0);
Node shapesGraphNode = argSubject.getArgList().get(1);
Model currentModel = ModelFactory.createModelForGraph(execCxt.getActiveGraph());
Dataset dataset = new DatasetWithDifferentDefaultModel(currentModel, DatasetImpl.wrap(execCxt.getDataset()));
Model model = dataset.getNamedModel(shapesGraphNode.getURI());
Resource target = (Resource) model.asRDFNode(targetNode);
Set<Node> focusNodes = new HashSet<Node>();
SHACLUtil.addNodesInTarget(target, dataset, focusNodes);
return new QueryIterExtendByVar(binding, (Var) argObject.getArg(), focusNodes.iterator(), execCxt);
}
示例2: execEvaluated
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
@Override
public QueryIterator execEvaluated(Binding binding, Node subject, Node predicate, Node object, ExecutionContext execCxt) {
Table table = getTable(predicate) ;
if ( table == null ) {
Log.warn(this, "No table for "+SSE.str(predicate));
return IterLib.noResults(execCxt) ;
}
if ( subject.isVariable() ) {
if ( object.isVariable() )
return execVarVar(binding, table, subject, object, execCxt) ;
else
return execVarTerm(binding, table, subject, object, execCxt) ;
} else {
if ( object.isVariable() )
return execTermVar(binding, table, subject, object, execCxt) ;
else
return execTermTerm(binding, table, subject, object, execCxt) ;
}
}
示例3: execute
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
@Override
protected QueryIterator execute(OpFilter opFilter, QueryIterator input)
{
if ( !isForLDF)
return super.execute(opFilter, input) ;
// If the filter does not apply to the input??
// Where does ARQ catch this?
// (filter (bgp ...))
if ( OpBGP.isBGP(opFilter.getSubOp()) )
{
// Still may be a LDF graph in a non-LDF dataset (e.g. a named model)
LinkedDataFragmentGraph graph = (LinkedDataFragmentGraph)execCxt.getActiveGraph() ;
OpBGP opBGP = (OpBGP)opFilter.getSubOp() ;
return executeBGP(graph, opBGP, input, opFilter.getExprs(), execCxt) ;
}
// (filter (anything else))
return super.execute(opFilter, input) ;
}
示例4: plainExecute
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
/** Execute without modification of the op - does <b>not</b> apply special graph name translations */
private static QueryIterator plainExecute(Op op, QueryIterator input, ExecutionContext execCxt)
{
// -- Execute
// Switch to a non-reordering executor
// The Op may be a sequence due to TransformFilterPlacement
// so we need to do a full execution step, not go straight to the SolverLib.
ExecutionContext ec2 = new ExecutionContext(execCxt) ;
ec2.setExecutor(plainFactory) ;
// Solve without going through this executor again.
// There would be issues of nested patterns but this is only a
// (filter (bgp...)) or (filter (quadpattern ...)) or sequences of these.
// so there are no nested patterns to reorder.
return QC.execute(op, input, ec2) ;
}
示例5: buildSyntax
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
private QueryIterator buildSyntax(QueryIterator input, Node nodeVar, String pattern, ExecutionContext execCxt)
{
Var var2 = createNewVar() ;
// Triple patterns for ?x rdfs:label ?hiddenVar
ElementTriplesBlock elementBGP = new ElementTriplesBlock();
Triple t = new Triple(nodeVar, RDFS.label.asNode(), var2) ;
elementBGP.addTriple(t) ;
// Regular expression for regex(?hiddenVar, "pattern", "i")
Expr regex = new E_Regex(new ExprVar(var2.getName()), pattern, "i") ;
ElementGroup elementGroup = new ElementGroup() ;
elementGroup.addElement(elementBGP) ;
elementGroup.addElement(new ElementFilter(regex)) ;
// Compile it.
// The better design is to build the Op structure programmatically,
Op op = Algebra.compile(elementGroup) ;
op = Algebra.optimize(op, execCxt.getContext()) ;
return QC.execute(op, input, execCxt) ;
}
示例6: execFixedSubject
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
private QueryIterator execFixedSubject(Node nodeURI, Node nodeLocalname, Binding binding, ExecutionContext execCxt)
{
if ( ! nodeURI.isURI() )
// Subject bound but not a URI
return QueryIterNullIterator.create(execCxt) ;
// Subject is bound and a URI - get the localname as a Node
Node localname = NodeFactory.createLiteral(nodeURI.getLocalName()) ;
// Object - unbound variable or a value?
if ( ! nodeLocalname.isVariable() )
{
// Object bound or a query constant. Is it the same as the calculated value?
if ( nodeLocalname.equals(localname) )
// Same
return QueryIterSingleton.create(binding, execCxt) ;
// No - different - no match.
return QueryIterNullIterator.create(execCxt) ;
}
// Object unbound variable - assign the localname to it.
return QueryIterSingleton.create(binding, Var.alloc(nodeLocalname), localname, execCxt) ;
}
示例7: execAllNodes
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
private QueryIterator execAllNodes(Var subjVar, Node nodeLocalname, Binding input, ExecutionContext execCxt)
{
if ( ! nodeLocalname.isVariable() )
{
if ( ! nodeLocalname.isLiteral() )
// Not a variable, not a literal=> can't match
return QueryIterNullIterator.create(execCxt) ;
if( ! NodeUtils.isSimpleString(nodeLocalname) )
return QueryIterNullIterator.create(execCxt) ;
}
//Set bindings = new HashSet() ; // Use a Set if you want unique results.
List<Binding> bindings = new ArrayList<Binding>() ; // Use a list if you want counting results.
Graph graph = execCxt.getActiveGraph() ;
ExtendedIterator<Triple>iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ;
for ( ; iter.hasNext() ; )
{
Triple t = iter.next() ;
slot(bindings, input, t.getSubject(), subjVar, nodeLocalname) ;
slot(bindings, input, t.getPredicate(), subjVar, nodeLocalname) ;
slot(bindings, input, t.getObject(), subjVar, nodeLocalname) ;
}
return new QueryIterPlainWrapper(bindings.iterator(), execCxt) ;
}
示例8: main
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
public static void main(String []args)
{
String s = "SELECT DISTINCT ?s { ?s ?p ?o }";
// Parse
Query query = QueryFactory.create(s) ;
System.out.println(query) ;
// Generate algebra
Op op = Algebra.compile(query) ;
op = Algebra.optimize(op) ;
System.out.println(op) ;
// Execute it.
QueryIterator qIter = Algebra.exec(op, ExQuerySelect1.createModel()) ;
// Results
for ( ; qIter.hasNext() ; )
{
Binding b = qIter.nextBinding() ;
System.out.println(b) ;
}
qIter.close() ;
}
示例9: execute
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
@Override
public QueryIterator execute(BasicPattern pattern,
QueryIterator input,
ExecutionContext execCxt)
{
// Just want to pick out some BGPs (e.g. on a particualr graph)
// Test :: execCxt.getActiveGraph()
if ( ! ( execCxt.getActiveGraph() instanceof GraphBase ) )
// Example: pass on up to the original StageGenerator if
// not based on GraphBase (which most Graph implementations are).
return other.execute(pattern, input, execCxt) ;
System.err.println("MyStageGenerator.compile:: triple patterns = "+pattern.size()) ;
// Stream the triple matches together, one triple matcher at a time.
QueryIterator qIter = input ;
for (Triple triple : pattern.getList())
qIter = new QueryIterTriplePattern(qIter, triple, execCxt) ;
return qIter ;
}
示例10: testMultipleParallelIterators
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
@Test
public void testMultipleParallelIterators() throws IOException {
CSVOptions options = new CSVOptions();
options.setColumnNamesInFirstRow(false);
CSVTable table = new CSVTable(InputStreamSource.fromString("Alice,Smith\nBob,Cook"), options);
List<Var> vars = vars("a", "b", "ROWNUM");
Binding row1 = binding(vars, "\"Alice\"", "\"Smith\"", "1");
Binding row2 = binding(vars, "\"Bob\"", "\"Cook\"", "2");
QueryIterator it1 = table.iterator(null);
assertEquals(row1, it1.next());
QueryIterator it2 = table.iterator(null);
QueryIterator it3 = table.iterator(null);
assertEquals(row1, it2.next());
assertEquals(row2, it1.next());
it2.close();
assertEquals(row1, it3.next());
assertEquals(row2, it3.next());
}
示例11: eval1
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
/** One round of rule evaluation */
private static void eval1(Graph source, StreamTriple out, Rule rule) {
BasicPattern pattern = BasicPattern.wrap(rule.getBody()) ;
ExecutionContext execContext = new ExecutionContext(ARQ.getContext(), source, null, null) ;
// Create a chain of triple iterators.
QueryIterator iter = match(source, pattern) ;
iter.forEachRemaining(b->{
Triple t = Substitute.substitute(rule.getHead(), b) ;
if ( t.isConcrete() && ! source.contains(t) )
out.triple(t);
}) ;
}
示例12: match
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
/** Evaluate a BGP : encapsulate for a better/different version */
private static QueryIterator match(Graph source, BasicPattern pattern) {
ExecutionContext execContext = new ExecutionContext(ARQ.getContext(), source, null, null) ;
// Create a chain of triple iterators.
QueryIterator chain = QueryIterSingleton.create(BindingFactory.root(), execContext) ;
for (Triple triple : pattern)
chain = new QueryIterTriplePattern(chain, triple, execContext) ;
return chain ;
}
示例13: executeBGP
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
/** Execute a BGP (and filters) on a LDF graph, which may be in default storage or it may be a named graph */
private static QueryIterator executeBGP(LinkedDataFragmentGraph graph, OpBGP opBGP, QueryIterator input, ExprList exprs,
ExecutionContext execCxt)
{
// Execute a BGP on the real default graph
return optimizeExecuteTriples(graph, input, opBGP.getPattern(), exprs, execCxt) ;
}
示例14: execEvaluated
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
@Override
public QueryIterator execEvaluated(Binding binding, Node nodeURI, Node predicate, Node nodeLocalname, ExecutionContext execCxt)
{
if ( ! nodeURI.isVariable() )
return execFixedSubject(nodeURI, nodeLocalname, binding, execCxt) ;
else
return execAllNodes(Var.alloc(nodeURI), nodeLocalname, binding, execCxt) ;
}
示例15: eval
import org.apache.jena.sparql.engine.QueryIterator; //导入依赖的package包/类
@Override
public QueryIterator eval(Op op, DatasetGraph dsg, Binding initial, Context context)
{
// Extension point: access possible to all the parameters for execution.
// Be careful to deal with initial bindings.
Transform transform = new MyTransform() ;
op = Transformer.transform(transform, op) ;
return super.eval(op, dsg, initial, context) ;
}