Is there a syntax to define cyclic reference between anonymous nodes in Turtle RDF?
Asked Answered
K

1

10

I'm looking for a turtle syntax for calling the anonymous node who call an other anonymous node.

For example, I want to reproduce this code :

:Instance0 a Class0;
    :property0 :Instance1.

:Instance1 a Class1;
    :property1 :Instance2.

:Instance2 a Class2;
    :property2 :Instance1.

With something like :

:Instance0 a Class0;
    :property0 [
        a Class1;
        :property1 [
            a Class2;
            :property2 [
                ## The syntax to call the parent, the instance of :Class1
            ];
        ];
    ].

Is there any turtle syntax for this purpose?

Kaveri answered 23/2, 2015 at 14:58 Comment(1)
This is a good question. It's an easy answer ("no"), but it's something that I've heard lots of people ask for. In Common Lisp there's a cyclic object notation. E.g., a circular list can be written as '#1=(a b c . #1#), and that notation works for any repeated stuff, e.g., a list of length two with the element repeated can be '(#1=(a b c) #1#). I really wish Turtle had something like this.Sententious
P
6

RDF's data model is graph-based, not hierarchical, so there is no notion of parent/child relationships between resources, and hence no built-in syntax to refer to 'parent' nodes when nesting anonymous resource descriptions with the [] construct (which is really just syntactic sugar for grouping together a bunch of triples sharing the same anonymous subject).

That being said, Turtle's syntax is capable of serializing every conforming RDF graph. To achieve the graph structure that you describe, you must use the _: syntax rather than the more compact [] syntax for defining anonymous nodes.

Situations where you must use the _: syntax to manually assign blank node labels instead of using the [] convenience syntax include:

  • Cycles in a graph involving more than one anonymous node.
  • Multiple triples having the same anonymous node as the object.

The _: syntax allows you to manually assign a node identifier, which will allow you to refer to the blank node from the subject or object position of any arbitrary triple. The node identifier that you assign has no meaning outside the context of the Turtle document in which it appears, and so need not be globally unique. Nodes identified this way are still anonymous, because they cannot be globally referenced. However, every occurrence of the same blank node label inside the same document refers to the same resource, so the writer of the document is responsible for allocating blank node labels and tracking their usage within the same document.

Your document, then, would look something like:

:Instance0 a Class0;
    :property0 _:instance1.

_:instance1 a Class1;
    :property1 [
        a Class2;
        :property2 _:instance1;
    ].

See 2.6 RDF Blank Nodes in RDF 1.1 Turtle, Terse RDF Triple Language for more details.

Preconception answered 23/2, 2015 at 15:23 Comment(3)
But at end I'm obliged to manually define a blank node name _:instance1 to refer to it, even if it is the "parent" instance. Ok.Kaveri
Yes - the instance1 label has no significance outside the Turtle document itself, but the writer of the document is responsible for allocating blank node labels and tracking their usage. RDF is not a hierarchical data model, so there is no notion of a 'parent' resource.Preconception
That was the problematic concept. Thanks.Kaveri

© 2022 - 2024 — McMap. All rights reserved.