Log on:
Powered by Elgg

Home > Group JVDB > 3 Technologies > RDF and Turtle > Further Information and Examples

The following are examples taken from the w3 team's January 14th 2008 submission on Turtle and are useful in understanding how Turtle shortens and simplifies code writing.

The following example is related to the URI Reference section on the Turtle grammar page. It clearly shows that the in-scope base URI at any point in the document is determined by the @base directive which sets a new base URI relative to the current in-scope base URI. Below this example we show how the same would be encoded in N-Triples. (Note: The lines in N-Trples are so long they are cut off in this screen format.)

***************************URI Reference*******************************

# In-scope base URI is http://www.w3.org/2001/sw/DataAccess/df1/tests/ at this point
<test-00.ttl> <test-01.ttl> <test-02.ttl> .
@base <http://example.org/ns/> .
# In-scope base URI is http://example.org/ns/ at this point
<a2> <http://example.org/ns/b2> <c2> .
@base <foo/> .
# In-scope base URI is http://example.org/ns/foo/ at this point

<a3> <b3> <c3> .
@prefix : <bar#> .
:a4 :b4 :c4 .
@prefix : <http://example.org/ns2#> .
:a5 :b5 :c5 .
 
*************************Same Code in N-Triples************************* 
 <http://www.w3.org/2001/sw/DataAccess/df1/tests/test-01.ttl> <http://www.w3.org/2001/sw/DataAccess/df1/tests/test-02.ttl> 
<http://example.org/ns/a2> <http://example.org/ns/b2> <http://example.org/ns/c2&>
<http://example.org/ns/foo/a3> <http://example.org/ns/foo/b3> <http://example.org/ns/foo/c3>
<http://example.org/ns/foo/bar#a4> <http://example.org/ns/foo/bar#b4> <http://example.org/ns/foo/bar#c4>
<http://example.org/ns2#a5> <http://example.org/ns2#b5> <http://example.org/ns2#c5>

****************************End of Example*****************************

 

 

The following is an example written in turtle followed by the original code in RDF. It highlights the terseness and simplicity which are the earmarks of Turtle.

 

**************Turtle Translation of Example 7****************

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix dc: .
@prefix ex: <http://example.org/stuff/1.0/> .


dc:title "RDF/XML Syntax Specification (Revised)" ;
ex:editor [
ex:fullname "Dave Beckett";
ex:homePage <http://purl.org/net/dajobe/>
] .
******************Example 7 in RDF***********************

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ex="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)">
<ex:editor>

<ex:homePage rdf:resource="http://purl.org/net/dajobe/" />
</rdf:Description>
</ex:editor>
</rdf:Description>
</rdf:RDF>

******************End of Example*************************

 

The following again higlights how much simpler and concise using Turtle will be.

 

**********Example of an RDF Collection of two literals***********

@prefix :  .
:a :b ( "apple" "banana" ) .

*************which is the short of example 2.ttl****************

@prefix : <http://example.org/stuff/1.0/> .
@prefix rdf: .
:a :b
[ rdf:first "apple";
rdf:rest [ rdf:first "banana";
rdf:rest rdf:nil ]
] .

******************End of Example*************************

 

The following is an example of two identical triples containing literal objects containing newlines, written in plain and long literal forms.

********************Two Identical Triples*******************

@prefix :  .

:a :b "The first line\nThe second line\n more" .

:a :b """The first line
The second line
more""" .

*********************End of Example**********************