-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.jq
More file actions
69 lines (69 loc) · 1.74 KB
/
Copy pathtransform.jq
File metadata and controls
69 lines (69 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
. as $all
| .["@context"] as $context
| $context
| to_entries
| map(select(.value == {"@type": "@link"}))
| [ .[].key ] as $links
| $all
| del(.["@context"])
| to_entries
| map(select( [.key] as $keys
| $links
| contains($keys)
| not ))
| from_entries
| with_entries(.key |= ( if . == "@id" then "id" else . end )) as $root
| $all
| del(.["@context"])
| [ ..
| objects
| to_entries
| map(select( [.key] as $keys
| $links
| contains($keys)))
| reduce .[] as $item ( []
; . + ( [ $item.value[]
| {"type": $item.key } + .
] ) )
] | reduce .[] as $item ( []
; . + $item )
| . as $nodes
| $nodes
| [ .[]
| to_entries
| map(select( [.key] as $keys
| $links
| contains($keys)
| not ))
| from_entries
| with_entries(.key |= ( if . == "@id" then "id" else . end ))
] as $nodes
| ( [ $root ] + $nodes ) as $nodes
| [ $all
| del(.["@context"])
| ..
| .["@id"]? as $id
| $links[]
| . as $link
| $all
| ..
| objects
| select(.["@id"] == $id)
| to_entries
| map(select( [.key] as $keys
| [ $link ]
| contains($keys)))
| [ .[].value[]
| { source : ( [ $nodes[] | .id ]| index($id) )
, type : $link
, target : ( .["@id"] as $target | [ $nodes[] | .id ]| index($target) )
} ]
] | map(select(length !=0))
| reduce .[] as $item ( []
; . + $item )
| . as $edges
| { directed: "true"
, graph: []
, nodes: $nodes
, links: $edges
}