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

ale at codespeak.net ale at codespeak.net
Sun Jan 8 13:54:45 CET 2006


Author: ale
Date: Sun Jan  8 13:54:44 2006
New Revision: 21814

Modified:
   pypy/dist/pypy/lib/pyontology/pyontology.py
   pypy/dist/pypy/lib/pyontology/test/test_ontology.py
Log:
Added a test for class enumeration using oneOf


Modified: pypy/dist/pypy/lib/pyontology/pyontology.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/pyontology.py	(original)
+++ pypy/dist/pypy/lib/pyontology/pyontology.py	Sun Jan  8 13:54:44 2006
@@ -785,15 +785,18 @@
         return 100
         
     def narrow(self, domains):
-        property = domains[self.variable].property
-        cls = domains[self.variable].cls
         val = domains[self.List].getValues()
-        prop = Linkeddict(domains[property].getValues())
-        for v in prop[cls]:
-            if not v in val:
-                raise ConsistencyFailure(
-                    "The value of the property %s in the class %s is not oneof %r"
-                        %(property, cls, val))
-                        
+        if isinstance(domains[self.variable],Restriction):
+            property = domains[self.variable].property
+            cls = domains[self.variable].cls
+            prop = Linkeddict(domains[property].getValues())
+            for v in prop[cls]:
+                if not v in val:
+                    raise ConsistencyFailure(
+                        "The value of the property %s in the class %s is not oneof %r"
+                            %(property, cls, val))
+        else:
+            domains[self.variable].setValues(val)
+            return 1
 class HasvalueConstraint:
     pass

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	Sun Jan  8 13:54:44 2006
@@ -358,3 +358,20 @@
     O.type(own, obj)
     O.subClassOf(own,restrict)
     py.test.raises(ConsistencyFailure, O.consistency)
+
+def test_oneofclassenumeration():
+    O = Ontology()
+    restrict = BNode('anon')
+    own = URIRef('favlist')
+    obj = URIRef(namespaces['rdf']+'#List')
+    O.type(own, obj)
+    O.first(own, URIRef('first'))
+    O.rest(own,  URIRef('1'))
+    O.first( URIRef('1'), URIRef('second'))
+    O.rest( URIRef('1'),  URIRef('2'))
+    O.first( URIRef('2'), URIRef('third'))
+    O.rest( URIRef('2'),  URIRef(namespaces['rdf']+'#nil'))
+    O.oneOf(restrict, own)
+    O.type(restrict, namespaces['owl']+'#Class')
+    O.consistency(4)
+    assert len(O.rep._domains[restrict].getValues()) == 3
\ No newline at end of file



More information about the Pypy-commit mailing list