Search in sources :

Example 21 with Statement

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);
        }
    }
}
Also used : ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) RDFXMLWriter(org.openrdf.rio.rdfxml.RDFXMLWriter) Statement(org.openrdf.model.Statement) RepositoryException(org.openrdf.repository.RepositoryException) IOException(java.io.IOException)

Example 22 with Statement

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;
}
Also used : Statement(org.openrdf.model.Statement) Element(org.jdom.Element) Value(org.openrdf.model.Value) NameSpace(org.sbpax.schemas.util.NameSpace) URI(org.openrdf.model.URI)

Example 23 with Statement

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;
}
Also used : Statement(org.openrdf.model.Statement) Value(org.openrdf.model.Value) URI(org.openrdf.model.URI) URNParseFailureException(org.vcell.sybil.models.miriam.MIRIAMRef.URNParseFailureException) HashSet(java.util.HashSet)

Example 24 with Statement

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;
}
Also used : Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource)

Example 25 with Statement

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);
}
Also used : Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource)

Aggregations

Statement (org.openrdf.model.Statement)67 Resource (org.openrdf.model.Resource)22 Value (org.openrdf.model.Value)22 URI (org.openrdf.model.URI)21 HashSet (java.util.HashSet)16 SailException (org.openrdf.sail.SailException)10 Collection (java.util.Collection)9 Literal (org.openrdf.model.Literal)9 Graph (org.openrdf.model.Graph)7 Edge (com.tinkerpop.blueprints.Edge)6 Test (org.junit.Test)6 Vertex (com.tinkerpop.blueprints.Vertex)5 HashMap (java.util.HashMap)5 Map (java.util.Map)4 PrintWriter (java.io.PrintWriter)3 Set (java.util.Set)3 BNode (org.openrdf.model.BNode)3 ValueFactory (org.openrdf.model.ValueFactory)3 RDFHandlerException (org.openrdf.rio.RDFHandlerException)3 RdfXmlSerializer (org.qi4j.library.rdf.serializer.RdfXmlSerializer)3