Package org.eclipse.rdf4j.rio.jsonld
Class JSONLDHierarchicalProcessor
- java.lang.Object
-
- org.eclipse.rdf4j.rio.jsonld.JSONLDHierarchicalProcessor
-
public class JSONLDHierarchicalProcessor extends java.lang.Object
Converts a JSON-LD object to a hierarchical form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JSONLDHierarchicalProcessor.TreeNode
-
Constructor Summary
Constructors Constructor Description JSONLDHierarchicalProcessor()
-
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 objectprivate 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)
-
-
-
Field Detail
-
ID
public static final java.lang.String ID
- See Also:
- Constant Field Values
-
GRAPH
public static final java.lang.String GRAPH
- See Also:
- Constant Field Values
-
-
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
- 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
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-farsortedNodes
- 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
-
-