Class JsonLdProcessor


  • public class JsonLdProcessor
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<java.lang.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.
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonLdProcessor()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Map<java.lang.String,​java.lang.Object> compact​(java.lang.Object input, java.lang.Object context, JsonLdOptions opts)
      Compacts the given input using the context according to the steps in the Compaction algorithm.
      static java.util.List<java.lang.Object> expand​(java.lang.Object input)
      Expands the given input according to the steps in the Expansion algorithm, using the default JsonLdOptions.
      static java.util.List<java.lang.Object> expand​(java.lang.Object input, JsonLdOptions opts)
      Expands the given input according to the steps in the Expansion algorithm.
      static java.lang.Object flatten​(java.lang.Object input, JsonLdOptions opts)
      Flattens the given input and compacts it using the passed context according to the steps in the Flattening algorithm:
      static java.lang.Object flatten​(java.lang.Object input, java.lang.Object context, JsonLdOptions opts)  
      static java.util.Map<java.lang.String,​java.lang.Object> frame​(java.lang.Object input, java.lang.Object frame, JsonLdOptions opts)
      Frames the given input using the frame according to the steps in the Framing Algorithm.
      static java.lang.Object fromRDF​(java.lang.Object dataset)
      Converts an RDF dataset to JSON-LD, using the default JsonLdOptions.
      static java.lang.Object fromRDF​(java.lang.Object dataset, JsonLdOptions options)
      Converts an RDF dataset to JSON-LD.
      static java.lang.Object fromRDF​(java.lang.Object input, JsonLdOptions options, RDFParser parser)
      Converts an RDF dataset to JSON-LD, using a specific instance of RDFParser.
      static java.lang.Object fromRDF​(java.lang.Object input, RDFParser parser)
      Converts an RDF dataset to JSON-LD, using a specific instance of RDFParser, and the default JsonLdOptions.
      static java.lang.Object normalize​(java.lang.Object input)
      Performs RDF dataset normalization on the given JSON-LD input.
      static java.lang.Object normalize​(java.lang.Object input, JsonLdOptions options)
      Performs RDF dataset normalization on the given JSON-LD input.
      static void registerRDFParser​(java.lang.String format, RDFParser parser)  
      static void removeRDFParser​(java.lang.String format)  
      private static java.lang.Object returnedContext​(java.lang.Object context, JsonLdOptions opts)
      Builds the context to be returned in framing, flattening and compaction algorithms.
      static java.lang.Object toRDF​(java.lang.Object input)
      Outputs the RDF dataset found in the given JSON-LD object, using the default JsonLdOptions.
      static java.lang.Object toRDF​(java.lang.Object input, JsonLdOptions options)
      Outputs the RDF dataset found in the given JSON-LD object.
      static java.lang.Object toRDF​(java.lang.Object input, JsonLdTripleCallback callback)
      Outputs the RDF dataset found in the given JSON-LD object, using the default JsonLdOptions.
      static java.lang.Object toRDF​(java.lang.Object input, JsonLdTripleCallback callback, JsonLdOptions options)
      Outputs the RDF dataset found in the given JSON-LD object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • rdfParsers

        private static java.util.Map<java.lang.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 Detail

      • JsonLdProcessor

        public JsonLdProcessor()
    • Method Detail

      • compact

        public static java.util.Map<java.lang.String,​java.lang.Object> compact​(java.lang.Object input,
                                                                                     java.lang.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 java.util.List<java.lang.Object> expand​(java.lang.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 java.util.List<java.lang.Object> expand​(java.lang.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 java.lang.Object flatten​(java.lang.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 java.util.Map<java.lang.String,​java.lang.Object> frame​(java.lang.Object input,
                                                                                   java.lang.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 java.lang.Object returnedContext​(java.lang.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​(java.lang.String format,
                                             RDFParser parser)
      • removeRDFParser

        public static void removeRDFParser​(java.lang.String format)
      • fromRDF

        public static java.lang.Object fromRDF​(java.lang.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 java.lang.Object fromRDF​(java.lang.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 java.lang.Object fromRDF​(java.lang.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 java.lang.Object fromRDF​(java.lang.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 java.lang.Object toRDF​(java.lang.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 java.lang.Object toRDF​(java.lang.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 java.lang.Object toRDF​(java.lang.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 java.lang.Object toRDF​(java.lang.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 java.lang.Object normalize​(java.lang.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 java.lang.Object normalize​(java.lang.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.