yaml_ld.to_rdf.to_rdf
to_rdf(
document: JsonLdInput,
options: ToRDFOptions = DEFAULT_TO_RDF_OPTIONS,
) -> Dataset | str
Convert a *-LD document to RDF.
Example
to_rdf.py
from pprint import pprint
import yaml_ld
pprint(yaml_ld.to_rdf('pythagorean-theorem.yamlld'))
pythagorean-theorem.yamlld
"@context":
- https://json-ld.org/contexts/dollar-convenience.jsonld
- prov: http://www.w3.org/ns/prov#
- variable: https://variables.namespace/
=: https://math.namespace/equal
+: https://math.namespace/add
²: https://math.namespace/squared
$id: https://dbpedia.org/page/Pythagorean_theorem
prov:Entity:
=:
- +:
- ²: variable:a
- ²: variable:b
- ²: variable:c
python to_rdf.py
{'@default': [{'object': {'type': 'blank node', 'value': '_:b1'},
'predicate': {'type': 'IRI',
'value': 'https://math.namespace/equal'},
'subject': {'type': 'blank node', 'value': '_:b0'}},
{'object': {'type': 'blank node', 'value': '_:b4'},
'predicate': {'type': 'IRI',
'value': 'https://math.namespace/equal'},
'subject': {'type': 'blank node', 'value': '_:b0'}},
{'object': {'type': 'blank node', 'value': '_:b2'},
'predicate': {'type': 'IRI',
'value': 'https://math.namespace/add'},
'subject': {'type': 'blank node', 'value': '_:b1'}},
{'object': {'type': 'blank node', 'value': '_:b3'},
'predicate': {'type': 'IRI',
'value': 'https://math.namespace/add'},
'subject': {'type': 'blank node', 'value': '_:b1'}},
{'object': {'datatype': 'http://www.w3.org/2001/XMLSchema#string',
'type': 'literal',
'value': 'variable:a'},
'predicate': {'type': 'IRI',
'value': 'https://math.namespace/squared'},
'subject': {'type': 'blank node', 'value': '_:b2'}},
{'object': {'datatype': 'http://www.w3.org/2001/XMLSchema#string',
'type': 'literal',
'value': 'variable:b'},
'predicate': {'type': 'IRI',
'value': 'https://math.namespace/squared'},
'subject': {'type': 'blank node', 'value': '_:b3'}},
{'object': {'datatype': 'http://www.w3.org/2001/XMLSchema#string',
'type': 'literal',
'value': 'variable:c'},
'predicate': {'type': 'IRI',
'value': 'https://math.namespace/squared'},
'subject': {'type': 'blank node', 'value': '_:b4'}},
{'object': {'type': 'blank node', 'value': '_:b0'},
'predicate': {'type': 'IRI',
'value': 'http://www.w3.org/ns/prov#Entity'},
'subject': {'type': 'IRI',
'value': 'https://dbpedia.org/page/Pythagorean_theorem'}}]}