Re: Turtle null prefix and namespaces

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#> .

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

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

    :Person
            a owl:Class .

    :Mark
            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:

    <rdf:RDF
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns="http://example.com/test#"
        xmlns:owl="http://www.w3.org/2002/07/owl#"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
        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:Description rdf:about="http://example.com/test#hasAge">
        <rdf:type
    rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
      </rdf:Description>
      <rdf:Description rdf:about="http://example.com/test#hasName">
        <rdf:type
    rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
      </rdf:Description>
      <rdf:Description rdf:about="http://example.com/test#Mark">
        <rdf:type rdf:resource="http://example.com/test#Person"/>
        <hasAge
    rdf:datatype="http://www.w3.org/2001/XMLSchema#int">45</hasAge>
        <hasName>Mark</hasName>
      </rdf:Description>
    </rdf:RDF>

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

 -Mark

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