Package com.github.jsonldjava.core
Class JsonLdProcessor
java.lang.Object
com.github.jsonldjava.core.JsonLdProcessor
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
FieldsModifier and TypeFieldDescriptionA 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 -
Method Summary
Modifier and TypeMethodDescriptioncompact
(Object input, Object context, JsonLdOptions opts) Compacts the given input using the context according to the steps in the Compaction algorithm.Expands the given input according to the steps in the Expansion algorithm, using the defaultJsonLdOptions
.expand
(Object input, JsonLdOptions opts) Expands the given input according to the steps in the Expansion algorithm.static Object
flatten
(Object input, JsonLdOptions opts) Flattens the given input and compacts it using the passed context according to the steps in the Flattening algorithm:static Object
flatten
(Object input, Object context, JsonLdOptions opts) frame
(Object input, Object frame, JsonLdOptions opts) Frames the given input using the frame according to the steps in the Framing Algorithm.static Object
Converts an RDF dataset to JSON-LD, using the defaultJsonLdOptions
.static Object
fromRDF
(Object dataset, JsonLdOptions options) Converts an RDF dataset to JSON-LD.static Object
fromRDF
(Object input, JsonLdOptions options, RDFParser parser) Converts an RDF dataset to JSON-LD, using a specific instance ofRDFParser
.static Object
Converts an RDF dataset to JSON-LD, using a specific instance ofRDFParser
, and the defaultJsonLdOptions
.static Object
Performs RDF dataset normalization on the given JSON-LD input.static Object
normalize
(Object input, JsonLdOptions options) Performs RDF dataset normalization on the given JSON-LD input.static void
registerRDFParser
(String format, RDFParser parser) static void
removeRDFParser
(String format) private static Object
returnedContext
(Object context, JsonLdOptions opts) Builds the context to be returned in framing, flattening and compaction algorithms.static Object
Outputs the RDF dataset found in the given JSON-LD object, using the defaultJsonLdOptions
.static Object
toRDF
(Object input, JsonLdOptions options) Outputs the RDF dataset found in the given JSON-LD object.static Object
toRDF
(Object input, JsonLdTripleCallback callback) Outputs the RDF dataset found in the given JSON-LD object, using the defaultJsonLdOptions
.static Object
toRDF
(Object input, JsonLdTripleCallback callback, JsonLdOptions options) Outputs the RDF dataset found in the given JSON-LD object.
-
Field Details
-
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
- TheJsonLdOptions
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
Expands the given input according to the steps in the Expansion algorithm.- Parameters:
input
- The input JSON-LD object.opts
- TheJsonLdOptions
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
Expands the given input according to the steps in the Expansion algorithm, using the defaultJsonLdOptions
.- Parameters:
input
- The input JSON-LD object.- Returns:
- The expanded JSON-LD document
- Throws:
JsonLdError
- If there is an error while expanding.
-
flatten
- Throws:
JsonLdError
-
flatten
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
- TheJsonLdOptions
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
- TheJsonLdOptions
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
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
-
removeRDFParser
-
fromRDF
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
Converts an RDF dataset to JSON-LD, using the defaultJsonLdOptions
.- 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 ofRDFParser
.- 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 ofRDFParser
to use for the conversion.- Returns:
- A JSON-LD object.
- Throws:
JsonLdError
- If there is an error converting the dataset to JSON-LD.
-
fromRDF
Converts an RDF dataset to JSON-LD, using a specific instance ofRDFParser
, and the defaultJsonLdOptions
.- 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 ofRDFParser
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 ifJsonLdOptions.format
is not null, a result in that format if it is found, or otherwise the rawRDFDataset
. - Throws:
JsonLdError
- If there is an error converting the dataset to JSON-LD.
-
toRDF
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
Outputs the RDF dataset found in the given JSON-LD object, using the defaultJsonLdOptions
.- 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
Outputs the RDF dataset found in the given JSON-LD object, using the defaultJsonLdOptions
.- 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
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
Performs RDF dataset normalization on the given JSON-LD input. The output is an RDF dataset unless the 'format' option is used. Uses the defaultJsonLdOptions
.- Parameters:
input
- the JSON-LD input to normalize.- Returns:
- The JSON-LD object
- Throws:
JsonLdError
- If there is an error normalizing the dataset.
-