[pypy-svn] r22108 - in pypy/dist/pypy/lib/pyontology: . test

ale at codespeak.net ale at codespeak.net
Fri Jan 13 13:54:37 CET 2006


Author: ale
Date: Fri Jan 13 13:54:36 2006
New Revision: 22108

Modified:
   pypy/dist/pypy/lib/pyontology/pyontology.py
   pypy/dist/pypy/lib/pyontology/test/test_ontology.py
Log:
Changed differentFrom and added extra test.


Modified: pypy/dist/pypy/lib/pyontology/pyontology.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/pyontology.py	(original)
+++ pypy/dist/pypy/lib/pyontology/pyontology.py	Fri Jan 13 13:54:36 2006
@@ -1,6 +1,6 @@
 from rdflib import Graph, URIRef, BNode, Literal
 from logilab.constraint import  Repository, Solver
-from logilab.constraint.fd import Equals, AllDistinct, BinaryExpression, Expression 
+from logilab.constraint.fd import BinaryExpression
 from logilab.constraint.fd import  FiniteDomain as fd
 from logilab.constraint.propagation import AbstractDomain, AbstractConstraint, ConsistencyFailure
 import sys
@@ -404,9 +404,9 @@
         self.constraints.append(constrain) 
 
     def differentFrom(self, s, var):
-        s_var = self.make_var(ClassDomain, s)
+        s_var = self.make_var(Thing, s)
         var_var = self.make_var(Thing, var)
-        constrain = BinaryExpression([s_var, var_var],"%s != %s" %(s_var,  var_var))
+        constrain = DifferentfromConstraint(s_var, var_var)
         self.constraints.append(constrain)
 
 #XXX need to change this
@@ -717,6 +717,15 @@
             if not (val,cls) in obj_domain:
                 raise ConsistencyFailure("Inverseof failed") 
 
+class DifferentfromConstraint(SubClassConstraint):
+
+    def narrow(self, domains):
+        if self.variable == self.object:
+            raise ConsistencyFailure("%s can't be differentFrom itself" % self.variable)
+        else:
+            return 0
+
+
 class ListConstraint(OwlConstraint):
     """Contraint: all values must be distinct"""
 

Modified: pypy/dist/pypy/lib/pyontology/test/test_ontology.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/test/test_ontology.py	(original)
+++ pypy/dist/pypy/lib/pyontology/test/test_ontology.py	Fri Jan 13 13:54:36 2006
@@ -462,12 +462,19 @@
     cls = BNode('anon')
     own1 = BNode('liist1')
     own2 = BNode('liist2')
-    list1 = rdf_list(O, 'favlist1', ['1', '2', '3'])
-    list2 = rdf_list(O, 'favlist2', ['3', '4', '5'])
-    own = rdf_list(O, 'favlist', [own1, own2])
-    O.oneOf( own1, list1)
-    O.oneOf( own2, list2)
-    O.intersectionOf(cls, own)
-    O.type(cls, namespaces['owl']+'#Class')
+    O.differentFrom(cls, own1)
+    O.differentFrom(own1, own2)
+    O.differentFrom(cls, own2)
+    O.differentFrom(own2,cls)
+    O.type(cls, namespaces['owl']+'#Thing')
+    O.type(own1, namespaces['owl']+'#Thing')
+    O.type(own2, namespaces['owl']+'#Thing')
     O.consistency(3)
-    assert O.rep._domains[cls].getValues() == ['3']
+    assert len(O.rep._constraints) == 4
+
+def test_differentfromconsistency():
+    O = Ontology()
+    cls = BNode('anon')
+    O.differentFrom(cls, cls)
+    O.type(cls, namespaces['owl']+'#Thing')
+    py.test.raises(ConsistencyFailure, O.consistency, 3)



More information about the Pypy-commit mailing list