TriG is a Turtle-based serialization syntax for RDF datasets. The only implementation I know of is in NG4J. An example:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
{
<http://example.org/bob.rdf> dc:publisher "Bob" .
<http://example.org/alice.rdf> dc:publisher "Alice" .
}
<http://example.org/bob.rdf> {
[] foaf:name "Bob"; foaf:mbox <mailto:bob@example.org> .
}
<http://example.org/alice> {
[] foaf:name "Alice"; foaf:mbox <mailto:alice@example.org> .
}
This is an RDF dataset. The default graph contains metadata about the two named graphs. TriG is quite useful to write down small examples like this.
The point of this post is not to promote this nice syntax, but to act as a reminder about some minor syntactical issues with the current TriG spec. I’ve culled them from several email threads. This post summarizes my position, and I should probably prod Chris (who maintains the spec) to do something about it at some point in the future.
Namespace declarations
TriG currently allows namespace declarations (the @prefix lines) before, after and between graphs, but not within. I argue that namespaces should be allowed within graphs. This would make any valid Turtle file a valid TriG graph and vice versa, which is a Good Thing for several reasons (simpler spec, easier implementation, easier authoring).
Graph naming
TriG originally didn’t allow unnamed graphs, but after the RDF dataset was adopted for SPARQL, TriG was changed to allow a default graph.
Chris has gone on record saying that these syntactic variations should be allowed for named graphs:
<uri> { ...triples... }
<uri> :- { ...triples... }
And this is for the default graph:
{ ...triples...}
Currently, the spec also allows this:
:- { ...triples... }
This is a bug.
N3 compatibility
There was some push from Jeremy Carroll to maintain compatibility with Notation 3‘s syntax for formulae, which also uses curly brackets to denote graph-like structures, so we discussed adding some more options for named graphs:
<uri> { ...triples... } .
<uri> :- { ...triples... } .
<uri> = { ...triples... }
<uri> = { ...triples... } .
and for the default graph:
{ ...triples... } .
But of all these, only two are actually syntactically valid N3:
<uri> :- { ...triples... } .
<uri> = { ...triples... } .
So, if we want to align the spec more closely to N3, then we should allow only these two, and maybe this one
<uri> = { ...triples... }
because of symmetry.
(N3’s non-RDF (non-Turtle) features like formulae are quite obscure, and I’m not really convinced that compatibility with them is worth the additional complexity.)