jsonld.normalize()¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_
|
the JSON-LD input to normalize. |
required | |
options
|
NormalizeOptions | None
|
optional processing options; see Options below. |
None
|
Returns:
| Type | Description |
|---|---|
|
the normalized output. |
Options¶
algorithm
instance-attribute
¶
The algorithm to use (default: RDFC10).
documentLoader
instance-attribute
¶
The document loader (default: the global default document loader).
extractAllScripts
instance-attribute
¶
True to extract all JSON-LD script elements from HTML, False to extract just the first (default: False).
format
instance-attribute
¶
The format if output is a string: application/n-quads for N-Quads.
hashAlgorithm
instance-attribute
¶
The hashing algorithm for RDFC10 (default: SHA256).
inputFormat
instance-attribute
¶
The format if input is not JSON-LD: application/n-quads for N-Quads.
maxPermutations
instance-attribute
¶
Maximum Hash N-Degree Quads permutations before aborting canonicalization to prevent dataset poisoning, or None for no limit (default: 100000).
outputMap
instance-attribute
¶
True to return a blank node identifier map instead of the normalized dataset (default: False).
processingMode
instance-attribute
¶
Either json-ld-1.0 or json-ld-1.1 (default: json-ld-1.1).
RDFC10 is the default algorithm in PyLD 4. Use URDNA2015 or URGNA2012
explicitly when an integration requires the older canonicalization output.
Examples¶
Normalizing RDF as canonical N-Quads¶
Example normalize.py
from pyld import jsonld
doc = {
"@type": "http://schema.org/Person",
"http://schema.org/name": "Manu Sporny",
"http://schema.org/url": {"@id": "http://manu.sporny.org/"},
"http://schema.org/image": {
"@id": "http://manu.sporny.org/images/manu.png"
},
}
# Normalize with RDFC10
normalized = jsonld.normalize(
doc,
{"format": "application/n-quads"},
)
print(normalized)
# Normalize with URDNA2015
normalized = jsonld.normalize(
doc,
{"algorithm": "URDNA2015", "format": "application/n-quads"},
)
print(normalized)
_:c14n0 <http://schema.org/image> <http://manu.sporny.org/images/manu.png> .
_:c14n0 <http://schema.org/name> "Manu Sporny" .
_:c14n0 <http://schema.org/url> <http://manu.sporny.org/> .
_:c14n0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
_:c14n0 <http://schema.org/image> <http://manu.sporny.org/images/manu.png> .
_:c14n0 <http://schema.org/name> "Manu Sporny" .
_:c14n0 <http://schema.org/url> <http://manu.sporny.org/> .
_:c14n0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
Outputting the Identifier Map of the canonicalization process (RDFC1.0)¶
Example normalize_output_map.py
import json
from pyld import jsonld
doc = {
"@type": "http://schema.org/Person",
"http://schema.org/name": "Manu Sporny",
"http://schema.org/url": {"@id": "http://manu.sporny.org/"},
"http://schema.org/image": {
"@id": "http://manu.sporny.org/images/manu.png"
},
}
identifier_map = jsonld.normalize(
doc,
{"algorithm": "RDFC10", "outputMap": True},
)
print(json.dumps(identifier_map, indent=2))