woensdag 24 april 2013

Making a Turtle RDF with rdflib

RDF with Saxophone as topic

So the fist thing I did today is finalize mij rdf script. Now it is a fully working command based script to make an RDF.  source:


There are only a few things that are hard coded. These things are the name of the output file and the format the script parses and writes. Paying close attention to the parsing part is that it says that it has to parse n3 rdfs. Whereas the serializing happens in turtle. This is no problem since, there is no turtle parser and since turtle is a correct format for n3, the n3 parser can read turtle formats too.

Before I started writing the RDF I needed to find out which predicate vocabulary I can use to define my predicates. Doing research on this subject, I came upon a problem it seems that there was no easy way of searching for certain predicates then going to the individual vocabularies and looking for the predicates required. But just recently I stumbled on this website (http://lov.okfn.org/dataset/lov/), it seems like you can type the predicate you want in the search engine and it will find you the namespace for it, which is exactly what I needed. Now I haven't fully tested this website, but it looks like a nice start. Here is another website I found useful to use to find certain namespaces (no property attached to it): http://prefix.cc/

Also another issue, that I wasn't to sure of is, whether reversals were to be implemented in the RDF too. An example of what I mean:

normal:     Saxophone    maker    Adolphe_Sax
reversed: Adolphe_Sax    made    Saxophone

Aside from the predicates, the subject has to be a link to an object not a webpage, for example, we take the dbpedia of Saxophone and not the wikipedia webpage of Saxophone. This is required because dbpedia has further links that connects other webpages and libraries.

The object, can be a link as well as a literal.

To use the python script to create your own RDF you have to supply the "subject-predicate-object". By entering in the command line the following the "subject-predicate-object" will be added to the RDF in turtle format.

python <name of script> <subject> <predicate> <object>

below you see a beginning for the RDF in turtle format:


@prefix : <file:///home/cizaralmalak/Desktop/Scripts/Saxophone.ttl#>.
@prefix _4: <http://dbpedia.org/resource/>.
@prefix _5: <http://purl.org/ontology/mo/>.
@prefix _6: <http://xmlns.com/foaf/0.1/>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix xml: <http://www.w3.org/XML/1998/namespace>.

 _4:Saxophone "a" _5:instrument;
     _6:maker _4:Adolphe_Sax;
     _6:name "Saxophone". 

 _4:Adolphe_Sax _6:age "79";
     <http://xmlns.com/foaf/0.1/familyName> "Sax";
     _6:firstName "Adolphe";
     _6:gender "male";
     _6:name "Adolphe Sax". 

Using the rdflib, this format can be changed in any other rdf format quite easily  This can be achieved by changing the graph.serialize format to any of the preferred formats. But in the next run the parser has to be changed too, to be able to read the new format.

Geen opmerkingen:

Een reactie posten