The serialization of Nested Named Graphs, NNG, is defined as an extension of TriG. Its datatype is application/nng
. It provides the following functionality on top of TriG:
- it supports the nesting of named graphs
- it adds syntactic sugar for graph literals with specific semantics to support three common variants of citation semantics
- it provides a slot to support configurable semantics
- it offers a self-reference operator named
THIS
to ease the work with nested graphs While graph literals are a proposed new datatype, everything else is just syntactic sugar and can be expressed in standard TriG via a few more triples.
A nested named graph
:Y {
:X { :a :b :c . }
:d :e .
}
maps to standard RDF 1.1 named graphs by applying the nng:transcludes
property - e.g. in TriG:
:X { :a :b :c . }
:Y { :Y nng:transcludes :X .
:X :d :e .
}
See Nesting Graphs via Transclusion for more detail about the underlying mechanism.
Nested graphs are named like standard RDF 1.1 named graphs, either explicitly or by a blank node. The square brackets syntax doesn't support full property lists, but a succinct subset. It can encode either a semantics annotation to specify a semantics, like e.g.
[nng:APP] { :s :p :o . }
or it can encode a name and a semantics:
[ :X nng:APP] { :x :y :z . }
Mapped to standard TriG the two preceding examples would be expressed as:
<> nng:transcludes _:nng1 ,
:X .
_:nng1 nng:semantics nng:APP .
:X nng:semantics nng:APP .
_:nng1 { :s :p :o . }
:X { :x :y :z . }
Note that specifying a semantics on a regular named graph is not advisable without support by out-of-band arrangements. Only graph literals, discussed below, support this mechanism with the necessary predictability with RDF proper.
A nested named graph may be nested without any further annotations, with annotations directly attached or with annotations as extra statements, e.g.:
:Y {
:X { :a :b :c } # transcluded and annotated
:d :e .
:Z { :u :v :w } . # transcluded, not annotated
:X :p :q . # transcluded first, annotated later
}
Mapped to TriG:
:X { :a :b :c }
:Y {
:Y nng:transcludes :X ,
:Z .
:X :d :e ;
:p :q .
}
:Z { :u :v :w }
NNG provides an RDF graph literal datatype and supports three kinds of citations with specific variants of syntactic sugar. The bare datatype is encoded as a literal with datatype declaration, e.g.
":a :b :c"^^nng:ttl
Three different kinds of citation semantics are supported: records, reports and quotes. Prepending a name to a graph literal allows to omit the datatype declaration and makes the graph literal a quote (differentiating the two is necessary to support other semantics discussed in the next section). Adding curly braces inside or outside the quote signs modifies the semantics of the quote as described in the section on citation semantics.
:Alice :said [] << :a :b :c . >> # Quote - unasserted, referentially opaque
:Alice :said [] {" :a :b :c . "} # Record - asserted, referentially opaque
:Alice :said [] "{ :a :b :c . }" # Report - unasserted, referentially transparent
[TODO]
The workbook doesn't yet implement all variants of this syntactic sugar
This notation is syntactic sugar for the following expanded form which is valid in NNG as well as in TriG:
:Alice :said [ nng:quotes ":a :b :c"^^nng:ttl ] .
:Alice :said [ nng:records ":a :b :c"^^nng:ttl ] .
:Alice :said [ nng:reports ":a :b :c"^^nng:ttl ] .
The different forms of quotation could as well be encoded, for anonymous graph, as follows:
:Alice :said [nng:Quote] { :a :b :c . } .
:Alice :said [nng:Record] { :a :b :c . } .
:Alice :said [nng:Report] { :a :b :c . } .
or, for named graphs:
:Alice :said [:X nng:Quote] { :a :b :c . } .
:Alice :said [:X nng:Record] { :a :b :c . } .
:Alice :said [:X nng:Report] { :a :b :c . } .
From this follows a more general form, that allows to specify and apply any kind of semantics one may find useful:
:Alice :said [ex:MySemantics] { :s :p :o . } .
The section on Configurable Semantics sketches some use cases and an example vocabulary to that effect. Notation3 provides an arguably more mature approach that should be easy to implement with this mechanism.
NNG introduces a new THIS
keyword to allow a named graph to reference itself.
# VOCABULARY
THIS a rdfs:Resource ;
rdfs:comment "A self-reference from inside a (nested) graph to itself" .
This provides a bit of convenience when transcluding graphs, especially when they are named by blank nodes:
:G { :a :b :c }
[] { THIS nng:transcludes :G .
:G :d :e }
It can also be used to include annotations on a nested graph in the nested graph itself, e.g.:
[]{
:s :p :o .
THIS :source :X .
}
However, a bit of care is needed when using THIS together with fragment identifiers. In the following example the annotation per definition applies to the subjects of each statement in the graph, i.e. also to THIS, leading to a rather nonsensical annotation:
[]{
:Alice :buys :Car .
THIS nng:domain [ :age 20 ] .
}
The obvious solution is to ignore such self-referential annotations.
THIS
encourages a modelling stye where annotations are kept very close to the annotated term, statement or graph. This localization of annotations can help structuring and navigation of annotated data.