12 June 2009

RDF : javascript, xsl stylesheets

A few notes:
I've implemented a javascript library to parse RDF (I love re-inventing the wheel, it's always interesting to learn how softwares and algorithms are working ). The RDF syntax is still not fully implemented (e.g. it don't support xml:lang, parseType=Literal, etc...)

.


I've also created 3 XSLT stylesheets transforming RDF to ....

  • N3:
    xsltproc rdf2n3.xsl http://www.w3.org/TR/rdf-syntax-grammar/example12.rdf
    <http://www.w3.org/TR/rdf-syntax-grammar> <http://purl.org/dc/elements/1.1/title> "RDF/XML Syntax Specification (Revised)" .
    <http://www.w3.org/TR/rdf-syntax-grammar> <http://example.org/stuff/1.0/editor> <_:anodeid2245696> .
    <_:anodeid2245696> <http://example.org/stuff/1.0/fullName> "Dave Beckett" .
    <_:anodeid2245696> <http://example.org/stuff/1.0/homePage> <http://purl.org/net/dajobe/> .
  • rdf:Statement:
    xsltproc rdf2rdf.xsl http://www.w3.org/TR/rdf-syntax-grammar/example12.rdf

    <?xml version="1.0"?>
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Statement>
    <rdf:subject rdf:resource="http://www.w3.org/TR/rdf-syntax-grammar"/>
    <rdf:predicate rdf:resource="http://purl.org/dc/elements/1.1/title"/>
    <rdf:object>RDF/XML Syntax Specification (Revised)</rdf:object>
    </rdf:Statement>
    <rdf:Statement>
    <rdf:subject rdf:resource="http://www.w3.org/TR/rdf-syntax-grammar"/>
    <rdf:predicate rdf:resource="http://example.org/stuff/1.0/editor"/>
    <rdf:object rdf:resource="_:anodeid2245620"/>
    </rdf:Statement>
    <rdf:Statement>
    <rdf:subject rdf:resource="_:anodeid2245620"/>
    <rdf:predicate rdf:resource="http://example.org/stuff/1.0/fullName"/>
    <rdf:object>Dave Beckett</rdf:object>
    </rdf:Statement>
    <rdf:Statement>
    <rdf:subject rdf:resource="_:anodeid2245620"/>
    <rdf:predicate rdf:resource="http://example.org/stuff/1.0/homePage"/>
    <rdf:object rdf:resource="http://purl.org/net/dajobe/"/>
    </rdf:Statement>
    </rdf:RDF>
  • SQL statements:
    xsltproc rdf2sql.xsl http://www.w3.org/TR/rdf-syntax-grammar/example12.rdf


    create table TRIPLE IF NOT EXISTS
    (
    subject varchar(50) not null,
    predicate varchar(50) not null,
    value_is_uri enum('true','false') not null,
    value varchar(50) not null //need to fix dataType and xml:lang
    );
    insert into TRIPLE(subject,predicate,value_is_uri,value) values ("http://www.w3.org/TR/rdf-syntax-grammar","http://purl.org/dc/elements/1.1/title","false","RDF/XML Syntax Specification (Revised)");
    insert into TRIPLE(subject,predicate,value_is_uri,value) values ("http://www.w3.org/TR/rdf-syntax-grammar","http://example.org/stuff/1.0/editor","true","_:anodeid2245974");
    insert into TRIPLE(subject,predicate,value_is_uri,value) values ("_:anodeid2245974","http://example.org/stuff/1.0/fullName","false","Dave Beckett");
    insert into TRIPLE(subject,predicate,value_is_uri,value) values ("_:anodeid2245974","http://example.org/stuff/1.0/homePage","true","http://purl.org/net/dajobe/");



That's it
Pierre

No comments: