Class JSONLDHierarchicalProcessor


  • public class JSONLDHierarchicalProcessor
    extends java.lang.Object
    Converts a JSON-LD object to a hierarchical form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String GRAPH  
      static java.lang.String ID  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.Object expandContextInDepth​(java.lang.Object input)
      Transforms a JSON-LD object to a more human-readable hierarchical form.
      private static java.lang.Object expandInDepth​(java.lang.Object input)
      Expands the JSON-LD object to a hierarchical shape.
      static java.lang.Object fromJsonLdObject​(java.lang.Object jsonLdObject)
      Converts a JSON-LD object to a hierarchical JSON-LD object
      private static java.lang.String getNextRoot​(java.util.Set<java.lang.String> visited, java.util.List<java.lang.String> sortedNodes)
      Returns the next node to be a root.
      private static java.util.List<java.lang.String> getNodesOrder​(java.util.Map<java.lang.String,​java.lang.Object> graph)
      Returns the nodes in a JSON-LD object ordered by the number of their subnodes (predicates in which the nodes are subjects)
      • Methods inherited from class java.lang.Object

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

      • JSONLDHierarchicalProcessor

        public JSONLDHierarchicalProcessor()
    • Method Detail

      • fromJsonLdObject

        public static java.lang.Object fromJsonLdObject​(java.lang.Object jsonLdObject)
        Converts a JSON-LD object to a hierarchical JSON-LD object
        Parameters:
        jsonLdObject - JSON-LD object to be converted. Gets modified during processing
        Returns:
        hierarchical JSON-LD object
      • expandInDepth

        private static java.lang.Object expandInDepth​(java.lang.Object input)
        Expands the JSON-LD object to a hierarchical shape.

        As the first level of nodes in the object can be either a triple or a whole graph we first expand the graph nodes and after that we expand the default graph.

        The different graphs are processed independently to keep them in insulation.

        Parameters:
        input - the JSON-LD object. Gets modified during processing.
        Returns:
      • expandContextInDepth

        private static java.lang.Object expandContextInDepth​(java.lang.Object input)
        Transforms a JSON-LD object to a more human-readable hierarchical form.

        The steps performed are

        1. Take all triples which will take part of the processing and add them to a separate map
        2. Create a separate list the triples sorted by number of predicates in the descending order
        3. Select a root to start
        4. Take this root from the graph and start a DFS traversing. For each traversed node
          1. Mark this node as visited
          2. Find all sub-nodes (effectively objects in triples in which the current node is subject)
          3. Expand the sub-nodes (replace them with their full version) and add them to the traversing if the following conditions are met
            • sub-node is IRI or BlankNode
            • sub-node has not been expanded already in the current path
            • sub-node is not the same as it's parent
        5. If the visited list shows there are still unvisited nodes choose a new root from the list of sorted nodes and start another traversal
        Parameters:
        input - JSON-LD object. Gets modified during processing
        Returns:
        the hierarchical JSON-LD object
      • getNextRoot

        private static java.lang.String getNextRoot​(java.util.Set<java.lang.String> visited,
                                                    java.util.List<java.lang.String> sortedNodes)
        Returns the next node to be a root. Chooses the first non-visited node from the sortedNodes list.
        Parameters:
        visited - contains the visited nodes so-far
        sortedNodes - contains the nodes in a specific order. This list will get modified by the method!
        Returns:
        root for the next tree
      • getNodesOrder

        private static java.util.List<java.lang.String> getNodesOrder​(java.util.Map<java.lang.String,​java.lang.Object> graph)
        Returns the nodes in a JSON-LD object ordered by the number of their subnodes (predicates in which the nodes are subjects)
        Parameters:
        graph - JSON-LD object
        Returns:
        List with the nodes' ids