Commits

gweis  committed a111560

implement __ne__ for graph to do isomorphic comparison

  • Participants
  • Parent commits d7721c1

Comments (0)

Files changed (1)

File ordf/graph.py

     from rdflib.graph import Graph as _Graph
     from rdflib.graph import ReadOnlyGraphAggregate as _ROGraph
     from rdflib.graph import ConjunctiveGraph as _CGraph
+    from rdflib.compare import isomorphic
     __rdflib_version__ = 3
 except ImportError:
     from rdflib.Graph import Graph as _Graph
 
     def distinct_subjects(self, *av, **kw):
         """
-        Return a *distinct* set of subjects. Arguments are 
+        Return a *distinct* set of subjects. Arguments are
         as for :meth:subjects
         """
         return self._distinct(self.subjects, *av, **kw)
 
     def distinct_predicates(self, *av, **kw):
         """
-        Return a *distinct* set of predicates. Arguments are 
+        Return a *distinct* set of predicates. Arguments are
         as for :meth:predicates
         """
         return self._distinct(self.predicates, *av, **kw)
 
     def distinct_objects(self, *av, **kw):
         """
-        Return a *distinct* set of objects. Arguments are 
+        Return a *distinct* set of objects. Arguments are
         as for :meth:objects
         """
         return self._distinct(self.objects, *av, **kw)
         * pointer to any :mod:`ordf.handler` in use.
 
     .. attribute:: identifier
-    
+
     This is the URI of the resource that the graph can be said to be about.
 
     .. autoattribute:: __types__
     .. automethod:: distinct_predicates
     .. automethod:: distinct_objects
     """
-    
+
     __types__ = [RDFS["Resource"], RDFG["Graph"]]
     """
     Sub-classes should set this attribute to a list of :class:`URIRef`. It isn't
             break
         return version
 
+    # def __eq__(self, other):
+    #     if not super(Graph, self).__eq__(other):
+    #         return False
+    #     # FIXME: asking for len in __eq__ ends in endless recursion in IOMemory store
+    #     # if len(self) != len(other):
+    #     #     return False
+    #     # FIXME: this may be called very often due to IOMemory implementation
+    #     return isomorphic(self, other)
+
+    def __ne__(self, other):
+        # FIXME: this is asymmetric to __eq__ (which does identifier check only)
+        return not(isinstance(other, Graph)
+                   and self.identifier == other.identifier
+                   and isomorphic(self, other))
+
+
 class ConjunctiveGraph(_CGraph, _Common):
     __types__ = []
     def __init__(self, store="IOMemory", identifier=None, **kw):