util
General utilities module.
canonicalize_graph(src)
Creates a copy of a graph whose blank node labels are derived from the graph's contents
(see to_canonical_graph) instead of being randomly
minted on each run, so that serializing it produces the same output for the same
triples. Namespace bindings are preserved (except for auto-generated nsN ones, which the
serializer assigns again), and the source graph is left untouched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Graph
|
the source Graph |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
a new, writable Graph with canonical blank node labels |
Source code in ogc/na/util.py
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 | |
copy_triples(src, dst=None)
Copies all triples from one graph onto another (or a new, empty Graph if none is provided).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Graph
|
the source Graph |
required |
dst
|
Optional[Graph]
|
the destination Graph (or |
None
|
Returns:
| Type | Description |
|---|---|
Graph
|
the destination Graph |
Source code in ogc/na/util.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
dump_yaml(content, filename=None, ignore_alises=True, **kwargs)
Generates YAML output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
Any
|
content to convert to YAML. |
required |
filename
|
str | Path | None
|
optional filename to dump the content into. If None, string content will be returned. |
None
|
kwargs
|
other args to pass to |
{}
|
Source code in ogc/na/util.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
entail(g, rules, extra=None, inplace=True)
Performs SHACL entailments on a data Graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
input data Graph |
required |
rules
|
Graph
|
SHACL Graph for entailments |
required |
extra
|
Optional[Graph]
|
Graph with additional ontological information for entailment |
None
|
inplace
|
bool
|
if |
True
|
Returns:
| Type | Description |
|---|---|
Graph
|
the resulting Graph |
Source code in ogc/na/util.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
fix_nest(ctx)
fix nested @context inside @nest terms it should be ok, but our tooling of interest (json-ld playground, rdflib) do not support it see: https://github.com/json-ld/json-ld.org/issues/737
Source code in ogc/na/util.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
is_url(url, http_only=False)
Checks whether a string is a valid URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
the input string |
required |
http_only
|
bool
|
whether to only accept HTTP and HTTPS URLs as valid |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in ogc/na/util.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
load_yaml(filename=None, content=None, url=None, safe=True)
Loads a YAML file either from a file, a string or a URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path | None
|
YAML document file name |
None
|
content
|
Any | None
|
str with YAML contents |
None
|
url
|
str | None
|
url from which to retrieve the contents |
None
|
safe
|
bool
|
whether to use safe YAMl loading |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
a dict with the loaded data |
Source code in ogc/na/util.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
merge_contexts(a, b)
Merges two JSON-lD contexts, updating the first one passed to this function (and returning it).
Source code in ogc/na/util.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
parse_resources(src)
Join one or more RDF documents or Graph's together into a new Graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Union[str, Graph, list[Union[str, Graph]]]
|
a path or Graph, or list thereof |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
a union Graph |
Source code in ogc/na/util.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
validate(g, shacl_graph, extra=None, **kwargs)
Perform SHACL validation on a data Graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
input data Graph |
required |
shacl_graph
|
Graph
|
SHACL graph for validation |
required |
extra
|
Optional[Graph]
|
Graph with additional ontological information for validation |
None
|
Returns:
| Type | Description |
|---|---|
ValidationReport
|
the resulting [][ogc.na.validation.ValidationReport] |
Source code in ogc/na/util.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |