[redland-dev] Handling rdf:seq with redland

Dave Beckett dave at dajobe.org
Fri Sep 28 04:25:54 BST 2007


Sebastian Faubel wrote:
> Hi there,
> 
> i've tried to figure it out my self, but how do i construct a
> rdf:seq/rdf:bag statement using the redland api? 
> 
> also every statements i assert are serialized "flat", like this:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
>   <rdf:Description rdf:about="local:sequence">
>     <ns0:seq xmlns:ns0="rdf:" rdf:resource="local:test1"/>
>   </rdf:Description>
>   <rdf:Description rdf:about="local:sequence">
>     <ns0:seq xmlns:ns0="rdf:" rdf:resource="local:test2"/>
>   </rdf:Description>
> </rdf:RDF>

Your URIs are all wrong.  "rdf:Seq" is not a URI, it is an XML
artifact.  The URI of an rdf sequence is
<http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq>

It's easier to explain this by disasembly:
$ cat seq.rdf
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Seq>
  <rdf:li rdf:resource="http://example1.org/" />
  <rdf:li rdf:resource="http://example2.org/" />
</rdf:Seq>
</rdf:RDF>

A sequence of two resources.

$ utils/rdfproc test parse seq.rdf
lt-rdfproc: Parsing URI file:///home/dajobe/dev/redland/librdf/seq.rdf
with default parser

The default parser is rdfxml although it isn't mentioned.

$ utils/rdfproc test serialize ntriples
_:r1190949806r12055r1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#_1>
<http://example1.org/> .
_:r1190949806r12055r1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#_2>
<http://example2.org/> .
_:r1190949806r12055r1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq> .

There is the full URI.

Try serializing to rdf/xml again:

$ utils/rdfproc test serialize rdfxml
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:nodeID="r1190949806r12055r1">
    <rdf:_1 rdf:resource="http://example1.org/"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="r1190949806r12055r1">
    <rdf:_2 rdf:resource="http://example2.org/"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="r1190949806r12055r1">
    <rdf:type
rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq"/>
  </rdf:Description>
</rdf:RDF>

which is the 'flat' rdf/xml.

Instead try the abbreviated one:

$ utils/rdfproc test serialize rdfxml-abbrev
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Seq>
    <rdf:_1 rdf:resource="http://example1.org/"/>
    <rdf:_2 rdf:resource="http://example2.org/"/>
  </rdf:Seq>
</rdf:RDF>

which is similar to the original document in syntax.  Semantically
it is identical, and identical to the 'flat' rdf/xml.

> but how do i tell the serializer to nest relations regarding one
> subject? like this:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
>   <rdf:Description rdf:about="local:sequence">
>     <ns0:seq xmlns:ns0="rdf:" rdf:resource="local:test1"/>
>     <ns0:seq xmlns:ns0="rdf:" rdf:resource="local:test2"/>
>   </rdf:Description>
> </rdf:RDF>
> 
> sorry for the stupid questions..

Use the "rdfxml-abbrev" serializer rather than the "rdfxml" one
as I showed above.

That will make things appear right.

Dave


More information about the redland-dev mailing list