On Mon, Jun 07, 2004 at 10:58:52AM -0400, Kendall Clark wrote:
| I'm trying to add a YAML serialization to the Python RDF library,
| rdflib(.net). I've seen some other attempts to do a very XML-like
| serialization of RDF in YAML, which I didn't really think much of.
Something to keep in mind is that YAML is a "graph" model, and thus
once you mark a anchor a node, you can reuse it later. I'm not sure
if this helps you, but it is something to consider.
| I'm trying to represent an RDF model as a set of triples, where a triple
| is represented as a mapping (a Python dictionary) like this:
|
| s: <subject>
| p: <predicate>
| o: <object>
Seems as good as any. An alternative model:
<subject>:
<predicate>:
<object>
Since the object can actually be the subject, you could
then write:
<subject-one>:
<predicate>:
<object-and-subject>:
<another-predicate>:
<object>
I think of this as a white/black tree sort of structure,
where the odd-levels in the tree are subject/objects (nouns),
and the even-levels are predicates (verbs). But really,
this has its own set of good and bad things.
| I'm wondering whether this is good YAML style. I'm also struggling a
| bit with the Tag typing of the atoms of a triple. The builtin YAML
| types like !str, !int, !float are easy enough:
|
| ?
| s: ...
| p: ...
| o: !str "12" (or: o: !int 12)
*nods*
| But what I really want is a YAML builtin called !uri... There doesn't
| seem to be such a thing, so I guess I'm asking for such a thing and
| volunteering to write whatever needs to be written.
Sure, that sounds great. Let's call the type !uri and it would
comply with RFC 2396.
| In the meantime, I'm doing this, and I'm wondering if it's remotely
| legal:
|
| rdf-model: !set
| ?
| s: !w3.org,YYYY-MM:bnode _:FKKsHaJJ1
| p: !w3.org,YYYY-MM:uri http://foo.bar/blaz
| o: !str "Ronnie's dead"
If you agree to get concensus, let's make a "vocabulary" for RDF,
!rdf/uri
which will be a short-hand for:
tag:rdf.yaml.org,2002:uri
| Two issues: the YAML spec seems to suggest that I can only coin new
| Tags if I own the domain; I don't own "w3.org" but it seems absurd to
| coin Tags for URIs and blank nodes using *my* domain... I also
| understand that YYYY-MM needs to be actual values, but I can't tell
| from the spec whether they are the dates of the Tag coining or some
| other date...?
Well, we explictly reference 'taguri' in the specification, which
states that you cannot use domain,year unless you have permission
of the individual who owned the domain during the particular
date in question (if you leave off the month, it is January 1st).
| At any rate, here's a full example of the serialization as I have it
| so far; it contains support from two extensions of the RDF model which
| are likely to catch on soon -- named and asserted graphs (if you want
| to know what that means, lemme know. I don't want to take up too much
| YAML time with RDF details).
|
| --- %YAML:1.0
| asserted: true
| name: http://foobar
|
| rdf-model: !set
| ?
| s: !w3.org,YYYY-MM:bnode _:cwtAGnDy1
| p: !w3.org,YYYY-MM:uri http://xmlns.com/foaf/0.1/nick
| o: !str "donna"
|
| ?
| s: !w3.org,YYYY-MM:bnode _:cwtAGnDy1
| p: !w3.org,YYYY-MM:uri http://xmlns.com/foaf/0.1/mbox
| o: !str "donna@..."
|
| ?
| s: !w3.org,YYYY-MM:bnode _:cwtAGnDy1
| p: !w3.org,YYYY-MM:uri http://www.w3.org/1999/02/22-rdf-syntax-ns#type
| o: !w3.org,YYYY-MM:uri http://xmlns.com/foaf/0.1/Person
|
| ?
| s: !w3.org,YYYY-MM:bnode _:cwtAGnDy1
| p: !w3.org,YYYY-MM:uri http://xmlns.com/foaf/0.1/name
| o: !str "Donna Fales"
--- %YAML:1.0 !rdf/model
asserted: true
name: http://foobar
model:
? !rdf/bnode _:cwtAGnDy1
:
? !rdf/uri http://xmlns.com/foaf/0.1/nick
: !str donna
? !rdf/uri http://xmlns.com/foaf/0.1/mbox
: !str donna@...
? !rdf/uri http://www.w3.org/1999/02/22-rdf-syntax-ns#type
: !rfd/uri http://xmlns.com/foaf/0.1/Person
? !rdf/uri http://xmlns.com/foaf/0.1/name
: !str Donna Fales
Or, for now (till you have a spec we can put up at
http://rdf.yaml.org) you can use something like...
--- %YAML:1.0 !monkeyfist.com,2004-06/kendall/rdf/^model
asserted: true
name: http://foobar
model:
? !^bnode _:cwtAGnDy1
:
? !^uri http://xmlns.com/foaf/0.1/nick
: !str donna
? !^uri http://xmlns.com/foaf/0.1/mbox
: !str donna@...
? !^uri http://www.w3.org/1999/02/22-rdf-syntax-ns#type
: !^uri http://xmlns.com/foaf/0.1/Person
? !^uri http://xmlns.com/foaf/0.1/name
: !str Donna Fales
Hope this helps. YAML is "functional", when thinking about
your problems it helps to consider what your functions are...
in this case, they are predicates and nouns (objects/subjects).
Best,
Clark
|