Weather readings streamed as Jelly are normalized to SI units and placed in a SKOS hierarchy by rules that SHACL shapes specialize, and written back as Jelly.
readings-skos-qudt.ttl · readings-skos-qudt-shacl-in.ttl · readings-skos-qudt-shacl-out.ttl · data/readings-skos-qudt.jelly · output · playground
The question
Weather stations send six readings, one after another, as a Jelly stream of RDF Messages. Each message holds a value in the station’s own unit (degrees Celsius, kilometres per hour, hectopascal, millimetres) and a station code for what it measures, placed under a shared concept. What is each value in SI units, and which shared concepts lie above each station code?
Historical background
SKOS standardized concept schemes as RDF, and QUDT developed an RDF vocabulary for quantities and their units. Binary RDF streaming later supplied a transport for ongoing readings. The weather example brings the strands together by sending normalized readings and their SKOS concepts back out in Jelly. W3C, 2009 SKOS Reference · QUDT overview · Jelly serialization specification
What we tell eyemind
readings-skos-qudt.ttl is the background: a small
SKOS hierarchy of shared concepts,
such as
ex:airTemperature skos:broader ex:temperature .
ex:temperature skos:broader ex:weather .
data/readings-skos-qudt.jelly is the RDF Message Log, in binary Jelly. Its
first message, written as Turtle, is
ex:reading1 ex:phenomenon st:T2M .
ex:reading1 ex:value "21.5 Cel"^^cdt:temperature .
st:T2M skos:broader ex:airTemperature .
with values as CDT quantity literals in UCUM units.
readings-skos-qudt-shacl-in.ttl, given with --shacl-in, has closed input
shapes for a reading and for the place of a station code:
sh:property [
sh:path ex:value ;
sh:minCount 1 ;
sh:maxCount 1 ;
sh:nodeKind sh:Literal
] ;
readings-skos-qudt-shacl-out.ttl, given with --shacl-out, asks for each
reading’s normalized value and the transitive broader concepts of a code:
sh:path qconv:normalizedCdtLiteral ;
sh:path skos:broaderTransitive ;
--skos adds SKOS entailment, --qudt quantity normalization with
QUDT units, --stream-messages runs them for each
message on its own, with the hierarchy as background, and --to jelly writes
each message’s conclusions as a Jelly message.
What eyemind concludes
For each message, the triples the output shapes describe. The first message gives:
st:T2M skos:broaderTransitive ex:airTemperature .
st:T2M skos:broaderTransitive ex:temperature .
st:T2M skos:broaderTransitive ex:weather .
ex:reading1 qconv:normalizedCdtLiteral "294.65 K"^^cdt:temperature .
and the wind reading of the second message, 54 km/h, becomes
ex:reading2 qconv:normalizedCdtLiteral "15.0 m/s"^^cdt:speed .
Six messages give 22 triples, written as one Jelly stream of six messages.
How the shapes select the rules
The shapes are contracts, not validation inputs. Each property shape of an input shape becomes a pattern of message triples, and eyemind specializes the SKOS and QUDT rules to those patterns when it loads: a rule that no message triple can reach goes, and the rest are unfolded against the background. From the output shapes, only rules that can contribute to a property they ask for stay. Each message then takes under 400 inferences; without the shapes it takes about 1500.
QUDT compiles unit facts from the units a graph uses. Degrees Celsius, km/h, hectopascal and millimetres are QUDT’s builtin units, so every message uses the specialized program; a message with a unit that needs facts the background lacks runs the whole program, compiled with its own units.
The output shapes are also an output contract: only triples of their paths, with the values they allow, are written.
No proof for streamed messages
Each message runs independently and is discarded before the next, so this example saves its output only. Replay a message log to prove and check its conclusions.
Try it
From the repository root:
node bin/eyemind.js --skos --qudt --stream-messages --shacl-in examples/readings-skos-qudt-shacl-in.ttl --shacl-out examples/readings-skos-qudt-shacl-out.ttl examples/readings-skos-qudt.ttl examples/data/readings-skos-qudt.jelly
node bin/eyemind.js --skos --qudt --to jelly --stream-messages --shacl-in examples/readings-skos-qudt-shacl-in.ttl --shacl-out examples/readings-skos-qudt-shacl-out.ttl examples/readings-skos-qudt.ttl examples/data/readings-skos-qudt.jelly > /tmp/readings.jelly
The first command writes Turtle, the second the saved Jelly output. --stats
reports, for each message, whether its rules were specialized and how many
inferences it took.
