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.
  • Field Details

    • log

      private final org.slf4j.Logger log
    • opts

    • value

      Object value
    • context

      Context context
    • blankNodeIdentifierMap

      private final Map<String,String> blankNodeIdentifierMap
      Blank Node identifier map specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier
    • blankNodeCounter

      private int blankNodeCounter
      Counter specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier
    • nodeMap

      private Map<String,Object> nodeMap
  • 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

    • initialize

      private void initialize(Object input, Object context) throws JsonLdError
      Initializes this object by cloning the input object using JsonLdUtils.clone(Object), and by parsing the context using Context.parse(Object).
      Parameters:
      input - The initial object, which is to be cloned and used in operations.
      context - The context object, which is to be parsed and used in operations.
      Throws:
      JsonLdError - If there was an error cloning the object, or in parsing the context.
    • 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.
    • generateNodeMap

      void generateNodeMap(Object element, Map<String,Object> nodeMap) throws JsonLdError
      _____ _ _ _ _ _ _ _ _ | ___| | __ _| |_| |_ ___ _ __ / \ | | __ _ ___ _ __(_) |_| |__ _ __ ___ | |_ | |/ _` | __| __/ _ \ '_ \ / _ \ | |/ _` |/ _ \| '__| | __| '_ \| '_ ` _ \ | _| | | (_| | |_| || __/ | | | / ___ \| | (_| | (_) | | | | |_| | | | | | | | | |_| |_|\__,_|\__|\__\___|_| |_| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| |___/
      Throws:
      JsonLdError
    • generateNodeMap

      void generateNodeMap(Object element, Map<String,Object> nodeMap, String activeGraph) throws JsonLdError
      Throws:
      JsonLdError
    • generateNodeMap

      void generateNodeMap(Object element, Map<String,Object> nodeMap, String activeGraph, Object activeSubject, String activeProperty, Map<String,Object> list) throws JsonLdError
      Throws:
      JsonLdError
    • generateBlankNodeIdentifier

      String generateBlankNodeIdentifier(String id)
      Generates a blank node identifier for the given key using the algorithm specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier
      Parameters:
      id - The id, or null to generate a fresh, unused, blank node identifier.
      Returns:
      A blank node identifier based on id if it was not null, or a fresh, unused, blank node identifier if it was null.
    • generateBlankNodeIdentifier

      String generateBlankNodeIdentifier()
      Generates a fresh, unused, blank node identifier using the algorithm specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier
      Returns:
      A fresh, unused, blank node identifier.
    • 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.
    • createsCircularReference

      private boolean createsCircularReference(String id, JsonLdApi.FramingContext state)
    • frame

      private void frame(JsonLdApi.FramingContext state, Map<String,Object> nodes, Map<String,Object> frame, Object parent, String property) throws JsonLdError
      Frames subjects according to the given frame.
      Parameters:
      state - the current framing state.
      frame - the frame.
      parent - the parent subject or top-level array.
      property - the parent property, initialized to null.
      Throws:
      JsonLdError - If there was an error during framing.
    • getFrameValue

      private Object getFrameValue(Map<String,Object> frame, String name)
    • getFrameFlag

      private Boolean getFrameFlag(Map<String,Object> frame, String name, boolean thedefault)
    • getFrameEmbed

      private JsonLdConsts.Embed getFrameEmbed(Map<String,Object> frame, JsonLdConsts.Embed thedefault) throws JsonLdError
      Throws:
      JsonLdError
    • removeEmbed

      private static void removeEmbed(JsonLdApi.FramingContext state, String id)
      Removes an existing embed.
      Parameters:
      state - the current framing state.
      id - the @id of the embed to remove.
    • removeDependents

      private static void removeDependents(Map<String,JsonLdApi.EmbedNode> embeds, String id)
    • filterNodes

      private Map<String,Object> filterNodes(JsonLdApi.FramingContext state, Map<String,Object> nodes, Map<String,Object> frame, boolean requireAll) throws JsonLdError
      Throws:
      JsonLdError
    • filterNode

      private boolean filterNode(JsonLdApi.FramingContext state, Map<String,Object> node, Map<String,Object> frame, boolean requireAll) throws JsonLdError
      Throws:
      JsonLdError
    • addFrameOutput

      private static void addFrameOutput(JsonLdApi.FramingContext state, Object parent, String property, Object output)
      Adds framing output to the given parent.
      Parameters:
      state - the current framing state.
      parent - the parent to add to.
      property - the parent property.
      output - the output to add.
    • 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.