PROV-JSON
Export a KnowledgeGraph to, and import it from, PROV-JSON.
PROV-JSON <https://www.w3.org/submissions/prov-json/>_ is a standard JSON
serialisation of the W3C PROV data model <https://www.w3.org/TR/prov-dm/>_.
The generic mapping is:
- a node of type
activity->prov:Activity; typeagent->prov:Agent; any other type ->prov:Entity; - a node's
typebecomesprov:type(as ack:qualified name), itstextand each property becomeck:attributes; - edges map to the matching PROV relation (
used/generated_by/derived_from/attributed_to); every other edge type has no PROV equivalent and is exported aswasInfluencedBycarrying ack:predicateattribute so the original relationship is preserved.
Import is best-effort and lossy (node ids/types/text/properties survive, but node timestamps are not carried by PROV); the stable invariant is that re-exporting an imported graph reproduces the document.
dumps_prov(graph, *, indent=2)
¶
Serialise a knowledge graph to a PROV-JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
KnowledgeGraph
|
The graph to export. |
required |
indent
|
int
|
Indentation passed to :func: |
2
|
Returns:
| Type | Description |
|---|---|
str
|
The PROV-JSON document as a string. |
Source code in src/ideagraph/kg/prov.py
141 142 143 144 145 146 147 148 149 150 151 152 | |
from_prov(document)
¶
Reconstruct a knowledge graph from a PROV-JSON document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
dict[str, Any]
|
A PROV-JSON document as produced by :func: |
required |
Returns:
| Type | Description |
|---|---|
KnowledgeGraph
|
The reconstructed graph. External endpoint stubs (global ids or the |
KnowledgeGraph
|
generic |
KnowledgeGraph
|
as nodes. |
Source code in src/ideagraph/kg/prov.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
loads_prov(text)
¶
Deserialise a knowledge graph from a PROV-JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
A PROV-JSON document as produced by :func: |
required |
Returns:
| Type | Description |
|---|---|
KnowledgeGraph
|
The reconstructed graph. |
Source code in src/ideagraph/kg/prov.py
220 221 222 223 224 225 226 227 228 229 230 | |
to_prov(graph)
¶
Convert a knowledge graph to a PROV-JSON document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
KnowledgeGraph
|
The graph to export. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A PROV-JSON document as a plain dictionary. |
Source code in src/ideagraph/kg/prov.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |