use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class GraphImpl method add.
public boolean add(Resource subj, IRI pred, Value obj, Resource... contexts) {
OpenRDFUtil.verifyContextNotNull(contexts);
boolean graphChanged = false;
if (contexts.length == 0) {
graphChanged = add(valueFactory.createStatement(subj, pred, obj));
} else {
for (Resource context : contexts) {
graphChanged |= add(valueFactory.createStatement(subj, pred, obj, context));
}
}
return graphChanged;
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class LinkedHashModel method add.
@Override
public boolean add(Resource subj, IRI pred, Value obj, Resource... contexts) {
if (subj == null || pred == null || obj == null)
throw new UnsupportedOperationException("Incomplete statement");
Value[] ctxs = notNull(contexts);
if (ctxs.length == 0) {
ctxs = NULL_CTX;
}
boolean changed = false;
for (Value ctx : ctxs) {
ModelNode<Resource> s = asNode(subj);
ModelNode<IRI> p = asNode(pred);
ModelNode<Value> o = asNode(obj);
ModelNode<Resource> c = asNode((Resource) ctx);
ModelStatement st = new ModelStatement(s, p, o, c);
changed |= addModelStatement(st);
}
return changed;
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class TreeModel method before.
private Statement before(Value subj, Value pred, Value obj, Value ctx) {
Resource s = subj instanceof Resource ? (Resource) subj : BEFORE;
IRI p = pred instanceof IRI ? (IRI) pred : BEFORE;
Value o = obj instanceof Value ? obj : BEFORE;
Resource c = ctx instanceof Resource ? (Resource) ctx : BEFORE;
return new TreeStatement(s, p, o, c);
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class TreeModel method after.
private Statement after(Value subj, Value pred, Value obj, Value ctx) {
Resource s = subj instanceof Resource ? (Resource) subj : AFTER;
IRI p = pred instanceof IRI ? (IRI) pred : AFTER;
Value o = obj instanceof Value ? obj : AFTER;
Resource c = ctx instanceof Resource ? (Resource) ctx : AFTER;
return new TreeStatement(s, p, o, c);
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class SPARQLConnection method createDataBody.
private void createDataBody(StringBuilder qb, Iterable<? extends Statement> statements, boolean ignoreContext) {
for (Statement st : statements) {
final Resource context = st.getContext();
if (!ignoreContext) {
if (context != null) {
String namedGraph = context.stringValue();
if (context instanceof BNode) {
// SPARQL does not allow blank nodes as named graph
// identifiers, so we need to skolemize
// the blank node id.
namedGraph = "urn:nodeid:" + context.stringValue();
}
qb.append(" GRAPH <" + namedGraph + "> { \n");
}
}
if (st.getSubject() instanceof BNode) {
qb.append("_:" + st.getSubject().stringValue() + " ");
} else {
qb.append("<" + st.getSubject().stringValue() + "> ");
}
qb.append("<" + st.getPredicate().stringValue() + "> ");
if (st.getObject() instanceof Literal) {
Literal lit = (Literal) st.getObject();
qb.append("\"");
qb.append(SPARQLUtil.encodeString(lit.getLabel()));
qb.append("\"");
if (Literals.isLanguageLiteral(lit)) {
qb.append("@");
qb.append(lit.getLanguage().get());
} else {
qb.append("^^<" + lit.getDatatype().stringValue() + ">");
}
qb.append(" ");
} else if (st.getObject() instanceof BNode) {
qb.append("_:" + st.getObject().stringValue() + " ");
} else {
qb.append("<" + st.getObject().stringValue() + "> ");
}
qb.append(". \n");
if (!ignoreContext && context != null) {
qb.append(" }\n");
}
}
}
Aggregations