Class JsonLdApi


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

      Nested Classes 
      Modifier and Type Class Description
      private class  JsonLdApi.EmbedNode  
      private class  JsonLdApi.FramingContext
      _____ _ _ _ _ _ _ | ___| __ __ _ _ __ ___ (_)_ __ __ _ / \ | | __ _ ___ _ __(_) |_| |__ _ __ ___ | |_ | '__/ _` | '_ ` _ \| | '_ \ / _` | / _ \ | |/ _` |/ _ \| '__| | __| '_ \| '_ ` _ \ | _|| | | (_| | | | | | | | | | | (_| | / ___ \| | (_| | (_) | | | | |_| | | | | | | | | |_| |_| \__,_|_| |_| |_|_|_| |_|\__, | /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| |___/ |___/
      private class  JsonLdApi.Node  
      private class  JsonLdApi.NodeMapNode  
      private class  JsonLdApi.UsagesNode
      Helper class for node usages
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int blankNodeCounter
      Counter specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier
      private java.util.Map<java.lang.String,​java.lang.String> blankNodeIdentifierMap
      Blank Node identifier map specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier
      (package private) Context context  
      private org.slf4j.Logger log  
      private java.util.Map<java.lang.String,​java.lang.Object> nodeMap  
      (package private) JsonLdOptions opts  
      (package private) java.lang.Object value  
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonLdApi()
      Constructs an empty JsonLdApi object using the default JsonLdOptions, and without initialization.
      JsonLdApi​(JsonLdOptions opts)
      Constructs an empty JsonLdApi object using the given JsonLdOptions, and without initialization.
      JsonLdApi​(java.lang.Object input, JsonLdOptions opts)
      Constructs a JsonLdApi object using the given object as the initial JSON-LD object, and the given JsonLdOptions.
      JsonLdApi​(java.lang.Object input, java.lang.Object context, JsonLdOptions opts)
      Constructs a JsonLdApi object using the given object as the initial JSON-LD object, the given context, and the given JsonLdOptions.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static void addFrameOutput​(JsonLdApi.FramingContext state, java.lang.Object parent, java.lang.String property, java.lang.Object output)
      Adds framing output to the given parent.
      java.lang.Object compact​(Context activeCtx, java.lang.String activeProperty, java.lang.Object element)
      Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#compaction-algorithm
      java.lang.Object compact​(Context activeCtx, java.lang.String activeProperty, java.lang.Object element, boolean compactArrays)
      Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#compaction-algorithm
      private boolean createsCircularReference​(java.lang.String id, JsonLdApi.FramingContext state)  
      java.lang.Object expand​(Context activeCtx, java.lang.Object element)
      Expansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm
      java.lang.Object expand​(Context activeCtx, java.lang.String activeProperty, java.lang.Object element)
      Expansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm
      private boolean filterNode​(JsonLdApi.FramingContext state, java.util.Map<java.lang.String,​java.lang.Object> node, java.util.Map<java.lang.String,​java.lang.Object> frame, boolean requireAll)  
      private java.util.Map<java.lang.String,​java.lang.Object> filterNodes​(JsonLdApi.FramingContext state, java.util.Map<java.lang.String,​java.lang.Object> nodes, java.util.Map<java.lang.String,​java.lang.Object> frame, boolean requireAll)  
      private void frame​(JsonLdApi.FramingContext state, java.util.Map<java.lang.String,​java.lang.Object> nodes, java.util.Map<java.lang.String,​java.lang.Object> frame, java.lang.Object parent, java.lang.String property)
      Frames subjects according to the given frame.
      java.util.List<java.lang.Object> frame​(java.lang.Object input, java.util.List<java.lang.Object> frame)
      Performs JSON-LD framing.
      java.util.List<java.lang.Object> fromRDF​(RDFDataset dataset)
      Converts RDF statements into JSON-LD.
      java.util.List<java.lang.Object> fromRDF​(RDFDataset dataset, boolean noDuplicatesInDataset)
      Converts RDF statements into JSON-LD, presuming that there are no duplicates in the dataset.
      (package private) java.lang.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
      (package private) java.lang.String generateBlankNodeIdentifier​(java.lang.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
      (package private) void generateNodeMap​(java.lang.Object element, java.util.Map<java.lang.String,​java.lang.Object> nodeMap)
      _____ _ _ _ _ _ _ _ _ | ___| | __ _| |_| |_ ___ _ __ / \ | | __ _ ___ _ __(_) |_| |__ _ __ ___ | |_ | |/ _` | __| __/ _ \ '_ \ / _ \ | |/ _` |/ _ \| '__| | __| '_ \| '_ ` _ \ | _| | | (_| | |_| || __/ | | | / ___ \| | (_| | (_) | | | | |_| | | | | | | | | |_| |_|\__,_|\__|\__\___|_| |_| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| |___/
      (package private) void generateNodeMap​(java.lang.Object element, java.util.Map<java.lang.String,​java.lang.Object> nodeMap, java.lang.String activeGraph)  
      (package private) void generateNodeMap​(java.lang.Object element, java.util.Map<java.lang.String,​java.lang.Object> nodeMap, java.lang.String activeGraph, java.lang.Object activeSubject, java.lang.String activeProperty, java.util.Map<java.lang.String,​java.lang.Object> list)  
      private JsonLdConsts.Embed getFrameEmbed​(java.util.Map<java.lang.String,​java.lang.Object> frame, JsonLdConsts.Embed thedefault)  
      private java.lang.Boolean getFrameFlag​(java.util.Map<java.lang.String,​java.lang.Object> frame, java.lang.String name, boolean thedefault)  
      private java.lang.Object getFrameValue​(java.util.Map<java.lang.String,​java.lang.Object> frame, java.lang.String name)  
      private void initialize​(java.lang.Object input, java.lang.Object context)
      Initializes this object by cloning the input object using JsonLdUtils.clone(Object), and by parsing the context using Context.parse(Object).
      java.lang.Object normalize​(java.util.Map<java.lang.String,​java.lang.Object> dataset)
      Performs RDF normalization on the given JSON-LD input.
      private static void removeDependents​(java.util.Map<java.lang.String,​JsonLdApi.EmbedNode> embeds, java.lang.String id)  
      private static void removeEmbed​(JsonLdApi.FramingContext state, java.lang.String id)
      Removes an existing embed.
      RDFDataset toRDF()
      Adds RDF triples for each graph in the current node map to an RDF dataset.
      • Methods inherited from class java.lang.Object

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

      • log

        private final org.slf4j.Logger log
      • value

        java.lang.Object value
      • blankNodeIdentifierMap

        private final java.util.Map<java.lang.String,​java.lang.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 java.util.Map<java.lang.String,​java.lang.Object> nodeMap
    • Constructor Detail

      • JsonLdApi

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

        public JsonLdApi​(java.lang.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​(java.lang.Object input,
                         java.lang.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 Detail

      • initialize

        private void initialize​(java.lang.Object input,
                                java.lang.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 java.lang.Object compact​(Context activeCtx,
                                        java.lang.String activeProperty,
                                        java.lang.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 java.lang.Object compact​(Context activeCtx,
                                        java.lang.String activeProperty,
                                        java.lang.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 java.lang.Object expand​(Context activeCtx,
                                       java.lang.String activeProperty,
                                       java.lang.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 java.lang.Object expand​(Context activeCtx,
                                       java.lang.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​(java.lang.Object element,
                             java.util.Map<java.lang.String,​java.lang.Object> nodeMap)
                      throws JsonLdError
        _____ _ _ _ _ _ _ _ _ | ___| | __ _| |_| |_ ___ _ __ / \ | | __ _ ___ _ __(_) |_| |__ _ __ ___ | |_ | |/ _` | __| __/ _ \ '_ \ / _ \ | |/ _` |/ _ \| '__| | __| '_ \| '_ ` _ \ | _| | | (_| | |_| || __/ | | | / ___ \| | (_| | (_) | | | | |_| | | | | | | | | |_| |_|\__,_|\__|\__\___|_| |_| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| |___/
        Throws:
        JsonLdError
      • generateNodeMap

        void generateNodeMap​(java.lang.Object element,
                             java.util.Map<java.lang.String,​java.lang.Object> nodeMap,
                             java.lang.String activeGraph)
                      throws JsonLdError
        Throws:
        JsonLdError
      • generateNodeMap

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

        java.lang.String generateBlankNodeIdentifier​(java.lang.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

        java.lang.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 java.util.List<java.lang.Object> frame​(java.lang.Object input,
                                                      java.util.List<java.lang.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​(java.lang.String id,
                                                 JsonLdApi.FramingContext state)
      • frame

        private void frame​(JsonLdApi.FramingContext state,
                           java.util.Map<java.lang.String,​java.lang.Object> nodes,
                           java.util.Map<java.lang.String,​java.lang.Object> frame,
                           java.lang.Object parent,
                           java.lang.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 java.lang.Object getFrameValue​(java.util.Map<java.lang.String,​java.lang.Object> frame,
                                               java.lang.String name)
      • getFrameFlag

        private java.lang.Boolean getFrameFlag​(java.util.Map<java.lang.String,​java.lang.Object> frame,
                                               java.lang.String name,
                                               boolean thedefault)
      • removeEmbed

        private static void removeEmbed​(JsonLdApi.FramingContext state,
                                        java.lang.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​(java.util.Map<java.lang.String,​JsonLdApi.EmbedNode> embeds,
                                             java.lang.String id)
      • filterNodes

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

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

        private static void addFrameOutput​(JsonLdApi.FramingContext state,
                                           java.lang.Object parent,
                                           java.lang.String property,
                                           java.lang.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 java.util.List<java.lang.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 java.util.List<java.lang.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 java.lang.Object normalize​(java.util.Map<java.lang.String,​java.lang.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.