use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class LinkedHashModel method readObject.
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
// Read in any hidden serialization magic
s.defaultReadObject();
// Read in size
int size = s.readInt();
values = new HashMap<Value, ModelNode>(size * 2);
statements = new LinkedHashSet<ModelStatement>(size);
// Read in all elements
for (int i = 0; i < size; i++) {
Statement st = (Statement) s.readObject();
add(st);
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class LinkedHashModel method remove.
@Override
public boolean remove(Object o) {
if (o instanceof Statement) {
Iterator iter = find((Statement) o);
if (iter.hasNext()) {
iter.next();
iter.remove();
return true;
}
}
return false;
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class TreeModel method pollLast.
public Statement pollLast() {
try {
Statement last = trees.get(0).tree.last();
remove(last);
return last;
} catch (NoSuchElementException e) {
return null;
}
}
use of org.eclipse.rdf4j.model.Statement 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");
}
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class SPARQLConnection method getStatementGeneral.
private RepositoryResult<Statement> getStatementGeneral(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
GraphQueryResult gRes = null;
RepositoryResult<Statement> result = null;
boolean allGood = false;
try {
GraphQuery query = prepareGraphQuery(SPARQL, EVERYTHING, "");
query.setIncludeInferred(includeInferred);
setBindings(query, subj, pred, obj, contexts);
gRes = query.evaluate();
result = new RepositoryResult<Statement>(new ExceptionConvertingIteration<Statement, RepositoryException>(gRes) {
@Override
protected RepositoryException convert(Exception e) {
return new RepositoryException(e);
}
});
allGood = true;
return result;
} finally {
if (!allGood) {
try {
if (result != null) {
result.close();
}
} finally {
if (gRes != null) {
gRes.close();
}
}
}
}
}
Aggregations