Class JsonLdRDF

java.lang.Object
org.apache.commons.rdf.jsonldjava.JsonLdRDF
All Implemented Interfaces:
RDF

public final class JsonLdRDF extends Object implements RDF
JSON-LD Java RDF implementation.
  • Field Details

    • bnodePrefix

      final String bnodePrefix
  • Constructor Details

    • JsonLdRDF

      public JsonLdRDF()
    • JsonLdRDF

      JsonLdRDF(String bnodePrefix)
  • Method Details

    • asDataset

      public JsonLdDataset asDataset(com.github.jsonldjava.core.RDFDataset rdfDataSet)
      Adapt a JsonLd RDFDataset as a Commons RDF Dataset.

      Changes to the Commons RDF Dataset are reflected in the JsonLd RDFDataset and vice versa.

      Parameters:
      rdfDataSet - JsonLd RDFDataset to adapt
      Returns:
      Adapted Dataset
      See Also:
    • asGraph

      public JsonLdGraph asGraph(com.github.jsonldjava.core.RDFDataset rdfDataSet)
      Adapt a JsonLd RDFDataset as a Commons RDF Graph.

      Only triples in the default graph are included. To retrieve any other graph, asDataset(RDFDataset) together with Dataset.getGraph(BlankNodeOrIRI).

      Changes to the Commons RDF Graph are reflected in the JsonLd RDFDataset and vice versa.

      Parameters:
      rdfDataSet - JsonLd RDFDataset to adapt
      Returns:
      Adapted Graph covering the default graph
      See Also:
    • asJsonLdNode

      public com.github.jsonldjava.core.RDFDataset.Node asJsonLdNode(RDFTerm term)
    • asJsonLdQuad

      public com.github.jsonldjava.core.RDFDataset.Quad asJsonLdQuad(Quad quad)
      Adapt a Commons RDF Quad as a JsonLd RDFDataset.Quad.
      Parameters:
      quad - Commons RDF Quad to adapt
      Returns:
      Adapted JsonLd RDFDataset.Quad
    • asJsonLdQuad

      public com.github.jsonldjava.core.RDFDataset.Quad asJsonLdQuad(Triple triple)
      Adapt a Commons RDF Triple as a JsonLd RDFDataset.Quad.
      Parameters:
      triple - Commons RDF Triple to adapt
      Returns:
      Adapted JsonLd RDFDataset.Quad
    • asQuad

      public JsonLdQuad asQuad(com.github.jsonldjava.core.RDFDataset.Quad quad)
      Adapt a JsonLd RDFDataset.Quad as a Commons RDF Quad.

      The underlying JsonLd quad can be retrieved with JsonLdTripleLike.asJsonLdQuad().

      Parameters:
      quad - A JsonLd RDFDataset.Quad to adapt
      Returns:
      Adapted JsonLdQuad
    • asRDFTerm

      public JsonLdTerm asRDFTerm(com.github.jsonldjava.core.RDFDataset.Node node)
      Adapt a JsonLd RDFDataset.Node as a Commons RDF RDFTerm.

      The underlying node can be retrieved with JsonLdTerm.asJsonLdNode().

      Parameters:
      node - A JsonLd RDFDataset.Node to adapt
      Returns:
      Adapted JsonLdTerm
    • asTriple

      public JsonLdTriple asTriple(com.github.jsonldjava.core.RDFDataset.Quad quad)
      Adapt a JsonLd RDFDataset.Quad as a Commons RDF Triple.

      The underlying JsonLd quad can be retrieved with JsonLdTripleLike.asJsonLdQuad().

      Parameters:
      quad - A JsonLd RDFDataset.Quad to adapt
      Returns:
      Adapted JsonLdTriple
    • asUnionGraph

      public JsonLdUnionGraph asUnionGraph(com.github.jsonldjava.core.RDFDataset rdfDataSet)
      Adapt a JsonLd RDFDataset as a Commons RDF Graph.

      The graph can be seen as a union graph as it will contains all the triples across all the graphs of the underlying RDFDataset.

      Note that some triple operations on a union graph can be inefficient as they need to remove any duplicate triples across the graphs.

      Changes to the Commons RDF Graph are reflected in the JsonLd RDFDataset and vice versa. Triples removed from the graph are removed from all graphs, while triples added are added to the default graph.

      Parameters:
      rdfDataSet - JsonLd RDFDataset to adapt
      Returns:
      Adapted Dataset
    • createBlankNode

      public JsonLdBlankNode createBlankNode()
      Description copied from interface: RDF
      Create a new blank node.

      The returned blank node MUST NOT be equal to any existing BlankNode instances according to BlankNode.equals(Object).

      Specified by:
      createBlankNode in interface RDF
      Returns:
      A new, unique BlankNode
    • createBlankNode

      public JsonLdBlankNode createBlankNode(String name)
      Description copied from interface: RDF
      Create a blank node based on the given name.

      All BlankNodes created with the given name on a particular instance of RDF MUST be equivalent according to BlankNode.equals(Object),

      The returned BlankNode MUST NOT be equal to BlankNode instances returned for any other name or those returned from RDF.createBlankNode().

      The returned BlankNode SHOULD NOT be equivalent to any BlankNodes created on a different RDF instance, e.g. different instances of RDF should produce different blank nodes for the same name unless they purposely are intending to create equivalent BlankNode instances (e.g. a reinstated Serializable factory).

      Specified by:
      createBlankNode in interface RDF
      Parameters:
      name - A non-empty, non-null, String that is unique to this blank node in the context of this RDF.
      Returns:
      A BlankNode for the given name
    • createDataset

      public JsonLdDataset createDataset()
      Description copied from interface: RDF
      Create a new dataset. It is undefined if the dataset will be persisted by any underlying storage mechanism.
      Specified by:
      createDataset in interface RDF
      Returns:
      A new Dataset
    • createGraph

      public JsonLdGraph createGraph()
      Description copied from interface: RDF
      Create a new graph. It is undefined if the graph will be persisted by any underlying storage mechanism.
      Specified by:
      createGraph in interface RDF
      Returns:
      A new Graph
    • createIRI

      public JsonLdIRI createIRI(String iri)
      Description copied from interface: RDF
      Create an IRI from a (possibly escaped) String. The provided iri string MUST be valid according to the W3C RDF-1.1 IRI definition.
      Specified by:
      createIRI in interface RDF
      Parameters:
      iri - Internationalized Resource Identifier
      Returns:
      A new IRI
    • createLiteral

      public JsonLdLiteral createLiteral(String literal)
      Description copied from interface: RDF
      Create a simple literal. The provided lexical form should not be escaped in any sense, e.g. should not include "quotes" unless those are part of the literal value. The returned Literal MUST have a Literal.getLexicalForm() that is equal to the provided lexical form, MUST NOT have a Literal.getLanguageTag() present, and SHOULD return a Literal.getDatatype() that is equal to the IRI http://www.w3.org/2001/XMLSchema#string.
      Specified by:
      createLiteral in interface RDF
      Parameters:
      literal - The literal value in plain text
      Returns:
      The created Literal
    • createLiteral

      public JsonLdLiteral createLiteral(String literal, IRI dataType)
      Description copied from interface: RDF
      Create a literal with the specified data type. The provided lexical form should not be escaped in any sense, e.g. should not include "quotes" unless those are part of the literal value. It is RECOMMENDED that the provided dataType is one of the RDF-compatible XSD types. The provided lexical form SHOULD be in the lexical space of the provided dataType. The returned Literal SHOULD have a Literal.getLexicalForm() that is equal to the provided lexicalForm, MUST NOT have a Literal.getLanguageTag() present, and MUST return a Literal.getDatatype() that is equivalent to the provided dataType IRI.
      Specified by:
      createLiteral in interface RDF
      Parameters:
      literal - The literal value
      dataType - The data type IRI for the literal value, e.g. http://www.w3.org/2001/XMLSchema#integer
      Returns:
      The created Literal
    • createLiteral

      public JsonLdLiteral createLiteral(String literal, String language)
      Description copied from interface: RDF
      Create a language-tagged literal. The provided lexical form should not be escaped in any sense, e.g. should not include "quotes" unless those are part of the literal value. The provided language tag MUST be valid according to BCP47, e.g. en. The provided language tag MAY be converted to lower case. The returned Literal SHOULD have a Literal.getLexicalForm() which is equal to the provided lexicalForm, MUST return a Literal.getDatatype() that is equal to the IRI http://www.w3.org/1999/02/22-rdf-syntax-ns#langString, and MUST have a Literal.getLanguageTag() present which SHOULD be equal to the provided language tag (compared as String.toLowerCase(Locale) using Locale.ENGLISH).
      Specified by:
      createLiteral in interface RDF
      Parameters:
      literal - The literal value
      language - The non-empty language tag as defined by BCP47
      Returns:
      The created Literal
    • createQuad

      public JsonLdQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws IllegalArgumentException, UnsupportedOperationException
      Description copied from interface: RDF
      Create a quad.

      The returned Quad SHOULD have a Quad.getGraphName() that is equal to the provided graphName, a Quad.getSubject() that is equal to the provided subject, a Quad.getPredicate() that is equal to the provided predicate, and a Quad.getObject() that is equal to the provided object.

      Specified by:
      createQuad in interface RDF
      Parameters:
      graphName - The IRI or BlankNode that this quad belongs to, or null for the public graph
      subject - The IRI or BlankNode that is the subject of the quad
      predicate - The IRI that is the predicate of the quad
      object - The IRI, BlankNode or Literal that is the object of the quad
      Returns:
      The created Quad
      Throws:
      IllegalArgumentException - If any of the provided arguments are not acceptable, e.g. because a Literal has a lexicalForm that is too large for an underlying storage.
      UnsupportedOperationException
    • createTriple

      public JsonLdTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Description copied from interface: RDF
      Create a triple. The returned Triple SHOULD have a Triple.getSubject() that is equal to the provided subject, a Triple.getPredicate() that is equal to the provided predicate, and a Triple.getObject() that is equal to the provided object.
      Specified by:
      createTriple in interface RDF
      Parameters:
      subject - The IRI or BlankNode that is the subject of the triple
      predicate - The IRI that is the predicate of the triple
      object - The IRI, BlankNode or Literal that is the object of the triple
      Returns:
      The created Triple
    • asJsonLdString

      String asJsonLdString(BlankNodeOrIRI blankNodeOrIRI)
    • asRDFTerm

      JsonLdTerm asRDFTerm(com.github.jsonldjava.core.RDFDataset.Node node, String blankNodePrefix)
    • createJsonLdQuad

      com.github.jsonldjava.core.RDFDataset.Quad createJsonLdQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)