use of org.openrdf.model.Statement in project gocd by gocd.
the class SesameGraph method dumpTriplesNotInContext.
private void dumpTriplesNotInContext(Writer writer) {
try {
writer.append("Statements not in any context: \n");
} catch (IOException e) {
throw new RuntimeException(e);
}
RDFXMLWriter xmlWriter = new RDFXMLWriter(writer);
xmlWriter.startRDF();
try {
RepositoryResult<Statement> result = conn.getStatements(null, null, null, false);
while (result.hasNext()) {
Statement statement = result.next();
if (statement.getContext() == null) {
xmlWriter.handleStatement(statement);
}
}
} catch (RepositoryException | RDFHandlerException e) {
throw new RuntimeException(e);
} finally {
try {
xmlWriter.endRDF();
} catch (RDFHandlerException e) {
throw new RuntimeException(e);
}
}
}
use of org.openrdf.model.Statement in project vcell by virtualcell.
the class Model2JDOM method createElement.
protected Element createElement(Graph model, Resource resource) {
Element element = null;
Iterator<Statement> stmtIter = model.match(resource, RDF.TYPE, null);
while (stmtIter.hasNext()) {
Value object = stmtIter.next().getObject();
if (object instanceof URI) {
URI type = (URI) object;
String nameSpaceURI = type.getNamespace();
String localName = type.getLocalName();
if (localName != null && localName.length() > 0 && nameSpaceURI != null && nameSpaceURI.length() > 0) {
NameSpace ns = nsMap.provideNamesSpace(nameSpaceURI);
element = new Element(localName, Namespace.getNamespace(ns.prefix, ns.uri));
break;
}
}
}
if (element == null) {
element = new Element(TYPELESS_NODE_NAME, nsRDF);
}
if (resource instanceof URI) {
element.setAttribute("about", resource.stringValue(), nsRDF);
} else {
element.setAttribute("nodeID", blankNodeID(resource), nsRDF);
}
return element;
}
use of org.openrdf.model.Statement in project vcell by virtualcell.
the class RefGroup method refs.
public Set<MIRIAMRef> refs(Graph graph) {
Iterator<Statement> stmtIter = graph.match(getResource(), null, null);
Set<MIRIAMRef> refs = new HashSet<MIRIAMRef>();
while (stmtIter.hasNext()) {
Statement statement = stmtIter.next();
if (RDFBagUtil.isRDFContainerMembershipProperty(statement.getPredicate())) {
Value object = statement.getObject();
if (object instanceof URI) {
URI resourceRef = (URI) object;
try {
refs.add(MIRIAMRef.createFromURN(resourceRef.stringValue()));
} catch (URNParseFailureException e) {
e.printStackTrace();
}
}
}
}
return refs;
}
use of org.openrdf.model.Statement in project vcell by virtualcell.
the class RefGroup method remove.
public RefGroup remove(Graph graph, MIRIAMRef ref) {
Resource resourceRef = graph.getValueFactory().createURI(ref.urn());
Iterator<Statement> stmtIter = graph.match(getResource(), null, resourceRef);
while (stmtIter.hasNext()) {
stmtIter.next();
stmtIter.remove();
}
return this;
}
use of org.openrdf.model.Statement in project vcell by virtualcell.
the class RefGroup method contains.
public boolean contains(Graph graph, MIRIAMRef ref) {
Resource rRef = graph.getValueFactory().createURI(ref.urn());
Statement statement = graph.getValueFactory().createStatement(getResource(), RDF.LI, rRef);
return graph.contains(statement);
}
Aggregations