RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.16k stars 555 forks source link

rdf:resource pointing to existing URIRef #797

Closed igoralmeida closed 6 years ago

igoralmeida commented 6 years ago

Hi all,

I'm trying to create an RDF file that Zotero accepts, but I am struggling with getting rdf:resource properties (?) to show up.

Basically I'm trying to reference an item from a Zotero collection (this probably does not relate to what RDFLib calls "collection"). Collections in Zotero RDF look like this:

    <z:Collection rdf:about="#collection_6">
        <dc:title>Example</dc:title>
        <dcterms:hasPart rdf:resource="#collection_8"/>
        <dcterms:hasPart rdf:resource="https://www.example.com"/>
        <dcterms:hasPart rdf:resource="#item_426"/>
        <dcterms:hasPart rdf:resource="http://www.example2.com"/>
    </z:Collection>

And items such as attachments look like this:

    <z:Attachment rdf:about="#item_426">
       <z:itemType>attachment</z:itemType>
       <rdf:resource rdf:resource="files/426/filename.pdf"/>
       <dcterms:dateSubmitted>2017-11-28 16:15:48</dcterms:dateSubmitted>
       <dc:title>filename.pdf</dc:title>
       <z:linkMode>1</z:linkMode>
       <link:type>application/pdf</link:type>
    </z:Attachment>

So when trying something like mygraph.add((mycollection, DCTERMS.hasPart, myattachment)) the attachment is instead placed inside the collection (understandably), like so:

  <z:Collection rdf:about="#collection_6">
    <dc:title>Example</dc:title>
    <dcterms:hasPart>
      <z:Attachment rdf:about="#item_426">
      ...
      </z:Attachment>
    </dcterms:hasPart>
  </z:Collection>

I am definitely missing some concepts here but I am not sure what else to search for. Is there a way to get that <dcterms:hasPart rdf:resource="#item_426"/> part correctly? Note that, besides collections, attachments also have a similar child <rdf:resource rdf:resource="files/426/filename.pdf"/> that I would like to have as well.

Any help is greatly appreciated.

gromgull commented 6 years ago

The two rdf/xml docs contain the same graph. I.e. an RDF aware processor will treat them the same. There is no way to force rdflib to serialize the first type.

If Zotero does not accept the RDF/XML RDFLib produces, you either have to get them to fix it. Or make your own XML serializer that does exactly what Zotero expects.