Package org.eclipse.rdf4j.rio.jsonld
Class JSONLDHierarchicalProcessor
java.lang.Object
org.eclipse.rdf4j.rio.jsonld.JSONLDHierarchicalProcessor
Converts a JSON-LD object to a hierarchical form
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Object
expandContextInDepth
(Object input) Transforms a JSON-LD object to a more human-readable hierarchical form.private static Object
expandInDepth
(Object input) Expands the JSON-LD object to a hierarchical shape.static Object
fromJsonLdObject
(Object jsonLdObject) Converts a JSON-LD object to a hierarchical JSON-LD objectprivate static String
getNextRoot
(Set<String> visited, List<String> sortedNodes) Returns the next node to be a root.getNodesOrder
(Map<String, Object> graph) Returns the nodes in a JSON-LD object ordered by the number of their subnodes (predicates in which the nodes are subjects)
-
Field Details
-
ID
- See Also:
-
GRAPH
- See Also:
-
-
Constructor Details
-
JSONLDHierarchicalProcessor
public JSONLDHierarchicalProcessor()
-
-
Method Details
-
fromJsonLdObject
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
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
Transforms a JSON-LD object to a more human-readable hierarchical form.The steps performed are
- Take all triples which will take part of the processing and add them to a separate map
- Create a separate list the triples sorted by number of predicates in the descending order
- Select a root to start
- Take this root from the graph and start a DFS traversing. For each traversed node
- Mark this node as visited
- Find all sub-nodes (effectively objects in triples in which the current node is subject)
- 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
- 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
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-farsortedNodes
- contains the nodes in a specific order. This list will get modified by the method!- Returns:
- root for the next tree
-
getNodesOrder
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
-