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

ale at codespeak.net ale at codespeak.net
Fri Jan 6 18:49:41 CET 2006


Author: ale
Date: Fri Jan  6 18:49:40 2006
New Revision: 21749

Modified:
   pypy/dist/pypy/lib/pyontology/pyontology.py
   pypy/dist/pypy/lib/pyontology/test/test_ontology.py
Log:
Added test for inverseOf. Changed logic of rdfs:domain to be similar to rdfs:range, and changed test accordingly


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  6 18:49:40 2006
@@ -385,15 +385,6 @@
         # The classes that has this property (s) must belong to the class extension of var
         avar = self.make_var(ClassDomain, var)
         svar = self.make_var(Property, s)
-        assert isinstance(self.variables[svar], Property)
-        assert isinstance(self.variables[avar], ClassDomain)
-        vals = get_values(self.variables[avar], self.variables)  
-        if len(vals) == 0 :
-            vals = [(self.variables[avar], None)]
-        for k,v in self.variables[svar].getValues():
-            if not k in vals:
-                vals.append((k,v))
-        self.variables[svar].setValues(vals)
         cons = DomainConstraint(svar, avar)
         self.constraints.append(cons)
 
@@ -541,7 +532,6 @@
             val = val[0]
         if val in domains.keys():
             res.extend(get_values(domains[val], domains, attr))
-    #res[dom] = 1
     return res
 
 class SubClassConstraint(OwlConstraint):
@@ -587,9 +577,9 @@
         propdom = domains[self.variable]
         rangedom = domains[self.object]
         newrange = get_values(rangedom, domains, 'getValues')  
+        print rangedom
         range = []
-        prop = Linkeddict(propdom.getValues())
-        oldrange = propdom.range#get(None)
+        oldrange = propdom.range
         if oldrange:
             for v in oldrange:
                 if v in newrange:
@@ -597,7 +587,7 @@
         else:
             range = newrange
         propdom.range = range
-#        propdom.setValues(prop.items())
+        prop = Linkeddict(propdom.getValues())
         for pval in sum(prop.values(),[]):
             if pval not in range:
                 raise ConsistencyFailure("Value %r not in range %r"%(pval,range))
@@ -607,12 +597,20 @@
     def narrow(self, domains):
         propdom = domains[self.variable]
         domaindom = domains[self.object]
-        vals = get_values(domaindom, domains, 'getValues')  
-        res = []
-        for k,val in get_values(propdom, domains, 'getValues'):
-            if not k in vals and k != domaindom:
-                res.append((k,val))
-        propdom.removeValues(res)
+        newdomain = get_values(domaindom, domains, 'getValues') +[self.object]
+        domain = []
+        olddomain = propdom.domain
+        if olddomain:
+            for v in olddomain:
+                if v in newdomain:
+                    domain.append(v)
+        else:
+            domain = newdomain
+        propdom.domain = domain
+        prop = Linkeddict(propdom.getValues())
+        for pval in prop.keys():
+            if pval not in domain:
+                raise ConsistencyFailure("Value %r not in range %r"%(pval, domain))
 
 class SubPropertyConstraint(SubClassConstraint):
 

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  6 18:49:40 2006
@@ -157,7 +157,7 @@
     O.type(sub, pred , obj)
     assert len(O.constraints) == 1
     O.constraints[0].narrow(O.variables)
-    assert O.variables['a_'].getValues() == [(O.variables['b_'], None),]
+    assert O.variables['a_'].domain == ['b_']
 
 def test_domain_merge():
     O = Ontology()
@@ -283,26 +283,30 @@
     O.consistency()
     assert ('Alice_', 'Bob_') in O.variables['friend_'].getValues()
 
-def no_test_maxcardinality():
+def test_inverseof():
     
     O = Ontology()
-    #Make functional property
-    sub = URIRef('friend')
+    own = URIRef('owner')
     obj = URIRef(namespaces['owl']+'#ObjectProperty')
-    O.type(sub, None, obj)
+    O.type(own, None, obj)
+    owned = URIRef('ownedby')
+    obj = URIRef(namespaces['owl']+'#ObjectProperty')
+    O.type(owned, None, obj)
+    O.inverseOf(own, None, owned)
     #Make class
     sub = URIRef('c')
     obj = URIRef(namespaces['owl']+'#Class')
     O.type(sub, None, obj)
-    #Make individual with a cardinality restriction of the property
+    #Make individual with a property value
     sub = URIRef('Bob')
     obj = URIRef('c')
     O.type(sub, None, obj)
-    sub = BNode('anon')
-    obj = URIRef(namespaces['owl']+'#Restriction')
+    sub = URIRef('Fiat')
+    obj = URIRef('car')
     O.type(sub, None, obj)
-    O.onProperty(sub, None, URIRef('friend'))
-    O.maxCardinality(sub, None, 1)
-    O.variables['friend_'].setValues([('Bob_',['Alice_','Finn_'])])
-    O.consistency(verbose=5)
+    O.variables['owner_'].setValues([('Bob_','Fiat_')])
+    py.test.raises(ConsistencyFailure, O.consistency)
+    O.variables['ownedby_'].setValues([('Fiat_','Bob_')])
+    print O.variables
+    O.consistency()
     assert not '_anon' in O.variables
\ No newline at end of file



More information about the Pypy-commit mailing list