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

ale at codespeak.net ale at codespeak.net
Sun Jan 8 15:30:55 CET 2006


Author: ale
Date: Sun Jan  8 15:30:54 2006
New Revision: 21816

Modified:
   pypy/dist/pypy/lib/pyontology/pyontology.py
   pypy/dist/pypy/lib/pyontology/test/test_ontology.py
Log:
Added support for SomeValuesFrom and a test


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 15:30:54 2006
@@ -482,8 +482,10 @@
         pass
 
     def someValuesFrom(self, s, var):
-        # TODO: implement this 
-        pass
+        svar = self.make_var(Restriction, s)
+        avar = self.make_var(None, var)
+        constrain = SomeValueConstraint(svar, avar)
+        self.constraints.append(constrain)
 
     def imports(self, s, var):
         # PP TODO: implement this 
@@ -802,5 +804,29 @@
             domains[self.variable].setValues(val)
             return 1
 
+class SomeValueConstraint(AbstractConstraint):
+
+    def __init__(self, variable, List):
+        AbstractConstraint.__init__(self, [variable, List])
+        self.variable = variable
+        self.List = List
+
+    def estimateCost(self, domains):
+        return 100
+        
+    def narrow(self, domains):
+        print self.variable,self.List
+        val = domains[self.List].getValues()
+        property = domains[self.variable].property
+        cls = domains[self.variable].cls
+        prop = Linkeddict(domains[property].getValues())
+        for v in prop[cls]:
+            if v in val:
+                break
+        else:
+            raise ConsistencyFailure(
+                    "The value of the property %s in the class %s has no values from %r"
+                        %(property, cls, val))
+
 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 15:30:54 2006
@@ -391,4 +391,33 @@
     O.oneOf(restrict, own)
     O.type(restrict, namespaces['owl']+'#DataRange')
     O.consistency(4)
-    assert len(O.rep._domains[restrict].getValues()) == 3
\ No newline at end of file
+    assert len(O.rep._domains[restrict].getValues()) == 3
+
+def test_somevaluesfrom_datarange():
+    O = Ontology()
+    datarange = 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(datarange, own)
+    O.type(datarange, namespaces['owl']+'#DataRange')
+    restrict = BNode('anon1')
+    obj = URIRef(namespaces['owl']+'#Restriction')
+    O.type(restrict, obj)
+    p = URIRef('p')
+    O.onProperty(restrict,p)
+    obj = URIRef(namespaces['owl']+'#ObjectProperty')
+    O.type(p, obj)
+    O.someValuesFrom(restrict, datarange)
+    cls = URIRef('class')
+    obj = URIRef(namespaces['owl']+'#Class')
+    O.type(cls, obj)
+    O.subClassOf(cls,restrict)
+    O.variables['p_'].setValues([(cls,1)])
+    py.test.raises(ConsistencyFailure, O.consistency)



More information about the Pypy-commit mailing list