Search in sources :

Example 16 with ElementGroup

use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.

the class QueryExecutionBase method execDescribe.

@Override
public Model execDescribe(Model model) {
    checkNotClosed();
    if (!query.isDescribeType())
        throw new QueryExecException("Attempt to get a DESCRIBE result from a " + labelForQuery(query) + " query");
    //Was: query.setQueryResultStar(true) ; but why?
    query.setResultVars();
    // If there was no WhereClause, use an empty pattern (one solution, no columns). 
    if (query.getQueryPattern() == null)
        query.setQueryPattern(new ElementGroup());
    Set<RDFNode> set = new HashSet<>();
    //May return null (no query pattern) 
    ResultSet qRes = execResultSet();
    // Prefixes for result (after initialization)
    insertPrefixesInto(model);
    if (qRes != null) {
        for (; qRes.hasNext(); ) {
            QuerySolution rb = qRes.nextSolution();
            for (String varName : query.getResultVars()) {
                RDFNode n = rb.get(varName);
                set.add(n);
            }
        }
    }
    if (query.getResultURIs() != null) {
        // Any URIs in the DESCRIBE
        for (Node n : query.getResultURIs()) {
            // Need to make dataset available to describe handlers.
            RDFNode rNode = ModelUtils.convertGraphNodeToRDFNode(n, dataset.getDefaultModel());
            set.add(rNode);
        }
    }
    // Create new handlers for this process.
    List<DescribeHandler> dhList = DescribeHandlerRegistry.get().newHandlerList();
    getContext().put(ARQConstants.sysCurrentDataset, getDataset());
    // Notify start of describe phase
    for (DescribeHandler dh : dhList) dh.start(model, getContext());
    // Do describe for each resource found.
    for (RDFNode n : set) {
        if (n instanceof Resource) {
            for (DescribeHandler dh : dhList) {
                dh.describe((Resource) n);
            }
        } else {
            // Can't describe literals
            continue;
        }
    }
    for (DescribeHandler dh : dhList) dh.finish();
    this.close();
    return model;
}
Also used : DescribeHandler(org.apache.jena.sparql.core.describe.DescribeHandler) Node(org.apache.jena.graph.Node) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) HashSet(java.util.HashSet)

Example 17 with ElementGroup

use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.

the class TestBlankNodeBinary method bNodeSPARQL_Query_1.

// Check SPARQL parsing.
@Test
public void bNodeSPARQL_Query_1() {
    String qs = "SELECT * { ?s ?p <_:ABC>}";
    Query query = QueryFactory.create(qs);
    Element el = ((ElementGroup) query.getQueryPattern()).get(0);
    ElementPathBlock epb = (ElementPathBlock) el;
    TriplePath tp = epb.getPattern().get(0);
    Triple t = tp.asTriple();
    assertEquals("ABC", t.getObject().getBlankNodeLabel());
}
Also used : Query(org.apache.jena.query.Query) Element(org.apache.jena.sparql.syntax.Element) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 18 with ElementGroup

use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.

the class TestService method makeElt.

/*package*/
static ElementService makeElt(EnvTest env) {
    Node serviceNode = NodeFactory.createURI(env.datasetURL());
    ElementGroup elt = new ElementGroup();
    Element elt1 = new ElementTriplesBlock(bgp);
    elt.addElement(elt1);
    ElementService eltService = new ElementService(SERVICE, elt);
    return eltService;
}
Also used : ElementService(org.apache.jena.sparql.syntax.ElementService) Node(org.apache.jena.graph.Node) Element(org.apache.jena.sparql.syntax.Element) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Example 19 with ElementGroup

use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.

the class TestService method makeOp.

/*package*/
static OpService makeOp(EnvTest env, Node serviceNode) {
    ElementGroup elt = new ElementGroup();
    Element elt1 = new ElementTriplesBlock(bgp);
    elt.addElement(elt1);
    Op subOp = Algebra.compile(elt1);
    // ElementService eltService = new ElementService(SERVICE, elt);
    OpService opService = new OpService(serviceNode, subOp, false);
    return opService;
}
Also used : Op(org.apache.jena.sparql.algebra.Op) Element(org.apache.jena.sparql.syntax.Element) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) OpService(org.apache.jena.sparql.algebra.op.OpService) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Example 20 with ElementGroup

use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.

the class TestService method makeOpElt.

/*package*/
static OpService makeOpElt(EnvTest env) {
    Node serviceNode = NodeFactory.createURI(env.datasetURL());
    ElementGroup elt = new ElementGroup();
    Element elt1 = new ElementTriplesBlock(bgp);
    elt.addElement(elt1);
    Op subOp = Algebra.compile(elt1);
    ElementService eltService = new ElementService(SERVICE, elt);
    OpService opService = new OpService(serviceNode, subOp, eltService, false);
    return opService;
}
Also used : Op(org.apache.jena.sparql.algebra.Op) ElementService(org.apache.jena.sparql.syntax.ElementService) Node(org.apache.jena.graph.Node) Element(org.apache.jena.sparql.syntax.Element) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) OpService(org.apache.jena.sparql.algebra.op.OpService) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Aggregations

ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)37 Element (org.apache.jena.sparql.syntax.Element)24 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)11 Test (org.junit.Test)11 Triple (org.apache.jena.graph.Triple)9 ElementTriplesBlock (org.apache.jena.sparql.syntax.ElementTriplesBlock)9 Node (org.apache.jena.graph.Node)8 Query (org.apache.jena.query.Query)6 Var (org.apache.jena.sparql.core.Var)6 Quad (org.apache.jena.sparql.core.Quad)5 UpdateModify (org.apache.jena.sparql.modify.request.UpdateModify)5 Update (org.apache.jena.update.Update)5 Op (org.apache.jena.sparql.algebra.Op)3 TriplePath (org.apache.jena.sparql.core.TriplePath)3 ElementNamedGraph (org.apache.jena.sparql.syntax.ElementNamedGraph)3 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)3 HashSet (java.util.HashSet)2 SelectClause (org.apache.jena.arq.querybuilder.clauses.SelectClause)2 ElementRewriter (org.apache.jena.arq.querybuilder.rewriters.ElementRewriter)2 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)2