Search in sources :

Example 91 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class QueryTest method convertToStrings.

private ResultSetRewindable convertToStrings(ResultSetRewindable resultsActual) {
    List<Binding> bindings = new ArrayList<>();
    while (resultsActual.hasNext()) {
        Binding b = resultsActual.nextBinding();
        BindingMap b2 = BindingFactory.create();
        for (String vn : resultsActual.getResultVars()) {
            Var v = Var.alloc(vn);
            Node n = b.get(v);
            String s;
            if (n == null)
                s = "";
            else if (n.isBlank())
                s = "_:" + n.getBlankNodeLabel();
            else
                s = NodeFunctions.str(n);
            b2.add(v, NodeFactory.createLiteral(s));
        }
        bindings.add(b2);
    }
    ResultSet rs = new ResultSetStream(resultsActual.getResultVars(), null, new QueryIterPlainWrapper(bindings.iterator()));
    return ResultSetFactory.makeRewindable(rs);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) Var(org.apache.jena.sparql.core.Var) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 92 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class TestGraphUnionRead method gr_union_05.

@Test
public void gr_union_05() {
    List<Node> gnodes = list();
    Graph g = new GraphUnionRead(dsg, gnodes);
    long x = Iter.count(g.find(null, null, null));
    assertEquals(0, x);
}
Also used : GraphUnionRead(org.apache.jena.sparql.graph.GraphUnionRead) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) BuilderGraph(org.apache.jena.sparql.sse.builders.BuilderGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 93 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class TestGraphUnionRead method gr_union_02.

@Test
public void gr_union_02() {
    List<Node> gnodes = list(gn1, gn2);
    Graph g = new GraphUnionRead(dsg, gnodes);
    Node s = NodeFactory.createURI("http://example/s");
    long x = Iter.count(g.find(s, null, null));
    assertEquals(3, x);
}
Also used : GraphUnionRead(org.apache.jena.sparql.graph.GraphUnionRead) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) BuilderGraph(org.apache.jena.sparql.sse.builders.BuilderGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 94 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class LabelToNodeMap method asNode.

public Node asNode(String label) {
    Node n = bNodeLabels.get(label);
    if (n != null)
        return n;
    n = allocNode();
    bNodeLabels.put(label, n);
    return n;
}
Also used : Node(org.apache.jena.graph.Node)

Example 95 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class ParserBase method createNode.

protected Node createNode(String iri) {
    // Is it a bNode label? i.e. <_:xyz>
    if (isBNodeIRI(iri)) {
        String s = iri.substring(bNodeLabelStart.length());
        Node n = NodeFactory.createBlankNode(s);
        return n;
    }
    return NodeFactory.createURI(iri);
}
Also used : Node(org.apache.jena.graph.Node)

Aggregations

Node (org.apache.jena.graph.Node)681 Test (org.junit.Test)191 Triple (org.apache.jena.graph.Triple)98 BaseTest (org.apache.jena.atlas.junit.BaseTest)85 Var (org.apache.jena.sparql.core.Var)84 ArrayList (java.util.ArrayList)55 Graph (org.apache.jena.graph.Graph)46 Binding (org.apache.jena.sparql.engine.binding.Binding)40 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)36 Quad (org.apache.jena.sparql.core.Quad)35 LabelToNode (org.apache.jena.riot.lang.LabelToNode)28 RDFNode (org.apache.jena.rdf.model.RDFNode)25 HashMap (java.util.HashMap)22 Model (org.apache.jena.rdf.model.Model)18 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)18 NodeId (org.apache.jena.tdb.store.NodeId)18 NodeWritable (org.apache.jena.hadoop.rdf.types.NodeWritable)16 Token (org.apache.jena.riot.tokens.Token)16 BasicPattern (org.apache.jena.sparql.core.BasicPattern)16 NodeValue (org.apache.jena.sparql.expr.NodeValue)16