views:

80

answers:

2

Hi.

I have just been introduced to the semantic web and it's family of functions but I have a hard time understanding some of it, which I was hoping someone could explain to me.

As far as I've understood, RDF can be written in several syntaxes. RDF/XML, Turtle, etc.

Now, I understand XML. How it is presented and how it can be parsed. However, some people write in the turtle syntax, but how do they parse that information? I can't seem to find a single library for any language to "extract" the information written in a turtle syntax into another form. The same goes for N3. How can it be used? Executed or else?

I seem to be able to understand RDFa. That it is a way to implement RDF into XHTML. For me that is a way to implement RDF into "something". But how can I compare that to turtle, N3, or the like?

Thanks in advance.

+6  A: 

Firstly, to be clear, when we say 'RDF' we mean (at base) a collection of triples:

<subject1> <predicate1> <object1>
<subject2> <predicate2> <object2>
...

It's a simple database, not 'executable'.

There are many ways to write RDF. RDF/XML is the most common, but not the most obvious when you're learning. N-Triples is the simplest, you just write out the triples:

<subject1> <predicate1> <object1> .
<subject2> <predicate2> <object2> .
...

Turtle is like N-Triples, but with lots of short cuts. It's very easy to write. For example if we had:

<person> <age> 21 .
<person> <friend> <bob> .
<person> <friend> <alice> .
...

In turtle we can avoid the repetition by writing:

<person> <age> 21 ; 
         <friend> <bob> ,
         <alice> .

(I've written this out on multiple lines so you can see how it looks like the triple version, but with parts missed out)

You'll find turtle parsers for most RDF libraries. See Jena (java), Redland (C), RDFLib (python), Trine (perl) etc. They take turtle and produce triples, just like the RDF/XML parsers and RDFa parsers do.

Once you have your RDF loaded you can query it, process it, whatever you'd do with any other data format.

RDFa is a strange RDF format, since it's embedded in something else (most of which is thrown away when you convert to triples). The point of RDFa is to get RDF more smoothly integrated into the web. Having both an RDF version and HTML version of my personal information is repetitious and fiddly to deploy. With RDFa I can have one document which serves both browsers and rdf consumers.

A: 

As someone with limited programming skills, I found that the ARC2 libraries for PHP make RDF very easy to deal with. There is good documentation and great examples on the site to get started. It includes parsers for all of the common formats, including turtle, and will even do format detection and choose the correct parser if you don't feel like it.

When parsing RDF, ARC produces two different types of associative arrays which are quite straightforward. A description of those structures can be found here.

I never thought I would say it, but PHP + ARC actually made working with RDF...fun.

wynz