Class JsonLdProcessor

java.lang.Object
com.github.jsonldjava.core.JsonLdProcessor

public class JsonLdProcessor extends Object
This class implements the JsonLdProcessor interface, except that it does not currently support asynchronous processing, and hence does not return Promises, instead directly returning the results.
  • Field Details

    • rdfParsers

      private static Map<String,RDFParser> rdfParsers
      A registry for RDF Parsers (in this case, JSONLDSerializers) used by fromRDF if no specific serializer is specified and options.format is set. TODO: this would fit better in the document loader class
  • Constructor Details

    • JsonLdProcessor

      public JsonLdProcessor()
  • Method Details

    • compact

      public static Map<String,Object> compact(Object input, Object context, JsonLdOptions opts) throws JsonLdError
      Compacts the given input using the context according to the steps in the Compaction algorithm.
      Parameters:
      input - The input JSON-LD object.
      context - The context object to use for the compaction algorithm.
      opts - The JsonLdOptions that are to be sent to the compaction algorithm.
      Returns:
      The compacted JSON-LD document
      Throws:
      JsonLdError - If there is an error while compacting.
    • expand

      public static List<Object> expand(Object input, JsonLdOptions opts) throws JsonLdError
      Expands the given input according to the steps in the Expansion algorithm.
      Parameters:
      input - The input JSON-LD object.
      opts - The JsonLdOptions that are to be sent to the expansion algorithm.
      Returns:
      The expanded JSON-LD document
      Throws:
      JsonLdError - If there is an error while expanding.
    • expand

      public static List<Object> expand(Object input) throws JsonLdError
      Expands the given input according to the steps in the Expansion algorithm, using the default JsonLdOptions.
      Parameters:
      input - The input JSON-LD object.
      Returns:
      The expanded JSON-LD document
      Throws:
      JsonLdError - If there is an error while expanding.
    • flatten

      public static Object flatten(Object input, Object context, JsonLdOptions opts) throws JsonLdError
      Throws:
      JsonLdError
    • flatten

      public static Object flatten(Object input, JsonLdOptions opts) throws JsonLdError
      Flattens the given input and compacts it using the passed context according to the steps in the Flattening algorithm:
      Parameters:
      input - The input JSON-LD object.
      opts - The JsonLdOptions that are to be sent to the flattening algorithm.
      Returns:
      The flattened JSON-LD document
      Throws:
      JsonLdError - If there is an error while flattening.
    • frame

      public static Map<String,Object> frame(Object input, Object frame, JsonLdOptions opts) throws JsonLdError
      Frames the given input using the frame according to the steps in the Framing Algorithm.
      Parameters:
      input - The input JSON-LD object.
      frame - The frame to use when re-arranging the data of input; either in the form of an JSON object or as IRI.
      opts - The JsonLdOptions that are to be sent to the framing algorithm.
      Returns:
      The framed JSON-LD document
      Throws:
      JsonLdError - If there is an error while framing.
    • returnedContext

      private static Object returnedContext(Object context, JsonLdOptions opts)
      Builds the context to be returned in framing, flattening and compaction algorithms. In cases where the context is empty or from an unexpected type, it returns null. When JsonLdOptions compactArrays is set to true and the context contains a List with a single element, the element is returned instead of the list
    • registerRDFParser

      public static void registerRDFParser(String format, RDFParser parser)
    • removeRDFParser

      public static void removeRDFParser(String format)
    • fromRDF

      public static Object fromRDF(Object dataset, JsonLdOptions options) throws JsonLdError
      Converts an RDF dataset to JSON-LD.
      Parameters:
      dataset - a serialized string of RDF in a format specified by the format option or an RDF dataset to convert.
      options - the options to use: [format] the format if input is not an array: 'application/nquads' for N-Quads (default). [useRdfType] true to use rdf:type, false to use @type (default: false). [useNativeTypes] true to convert XSD types into native types (boolean, integer, double), false not to (default: true).
      Returns:
      A JSON-LD object.
      Throws:
      JsonLdError - If there is an error converting the dataset to JSON-LD.
    • fromRDF

      public static Object fromRDF(Object dataset) throws JsonLdError
      Converts an RDF dataset to JSON-LD, using the default JsonLdOptions.
      Parameters:
      dataset - a serialized string of RDF in a format specified by the format option or an RDF dataset to convert.
      Returns:
      The JSON-LD object represented by the given RDF dataset
      Throws:
      JsonLdError - If there was an error converting from RDF to JSON-LD
    • fromRDF

      public static Object fromRDF(Object input, JsonLdOptions options, RDFParser parser) throws JsonLdError
      Converts an RDF dataset to JSON-LD, using a specific instance of RDFParser.
      Parameters:
      input - a serialized string of RDF in a format specified by the format option or an RDF dataset to convert.
      options - the options to use: [format] the format if input is not an array: 'application/nquads' for N-Quads (default). [useRdfType] true to use rdf:type, false to use @type (default: false). [useNativeTypes] true to convert XSD types into native types (boolean, integer, double), false not to (default: true).
      parser - A specific instance of RDFParser to use for the conversion.
      Returns:
      A JSON-LD object.
      Throws:
      JsonLdError - If there is an error converting the dataset to JSON-LD.
    • fromRDF

      public static Object fromRDF(Object input, RDFParser parser) throws JsonLdError
      Converts an RDF dataset to JSON-LD, using a specific instance of RDFParser, and the default JsonLdOptions.
      Parameters:
      input - a serialized string of RDF in a format specified by the format option or an RDF dataset to convert.
      parser - A specific instance of RDFParser to use for the conversion.
      Returns:
      A JSON-LD object.
      Throws:
      JsonLdError - If there is an error converting the dataset to JSON-LD.
    • toRDF

      public static Object toRDF(Object input, JsonLdTripleCallback callback, JsonLdOptions options) throws JsonLdError
      Outputs the RDF dataset found in the given JSON-LD object.
      Parameters:
      input - the JSON-LD input.
      callback - A callback that is called when the input has been converted to Quads (null to use options.format instead).
      options - the options to use: [base] the base IRI to use. [format] the format to use to output a string: 'application/nquads' for N-Quads (default). [loadContext(url, callback(err, url, result))] the context loader.
      Returns:
      The result of executing JsonLdTripleCallback.call(RDFDataset) on the results, or if JsonLdOptions.format is not null, a result in that format if it is found, or otherwise the raw RDFDataset.
      Throws:
      JsonLdError - If there is an error converting the dataset to JSON-LD.
    • toRDF

      public static Object toRDF(Object input, JsonLdOptions options) throws JsonLdError
      Outputs the RDF dataset found in the given JSON-LD object.
      Parameters:
      input - the JSON-LD input.
      options - the options to use: [base] the base IRI to use. [format] the format to use to output a string: 'application/nquads' for N-Quads (default). [loadContext(url, callback(err, url, result))] the context loader.
      Returns:
      A JSON-LD object.
      Throws:
      JsonLdError - If there is an error converting the dataset to JSON-LD.
    • toRDF

      public static Object toRDF(Object input, JsonLdTripleCallback callback) throws JsonLdError
      Outputs the RDF dataset found in the given JSON-LD object, using the default JsonLdOptions.
      Parameters:
      input - the JSON-LD input.
      callback - A callback that is called when the input has been converted to Quads (null to use options.format instead).
      Returns:
      A JSON-LD object.
      Throws:
      JsonLdError - If there is an error converting the dataset to JSON-LD.
    • toRDF

      public static Object toRDF(Object input) throws JsonLdError
      Outputs the RDF dataset found in the given JSON-LD object, using the default JsonLdOptions.
      Parameters:
      input - the JSON-LD input.
      Returns:
      A JSON-LD object.
      Throws:
      JsonLdError - If there is an error converting the dataset to JSON-LD.
    • normalize

      public static Object normalize(Object input, JsonLdOptions options) throws JsonLdError
      Performs RDF dataset normalization on the given JSON-LD input. The output is an RDF dataset unless the 'format' option is used.
      Parameters:
      input - the JSON-LD input to normalize.
      options - the options to use: [base] the base IRI to use. [format] the format if output is a string: 'application/nquads' for N-Quads. [loadContext(url, callback(err, url, result))] the context loader.
      Returns:
      The JSON-LD object
      Throws:
      JsonLdError - If there is an error normalizing the dataset.
    • normalize

      public static Object normalize(Object input) throws JsonLdError
      Performs RDF dataset normalization on the given JSON-LD input. The output is an RDF dataset unless the 'format' option is used. Uses the default JsonLdOptions.
      Parameters:
      input - the JSON-LD input to normalize.
      Returns:
      The JSON-LD object
      Throws:
      JsonLdError - If there is an error normalizing the dataset.