def _diff_graph(self):
'''
Uses rdflib.compare diff, https://github.com/RDFLib/rdflib/blob/master/rdflib/compare.py
When a resource is retrieved, the graph retrieved and parsed at that time is saved to self.rdf._orig_graph,
and all local modifications are made to self.rdf.graph. This method compares the two graphs and returns the diff
in the format of three graphs:
overlap - triples shared by both
removed - triples that exist ONLY in the original graph, self.rdf._orig_graph
added - triples that exist ONLY in the modified graph, self.rdf.graph
These are used for building a sparql update query for self.update.
Args:
None
Returns:
None: sets self.rdf.diffs and adds the three graphs mentioned, 'overlap', 'removed', and 'added'
'''
overlap, removed, added = graph_diff(
to_isomorphic(self.rdf._orig_graph),
to_isomorphic(self.rdf.graph))
diffs = SimpleNamespace()
diffs.overlap = overlap
diffs.removed = removed
diffs.added = added
self.rdf.diffs = diffs
评论列表
文章目录