Class JsonLdApi

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

public class JsonLdApi extends Object
A container object to maintain state relating to JsonLdOptions and the current Context, and push these into the relevant algorithms in JsonLdProcessor as necessary.
Author:
tristan
  • Constructor Details

    • JsonLdApi

      public JsonLdApi()
      Constructs an empty JsonLdApi object using the default JsonLdOptions, and without initialization.
    • JsonLdApi

      public JsonLdApi(Object input, JsonLdOptions opts) throws JsonLdError
      Constructs a JsonLdApi object using the given object as the initial JSON-LD object, and the given JsonLdOptions.
      Parameters:
      input - The initial JSON-LD object.
      opts - The JsonLdOptions to use.
      Throws:
      JsonLdError - If there is an error initializing using the object and options.
    • JsonLdApi

      public JsonLdApi(Object input, Object context, JsonLdOptions opts) throws JsonLdError
      Constructs a JsonLdApi object using the given object as the initial JSON-LD object, the given context, and the given JsonLdOptions.
      Parameters:
      input - The initial JSON-LD object.
      context - The initial context.
      opts - The JsonLdOptions to use.
      Throws:
      JsonLdError - If there is an error initializing using the object and options.
    • JsonLdApi

      public JsonLdApi(JsonLdOptions opts)
      Constructs an empty JsonLdApi object using the given JsonLdOptions, and without initialization.
      If the JsonLdOptions parameter is null, then the default options are used.
      Parameters:
      opts - The JsonLdOptions to use.
  • Method Details

    • compact

      public Object compact(Context activeCtx, String activeProperty, Object element, boolean compactArrays) throws JsonLdError
      Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#compaction-algorithm
      Parameters:
      activeCtx - The Active Context
      activeProperty - The Active Property
      element - The current element
      compactArrays - True to compact arrays.
      Returns:
      The compacted JSON-LD object.
      Throws:
      JsonLdError - If there was an error during compaction.
    • compact

      public Object compact(Context activeCtx, String activeProperty, Object element) throws JsonLdError
      Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#compaction-algorithm
      Parameters:
      activeCtx - The Active Context
      activeProperty - The Active Property
      element - The current element
      Returns:
      The compacted JSON-LD object.
      Throws:
      JsonLdError - If there was an error during compaction.
    • expand

      public Object expand(Context activeCtx, String activeProperty, Object element) throws JsonLdError
      Expansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm
      Parameters:
      activeCtx - The Active Context
      activeProperty - The Active Property
      element - The current element
      Returns:
      The expanded JSON-LD object.
      Throws:
      JsonLdError - If there was an error during expansion.
    • expand

      public Object expand(Context activeCtx, Object element) throws JsonLdError
      Expansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm
      Parameters:
      activeCtx - The Active Context
      element - The current element
      Returns:
      The expanded JSON-LD object.
      Throws:
      JsonLdError - If there was an error during expansion.
    • frame

      public List<Object> frame(Object input, List<Object> frame) throws JsonLdError
      Performs JSON-LD framing.
      Parameters:
      input - the expanded JSON-LD to frame.
      frame - the expanded JSON-LD frame to use.
      Returns:
      the framed output.
      Throws:
      JsonLdError - If the framing was not successful.
    • fromRDF

      public List<Object> fromRDF(RDFDataset dataset) throws JsonLdError
      Converts RDF statements into JSON-LD.
      Parameters:
      dataset - the RDF statements.
      Returns:
      A list of JSON-LD objects found in the given dataset.
      Throws:
      JsonLdError - If there was an error during conversion from RDF to JSON-LD.
    • fromRDF

      public List<Object> fromRDF(RDFDataset dataset, boolean noDuplicatesInDataset) throws JsonLdError
      Converts RDF statements into JSON-LD, presuming that there are no duplicates in the dataset.
      Parameters:
      dataset - the RDF statements.
      noDuplicatesInDataset - True if there are no duplicates in the dataset and false otherwise.
      Returns:
      A list of JSON-LD objects found in the given dataset.
      Throws:
      JsonLdError - If there was an error during conversion from RDF to JSON-LD.
    • toRDF

      public RDFDataset toRDF() throws JsonLdError
      Adds RDF triples for each graph in the current node map to an RDF dataset.
      Returns:
      the RDF dataset.
      Throws:
      JsonLdError - If there was an error converting from JSON-LD to RDF.
    • normalize

      public Object normalize(Map<String,Object> dataset) throws JsonLdError
      Performs RDF normalization on the given JSON-LD input.
      Parameters:
      dataset - the expanded JSON-LD object to normalize.
      Returns:
      The normalized JSON-LD object
      Throws:
      JsonLdError - If there was an error while normalizing.