Ontology graph generators
Scripts that compare an ontology file in ontology/ with its named graph in Artsdata’s GraphDB, and write the SPARQL to bring the graph up to date.
Each file ontology/<name>.ttl lives in the graph http://kg.artsdata.ca/culture-creates/artsdata-data-model/<name>.
artsdata-ontology.ttl is not loaded by the Push Ontology file workflow. Its graph is updated in place with gen_update.py. The SKOS vocabularies are still loaded by that workflow, but the scripts work for them too.
Setup
cd ontology/generators
pip install -r requirements.txt
Update the graph after changing the file
- Bump
owl:versionInfoanddcterms:modifiedin the file, and add a# V x.y.zentry to the changelog comment at the top. - Generate the update:
python3 gen_update.py ../artsdata-ontology.ttl > update.ruThe script downloads the live graph, writes
DELETE DATAfor triples that are no longer in the file andINSERT DATAfor new ones, and checks that the update applied to that download gives exactly the file. It prints a summary to stderr, or says the graph already matches. - Paste
update.ruinto the GraphDB Workbench SPARQL editor (repositoryartsdata) and run it. Alternatively, POST it with an account that can write:curl -u <user> -H 'Content-Type: application/sparql-update' \ --data-binary @update.ru https://db.artsdata.ca/repositories/artsdata/statements - Confirm with
gen_update.pyagain: it should report that the graph already matches.
The update is an exact diff against the graph at download time, so run it soon after generating it. If the graph changed in between, DELETE DATA skips triples that are gone and the old values can remain next to the new ones.
Options:
--graph URItargets a different graph, e.g. on staging.--live FILE.ntdiffs against a saved N-Triples copy instead of downloading the graph.
Compare without changing anything
python3 gen_diff.py ../artsdata-ontology.ttl > diff.rq
curl -H 'Accept: text/csv' -H 'Content-Type: application/sparql-query' \
--data-binary @diff.rq https://db.artsdata.ca/repositories/artsdata
diff.rq is a read-only SELECT with the file’s triples written into it. Each row is tagged only in file or only in graph.
Notes
- Use the GraphDB endpoint for large queries. Send these queries to
https://db.artsdata.ca/repositories/artsdata.https://query.artsdata.ca/queryforwards requests as GET and rejects large queries with “414 Request-URI Too Large”. - Load metadata is left alone. A Databus load adds triples to the graph that are not in the file:
- a SHACL validation report (blank nodes)
- dataset and provenance metadata whose subject is the graph URI or
<graph>#Activity
gen_update.pynever deletes these, andgen_diff.pylists them asonly in graph. - No blank nodes in the files. The scripts assume the ontology files have no blank nodes;
gen_update.pystops if one does.