Search in sources :

Example 6 with RDFDataset

use of com.github.jsonldjava.core.RDFDataset in project jena by apache.

the class JenaRDF2JSONLD method parse.

@Override
public RDFDataset parse(Object object) throws JsonLdError {
    RDFDataset result = new RDFDataset();
    if (object instanceof DatasetGraph) {
        DatasetGraph dsg = (DatasetGraph) object;
        Iterator<Quad> iter = dsg.find();
        for (; iter.hasNext(); ) {
            Quad q = iter.next();
            Node s = q.getSubject();
            Node p = q.getPredicate();
            Node o = q.getObject();
            Node g = q.getGraph();
            String gq = null;
            if (g != null && !Quad.isDefaultGraph(g)) {
                gq = blankNodeOrIRIString(g);
                if (gq == null)
                    throw new RiotException("Graph node is not a URI or a blank node");
            }
            String sq = blankNodeOrIRIString(s);
            if (sq == null)
                throw new RiotException("Subject node is not a URI or a blank node");
            String pq = p.getURI();
            if (o.isLiteral()) {
                String lex = o.getLiteralLexicalForm();
                String lang = o.getLiteralLanguage();
                String dt = o.getLiteralDatatypeURI();
                if (lang != null && lang.length() == 0) {
                    lang = null;
                // dt = RDF.getURI()+"langString" ;
                }
                if (dt == null)
                    dt = XSDDatatype.XSDstring.getURI();
                result.addQuad(sq, pq, lex, dt, lang, gq);
            } else {
                String oq = blankNodeOrIRIString(o);
                result.addQuad(sq, pq, oq, gq);
            }
        }
    } else
        Log.warn(JenaRDF2JSONLD.class, "unknown");
    return result;
}
Also used : RDFDataset(com.github.jsonldjava.core.RDFDataset) Quad(org.apache.jena.sparql.core.Quad) RiotException(org.apache.jena.riot.RiotException) Node(org.apache.jena.graph.Node) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

RDFDataset (com.github.jsonldjava.core.RDFDataset)6 JsonLdError (com.github.jsonldjava.core.JsonLdError)3 Map (java.util.Map)3 Node (org.apache.jena.graph.Node)3 Quad (org.apache.jena.sparql.core.Quad)3 JsonLdOptions (com.github.jsonldjava.core.JsonLdOptions)2 JsonLdTripleCallback (com.github.jsonldjava.core.JsonLdTripleCallback)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Triple (org.apache.jena.graph.Triple)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonLdApi (com.github.jsonldjava.core.JsonLdApi)1 LinkedHashMap (java.util.LinkedHashMap)1 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)1 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)1 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)1 Graph (org.apache.clerezza.commons.rdf.Graph)1 Triple (org.apache.clerezza.commons.rdf.Triple)1 Util.isLangString (org.apache.jena.rdf.model.impl.Util.isLangString)1