简体   繁体   中英

Preventing graph union in rdflib

Is there a way to prevent rdflib merging graphs ? I am creating two graphs in a single response which have a node in common, so rdf creates (because of the union):

<ore:aggregation rdf:about="http://example.org/obj/123">
  <edm:aggregatedCHO>
  <edm:ProvidedCHO rdf:about="#OBJ123">
    ...
  </edm:ProvidedCHO>
  </edm:aggregatedCHO>
</ore:aggregation>

which I would prefer instead to return as two top level graphs

<ore:aggregation rdf:about="http://example.org/obj/123">
  <edm:aggregatedCHO rdf:resource="#OBJ123/>
</ore:aggregation>

<edm:ProvidedCHO rdf:about="#OBJ123>
  ...
</edm:ProvidedCHO>

Is this possible ? I understand I can create them as part of a dataset which would prevent the union, but there doesn't seem to be a way to serialise the dataset out.

Solved by passing max_depth to serialisation call:

g.serialize(format='pretty-xml', max_depth=1)

which avoids recursing through the whole graph in one and instead writes each top level subject node out individually in the document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM