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);
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations