Search in sources :

Example 96 with Node

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

the class NodecSSE method decode.

@Override
public Node decode(ByteBuffer bb, PrefixMapping pmap) {
    // Ideally, this would be straight from the byte buffer.
    // But currently we go bytes -> string -> node 
    // Byte -> String
    String str = BlockUTF8.toString(bb);
    // Easy cases.
    if (str.startsWith("_:")) {
        // Must be done this way.
        // In particular, bnode labels can contain ":" from Jena
        // TokenizerText does not recognize these.
        str = str.substring(2);
        return NodeFactory.createBlankNode(str);
    }
    if (str.startsWith("<")) {
        // Do directly.
        // (is it quicker?)
        str = str.substring(1, str.length() - 1);
        str = StrUtils.unescapeString(str);
        str = StrUtils.decodeHex(str, MarkerChar);
        return NodeFactory.createURI(str);
    }
    Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(str);
    if (!tokenizer.hasNext())
        throw new TDBException("Failed to tokenise: " + str);
    Token t = tokenizer.next();
    try {
        Node n = t.asNode();
        if (n == null)
            throw new TDBException("Not a node: " + str);
        return n;
    } catch (RiotException ex) {
        throw new TDBException("Bad string for node: " + str);
    }
}
Also used : RiotException(org.apache.jena.riot.RiotException) TDBException(org.apache.jena.tdb.TDBException) Node(org.apache.jena.graph.Node) Token(org.apache.jena.riot.tokens.Token) Tokenizer(org.apache.jena.riot.tokens.Tokenizer)

Example 97 with Node

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

the class NodeTableTrans method append.

/** Copy from the journal file to the real file */
/*package*/
void append() {
    Iterator<Pair<NodeId, Node>> iter = nodeTableJournal.all();
    Pair<NodeId, Node> firstPair = null;
    Pair<NodeId, Node> lastPair = null;
    for (; iter.hasNext(); ) {
        Pair<NodeId, Node> x = iter.next();
        if (firstPair == null)
            firstPair = x;
        lastPair = x;
        NodeId nodeId = x.getLeft();
        Node node = x.getRight();
        debug("  append: %s -> %s", x, mapFromJournal(nodeId));
        // This does the write.
        NodeId nodeId2 = base.getAllocateNodeId(node);
        if (!nodeId2.equals(mapFromJournal(nodeId)))
            inconsistent(node, nodeId, nodeId2);
    }
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) Pair(org.apache.jena.atlas.lib.Pair)

Example 98 with Node

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

the class TDBInternal method getNode.

/**
     * Return the node for a NodeId (if any). Returns null if the NodeId does
     * not exist in the dataset.
     */
public static Node getNode(DatasetGraphTDB dsg, NodeId nodeId) {
    if (dsg == null)
        return null;
    NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable();
    Node node = nodeTable.getNodeForNodeId(nodeId);
    return node;
}
Also used : Node(org.apache.jena.graph.Node) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 99 with Node

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

the class TemplateLib method subst.

/** Substitute into a quad, with rewriting of bNodes */
public static Quad subst(Quad quad, Binding b, Map<Node, Node> bNodeMap) {
    Node g = quad.getGraph();
    Node s = quad.getSubject();
    Node p = quad.getPredicate();
    Node o = quad.getObject();
    Node g1 = g;
    Node s1 = s;
    Node p1 = p;
    Node o1 = o;
    // replace blank nodes.
    if (g1.isBlank() || Var.isBlankNodeVar(g1))
        g1 = newBlank(g1, bNodeMap);
    if (s1.isBlank() || Var.isBlankNodeVar(s1))
        s1 = newBlank(s1, bNodeMap);
    if (p1.isBlank() || Var.isBlankNodeVar(p1))
        p1 = newBlank(p1, bNodeMap);
    if (o1.isBlank() || Var.isBlankNodeVar(o1))
        o1 = newBlank(o1, bNodeMap);
    Quad q = quad;
    if (s1 != s || p1 != p || o1 != o || g1 != g)
        q = new Quad(g1, s1, p1, o1);
    Quad q2 = Substitute.substitute(q, b);
    return q2;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node)

Example 100 with Node

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

the class TemplateLib method subst.

/** Substitute into a triple, with rewriting of bNodes */
public static Triple subst(Triple triple, Binding b, Map<Node, Node> bNodeMap) {
    Node s = triple.getSubject();
    Node p = triple.getPredicate();
    Node o = triple.getObject();
    Node s1 = s;
    Node p1 = p;
    Node o1 = o;
    if (s1.isBlank() || Var.isBlankNodeVar(s1))
        s1 = newBlank(s1, bNodeMap);
    if (p1.isBlank() || Var.isBlankNodeVar(p1))
        p1 = newBlank(p1, bNodeMap);
    if (o1.isBlank() || Var.isBlankNodeVar(o1))
        o1 = newBlank(o1, bNodeMap);
    Triple t = triple;
    if (s1 != s || p1 != p || o1 != o)
        t = new Triple(s1, p1, o1);
    Triple t2 = Substitute.substitute(t, b);
    return t2;
}
Also used : Triple(org.apache.jena.graph.Triple) 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