W3C home > Mailing lists > Public > semantic-web@w3.org > January 2010

Re: Turtle null prefix and namespaces

From: Mark Wallace <mwallace@modusoperandi.com>
Date: Mon, 25 Jan 2010 09:12:50 -0500
Message-ID: <4B5DA6E2.3050909@modusoperandi.com>
To: Richard Light <richard@light.demon.co.uk>
CC: Peter Ansell <ansell.peter@gmail.com>, semantic-web@w3c.org
Richard Light wrote:
> In message 
> <a1be7e0e1001181249t23397d9bh3259b3dbc66abfd2@mail.gmail.com>, Peter 
> Ansell <ansell.peter@gmail.com> writes
>> Why can't you make up a namespace prefix in the RDF/XML document that
>> hasn't been used in the turtle document or the RDF/XML document and
>> apply it to all of the null prefixed items that you get out of turtle?
> Neat.  Thank you.
>> The fact that the prefix represents a namespace in Turtle has no
>> bearing on the RDF model in general, you are just lucky that the
>> RDF/XML document has support for namespaces.
> That bears on the whole issue of the degree of equivalence between 
> Turtle/SPARQL prefixes and XML namespace prefixes.  They look as 
> though they do the same job, but I have been harbouring a suspicion 
> that there might be differences that matter.  The "null prefix" case 
> seemed to me to be an example of this.
> You say I am "just lucky", but in fact RDF/XML itself could not work 
> as currently defined without namespace support.  Since predicates are 
> expressed as element names in RDF/XML, and since they are URIs, the 
> use of a namespace prefix is necessary for an absolute URI even to 
> have a chance of being a valid XML element name.  All the non-NAME 
> characters can go into the namespace URI.  (Personally I would prefer 
> predicates to be expressed as attributes in a revised XML 
> serialization of RDF, so as to remove this dependency/limitation.)
>> What is the advantage of doing a straight translation without
>> representing the triples in memory as abstract RDF by the way? Have
>> you tried translating the turtle document to NTriples first?
> This whole exercise started when a draft framework of interest to me 
> (VMF [1]) was offered only in Turtle form.  What started as a quick 
> hack has become a reasonably serious attempt to deal with the full 
> Turtle syntax.
Hi Richard,

Were you aware of the Jena framework's rdfcat too which can be used to 
convert between a number of formats, including Turtle to RDF/XML?

E.g. using this Turtle (note the null prefix usage):

    @prefix :   <http://example.com/test#> .
    @prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix owl:   <http://www.w3.org/2002/07/owl#> .
    @prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .

            a owl:DatatypeProperty ;
            rdfs:range xsd:int .

            a owl:DatatypeProperty ;
            rdfs:range xsd:string .

            a owl:Class .

            a :Person ;
            :hasAge "45"^^xsd:int ;
            :hasName "Mark" .

You can convert using this command:

    java jena.rdfcat -out xml -n x.ttl

.... which outputs this:

        xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
      <rdf:Description rdf:about="http://example.com/test#Person">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
      <rdf:Description rdf:about="http://example.com/test#hasAge">
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
      <rdf:Description rdf:about="http://example.com/test#hasName">
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
      <rdf:Description rdf:about="http://example.com/test#Mark">
        <rdf:type rdf:resource="http://example.com/test#Person"/>

It can convert to other formats as well: RDF/XML Abbreviated format, 
N-Triples, N3.


Mark Wallace
Principal Engineer, Semantic Applications
Modus Operandi, Melbourne, FL, USA

> I didn't see any value in going via intermediate forms, since my aim 
> was to get machine-processible XML to drop into a triple store.  I 
> could have done this job more easily with a custom XML target format, 
> but I wanted to improve my understanding of RDF/XML, and also to 
> produce something which might be of use to others.  In fact I load the 
> parsed data directly into an XML DOM, and just serialize it when 
> parsing is completed.  An extension which would be easy to add would 
> be to apply a user-supplied XSLT transform to this document, allowing 
> output in any required format.
> A couple of points about Turtle also dropped out of this exercise. 
> First, a literal-minded reading of the EBNF spec would suggest that 
> white space is only allowed where specified.  There ought to be a 
> statement somewhere that white space is allowed freely between tokens 
> (or did I miss it?). Second, the Turtle VMF resource didn't use UTF-8 
> encoding (accented characters were in ISO-8859-1), and despite this it 
> imported without problems into Protege 4.  This in turn suggests that 
> Protege's Turtle support doesn't deal correctly with encoding issues.
>> Would the following do what you want?
>> <rdf:Description rdf:about="http://example.org/a1"><a2
>> xmlns="http://example.org/"
>> rdf:resource="http://example.org/a3"/></rdf:Description>
> Only if the rdf:resource is an absolute URI, I think.
> Richard
> [1] http://cdlr.strath.ac.uk/VMF/
Received on Wednesday, 27 January 2010 10:05:45 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:48:05 UTC