[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Visionaries] RDF/YAML
From: |
Peter Minten |
Subject: |
[Visionaries] RDF/YAML |
Date: |
Sun, 22 Jun 2003 15:15:35 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.4) Gecko/20030529 |
Hi folks,
I did some experimenting with expressing RDF in YAML and it seems to work. A few
examples:
##--- RDF, http://www.w3.org/TR/rdf-primer/#example3 ---##
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:exterms="http://www.example.org/terms/">
<rdf:Description rdf:about="http://www.example.org/index.html">
<exterms:creation-date>August 16, 1999</exterms:creation-date>
</rdf:Description>
<rdf:Description rdf:about="http://www.example.org/index.html">
<exterms:language>English</exterms:language>
</rdf:Description>
</rdf:RDF>
##--- YAML ---##
--- %YAML:1.0
#note that YAML doesn't have namespaces AFAIK, so I invented a notation:
#the slash is like the colon in xml
rdf/rdf:
__namespaces__:
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
exterms: "http://www.example.org/terms/"
rdf/Description:
rdf/about: "http://www.example.org/index.html"
exterms/creationdate: August 16, 1999
rdf/Description:
rdf/about: "http://www.example.org/index.html"
exterms/language: English
---
RDF/YAML also supports anonymous nodes in two fashions:
##--- RDF, http://www.w3.org/TR/rdf-primer/#example6 ---##
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:exterms="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">
<dc:title>RDF/XML Syntax Specification (Revised)</dc:title>
<exterms:editor rdf:nodeID="abc"/>
</rdf:Description>
<rdf:Description rdf:nodeID="abc">
<exterms:fullName>Dave Beckett</exterms:fullName>
<exterms:homePage rdf:resource="http://purl.org/net/dajobe/"/>
</rdf:Description>
</rdf:RDF>
##--- YAML, 1 ---##
--- %YAML:1.0
rdf/rdf:
__namespaces__:
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
dc: "http://purl.org/dc/elements/1.1/"
exterms: "http://example.org/stuff/1.0/"
rdf/Description:
rdf/about: "http://www.w3.org/TR/rdf-syntax-grammar"
dc/title: "RDF/XML Syntax Specification (Revised)"
exterms/editor: !rdf/nodeID abc
rdf/Description:
rdf/nodeID: "abc"
exterms/fullName: Dave Beckett
exterms/homePage: !rdf/resource "http://purl.org/net/dajobe/"
---
##--- YAML, 2 ---##
--- %YAML:1.0
rdf/rdf:
__namespaces__:
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
dc: "http://purl.org/dc/elements/1.1/"
exterms: "http://example.org/stuff/1.0/"
rdf/Description:
rdf/about: "http://www.w3.org/TR/rdf-syntax-grammar"
dc/title: "RDF/XML Syntax Specification (Revised)"
exterms/editor:
exterms/fullName: Dave Beckett
exterms/homePage: !rdf/resource "http://purl.org/net/dajobe/"
---
Now that the basic stuff is introduced let's move on to collections. Here is an
example involving a bag:
##--- RDF http://www.w3.org/TR/rdf-primer/#example13 ---##
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:s="http://example.edu/students/vocab#">
<rdf:Description rdf:about="http://example.edu/courses/6.001">
<s:students>
<rdf:Bag>
<rdf:li rdf:resource="http://example.edu/students/Amy"/>
<rdf:li rdf:resource="http://example.edu/students/Tim"/>
<rdf:li rdf:resource="http://example.edu/students/John"/>
<rdf:li rdf:resource="http://example.edu/students/Mary"/>
<rdf:li rdf:resource="http://example.edu/students/Sue"/>
</rdf:Bag>
</s:students>
</rdf:Description>
</rdf:RDF>
##--- YAML ---###
--- %YAML:1.0
rdf/rdf:
__namespaces__:
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
s: "http://example.edu/students/vocab#"
rdf/Description:
rdf/about: "http://example.edu/courses/6.001"
s/students: !rdf/bag
- !rdf/resource "http://example.edu/students/Amy"
- !rdf/resource "http://example.edu/students/Tim"
- !rdf/resource "http://example.edu/students/John"
- !rdf/resource "http://example.edu/students/Mary"
- !rdf/resource "http://example.edu/students/Sue"
---
Now the same thing, replacing the bag by an alternative list (which is silly in
this context I know, but it's the idea that counts):
--- %YAML:1.0
rdf/rdf:
__namespaces__:
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
s: "http://example.edu/students/vocab#"
rdf/Description:
rdf/about: "http://example.edu/courses/6.001"
s/students: !rdf/alt
- !rdf/resource "http://example.edu/students/Amy"
- !rdf/resource "http://example.edu/students/Tim"
- !rdf/resource "http://example.edu/students/John"
- !rdf/resource "http://example.edu/students/Mary"
- !rdf/resource "http://example.edu/students/Sue"
---
And now with a sequence:
--- %YAML:1.0
rdf/rdf:
__namespaces__:
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
s: "http://example.edu/students/vocab#"
rdf/Description:
rdf/about: "http://example.edu/courses/6.001"
s/students:
- !rdf/resource "http://example.edu/students/Amy"
- !rdf/resource "http://example.edu/students/Tim"
- !rdf/resource "http://example.edu/students/John"
- !rdf/resource "http://example.edu/students/Mary"
- !rdf/resource "http://example.edu/students/Sue"
---
Sequences are the default so you don't need to have an extra !rdf/seq type tag.
And now the collection. For reasons not known to me it has a different syntax
than bag/seq/alt in RDF/XML, but since that doesn't translate very well to YAML
the syntax is a little different (and more straighforward):
--- %YAML:1.0
rdf/rdf:
__namespaces__:
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
s: "http://example.edu/students/vocab#"
rdf/Description:
rdf/about: "http://example.edu/courses/6.001"
s/students: !rdf/collection
- !rdf/resource "http://example.edu/students/Amy"
- !rdf/resource "http://example.edu/students/Tim"
- !rdf/resource "http://example.edu/students/John"
- !rdf/resource "http://example.edu/students/Mary"
- !rdf/resource "http://example.edu/students/Sue"
---
This isn't quite optimal yet, mainly in the namespace section, but it proves
that it's possible to expres RDF in YAML in an easy and understandable way.
Greetings,
Peter
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Visionaries] RDF/YAML,
Peter Minten <=