org.apache.jena.sparql.algebra.op.OpBGP Java Examples

The following examples show how to use org.apache.jena.sparql.algebra.op.OpBGP. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WhereTraversalBuilder.java    From sparql-gremlin with Apache License 2.0 5 votes vote down vote up
public static GraphTraversal<?, ?> transform(final E_Exists expression) {
    final OpBGP opBGP = (OpBGP) expression.getGraphPattern();
    final List<Triple> triples = opBGP.getPattern().getList();
    if (triples.size() != 1) throw new IllegalStateException("Unhandled EXISTS pattern");
    final GraphTraversal<?, ?> traversal = TraversalBuilder.transform(triples.get(0));
    final Step endStep = traversal.asAdmin().getEndStep();
    final String label = (String) endStep.getLabels().iterator().next();
    endStep.removeLabel(label);
    return traversal;
}
 
Example #2
Source File: WhereTraversalBuilder.java    From sparql-gremlin with Apache License 2.0 5 votes vote down vote up
public static GraphTraversal<?, ?> transform(final E_NotExists expression) {
    final OpBGP opBGP = (OpBGP) expression.getGraphPattern();
    final List<Triple> triples = opBGP.getPattern().getList();
    if (triples.size() != 1) throw new IllegalStateException("Unhandled NOT EXISTS pattern");
    final GraphTraversal<?, ?> traversal = TraversalBuilder.transform(triples.get(0));
    final Step endStep = traversal.asAdmin().getEndStep();
    final String label = (String) endStep.getLabels().iterator().next();
    endStep.removeLabel(label);
    return __.not(traversal);
}
 
Example #3
Source File: SparqlToGremlinCompiler.java    From sparql-gremlin with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(final OpBGP opBGP) {
    final List<Triple> triples = opBGP.getPattern().getList();
    final Traversal[] matchTraversals = new Traversal[triples.size()];
    int i = 0;
    for (final Triple triple : triples) {
        matchTraversals[i++] = TraversalBuilder.transform(triple);
    }
    traversal = traversal.match(matchTraversals);
}
 
Example #4
Source File: WhereTraversalBuilder.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static GraphTraversal<?, ?> transform(final E_Exists expression) {
    final OpBGP opBGP = (OpBGP) expression.getGraphPattern();
    final List<Triple> triples = opBGP.getPattern().getList();
    if (triples.size() != 1) throw new IllegalStateException("Unhandled EXISTS pattern");
    final GraphTraversal<?, ?> traversal = TraversalBuilder.transform(triples.get(0));
    final Step endStep = traversal.asAdmin().getEndStep();
    final String label = (String) endStep.getLabels().iterator().next();
    endStep.removeLabel(label);
    return traversal;
}
 
Example #5
Source File: WhereTraversalBuilder.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static GraphTraversal<?, ?> transform(final E_NotExists expression) {
    final OpBGP opBGP = (OpBGP) expression.getGraphPattern();
    final List<Triple> triples = opBGP.getPattern().getList();
    if (triples.size() != 1) throw new IllegalStateException("Unhandled NOT EXISTS pattern");
    final GraphTraversal<?, ?> traversal = TraversalBuilder.transform(triples.get(0));
    final Step endStep = traversal.asAdmin().getEndStep();
    final String label = (String) endStep.getLabels().iterator().next();
    endStep.removeLabel(label);
    return __.not(traversal);
}
 
Example #6
Source File: SparqlToGremlinCompiler.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Visiting triple patterns in SPARQL algebra.
 */
@Override
public void visit(final OpBGP opBGP) {
if(optionalFlag)
    {
        opBGP.getPattern().getList().forEach(triple -> optionalTraversals.add(TraversalBuilder.transform(triple)));
        opBGP.getPattern().getList().forEach(triple -> optionalVariable.add(triple.getObject().toString()));
        
    }
    else        
        opBGP.getPattern().getList().forEach(triple -> traversalList.add(TraversalBuilder.transform(triple)));
}
 
Example #7
Source File: OpVariableVistor.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(OpBGP opBGP) {
	for(Triple t : opBGP.getPattern().getList()) {
		process(t.getSubject());
		process(t.getPredicate());
		process(t.getObject());					
	}
}
 
Example #8
Source File: JenaTranslator.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(OpBGP arg0) {
	for(Triple t : arg0.getPattern().getList()) {
		Formula tripleConstraint = handleTriple(t);
		conj(tripleConstraint);
		doStandardBindings(tripleConstraint, arg0);
	}
	context.getCurrentContinuation().next(context, context.getCurrentQuery());
}
 
Example #9
Source File: OpVariableVistor.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(OpBGP opBGP) {
	for(Triple t : opBGP.getPattern().getList()) {
		process(t.getSubject());
		process(t.getPredicate());
		process(t.getObject());					
	}
}
 
Example #10
Source File: AlgebraExec.java    From xcurator with Apache License 2.0 4 votes vote down vote up
public static void main (String[] argv)
{
    String BASE = "http://example/" ; 
    BasicPattern bp = new BasicPattern() ;
    Var var_x = Var.alloc("x") ;
    Var var_z = Var.alloc("z") ;
    
    // ---- Build expression
    bp.add(new Triple(var_x, NodeFactory.createURI(BASE+"p"), var_z)) ;
    Op op = new OpBGP(bp) ;
    //Expr expr = ExprUtils.parse("?z < 2 ") ;
    Expr expr = new E_LessThan(new ExprVar(var_z), NodeValue.makeNodeInteger(2)) ;
    op = OpFilter.filter(expr, op) ;

    // ---- Example setup
    Model m = makeModel() ;
    m.write(System.out, "TTL") ;
    System.out.println("--------------") ;
    System.out.print(op) ;
    System.out.println("--------------") ;

    // ---- Execute expression
    QueryIterator qIter = Algebra.exec(op, m.getGraph()) ;
    
    // -------- Either read the query iterator directly ...
    if ( false )
    {
        for ( ; qIter.hasNext() ; )
        {
            Binding b = qIter.nextBinding() ;
            Node n = b.get(var_x) ;
            System.out.println(NodeFmtLib.displayStr(n)) ;
            System.out.println(b) ; 
        }
        qIter.close() ;
    }
    else
    {
        // -------- Or make ResultSet from it (but not both - reading an
        //          iterator consumes the current solution)
        List<String> varNames = new ArrayList<String>() ;
        varNames.add("x") ;
        varNames.add("z") ;
        ResultSet rs = new ResultSetStream(varNames, m, qIter);
        ResultSetFormatter.out(rs) ;
        qIter.close() ;
    }
    System.exit(0) ;
}
 
Example #11
Source File: labelSearch.java    From xcurator with Apache License 2.0 4 votes vote down vote up
@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
    Var var2 = createNewVar() ;                     // Hidden variable
    
    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) ;
}
 
Example #12
Source File: MyQueryEngine.java    From xcurator with Apache License 2.0 4 votes vote down vote up
@Override
public Op transform(OpBGP opBGP)                { return opBGP ; }
 
Example #13
Source File: OpExecutorAlt.java    From xcurator with Apache License 2.0 4 votes vote down vote up
@Override
protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {
    return super.execute(opBGP, input) ;
}