简体   繁体   English

在rdflib中防止图联合

[英]Preventing graph union in rdflib

Is there a way to prevent rdflib merging graphs ? 有没有办法防止rdflib合并图? I am creating two graphs in a single response which have a node in common, so rdf creates (because of the union): 我在单个响应中创建两个具有共同节点的图,因此rdf创建(由于并集):

<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: 通过将max_depth传递给序列化调用来解决:

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. 这样可以避免整个图重复出现,而是将每个顶级主题节点分别写出到文档中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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