util
General utilities module.
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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
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
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
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
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
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
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
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
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
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
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
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
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |