buildBuilding a chain
A semantic process in pgRDF is a chain of verbs. This page is the method for going from "what do I need?" to a chain you can run.
The order verbs run in
Import ─▶ Seal ─▶ Carve ─▶ Reason ─▶ Validate ─▶ Query ─▶ UnloadA chain is a subset of this line, kept in this order:
- Import always comes first.
- Seal can appear twice: after Import, to freeze a source you're about to carve from, and after Validate, to freeze a finished result. Reasoning refuses on a locked graph, so seal a graph only after you've reasoned over it.
- Carve appears only when the source is too big to reason over or validate in one session.
- Reason, Validate and Query are the semantic work.
- Unload comes last, once you no longer need a graph in the database.
The method — design backwards
- Name the output. Does the caller need solution rows (Query), a conformance report (Validate), or entailed facts stored in the graph (Reason)? That fixes where the chain ends.
- Work backwards to the inputs. Validate needs a shapes graph, loaded into a graph of its own. If the shapes constrain facts that follow from the ontology, Reason must run first. Everything needs Import. Each input adds a verb to the left.
- Decide whether to carve. Does the graph fit your hardware for Reason and Validate? If yes, skip Carve. If no, load everything, carve the slice you need, and reason over the slice. This is the one decision that changes the shape of the chain.
- Decide what to keep. Seal a result that other people will rely on, so it can't change under them and its fingerprint is on record. Unload graphs you've finished with.
- Write the calls. Walk the chain left to right and write one call per verb. Each verb page has the syntax.
Worked example
"Validate an ontology against SHACL shapes after OWL 2 RL reasoning, then freeze the result."
- Output → a conformance report, then a frozen graph. The chain ends Validate → Seal.
- Backwards → the shapes constrain entailed facts, so Reason runs before Validate. Everything needs Import.
- Carve? → say the ontology is a few million triples, small enough to reason over in one session. No Carve.
- Keep → seal the validated graph.
- Chain →
Import → Reason → Validate → Seal:
sql
-- Import: the data and the shapes go into separate graphs
SELECT pgrdf.add_graph('http://example.org/ontology');
SELECT pgrdf.add_graph('http://example.org/shapes');
SELECT pgrdf.load_turtle('/data/ontology.ttl', pgrdf.graph_id('http://example.org/ontology'));
SELECT pgrdf.load_turtle('/data/shapes.ttl', pgrdf.graph_id('http://example.org/shapes'));
-- Reason
SELECT pgrdf.materialize(pgrdf.graph_id('http://example.org/ontology'), 'owl-rl');
-- Validate: carry on only if this is true
SELECT pgrdf.validate(pgrdf.graph_id('http://example.org/ontology'),
pgrdf.graph_id('http://example.org/shapes')) -> 'conforms';
-- Seal
SELECT pgrdf.lock_graph(pgrdf.graph_id('http://example.org/ontology'), 'validated release');
SELECT pgrdf.graph_digest(pgrdf.graph_id('http://example.org/ontology'));load_turtle reads files on the database server, not on your client machine.
This is the Load → Validate → Query pattern with a seal on the end. Had the source been too large to reason over, step 3 would have added a carve. See Ingest → Carve → Reason.
See also
- Choosing a process — pick the pattern from your goal and graph size.
- The patterns — the four worked chains.
- Overview — the seven verbs and how each one scales.