[pypy-svn] r33781 - in pypy/dist/pypy/lib/pyontology: . test
ale at codespeak.net
ale at codespeak.net
Thu Oct 26 18:58:30 CEST 2006
Author: ale
Date: Thu Oct 26 18:58:28 2006
New Revision: 33781
Modified:
pypy/dist/pypy/lib/pyontology/constraint_classes.py
pypy/dist/pypy/lib/pyontology/pyontology.py
pypy/dist/pypy/lib/pyontology/test/test_ontology.py
Log:
Fixed unioOf
Modified: pypy/dist/pypy/lib/pyontology/constraint_classes.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/constraint_classes.py (original)
+++ pypy/dist/pypy/lib/pyontology/constraint_classes.py Thu Oct 26 18:58:28 2006
@@ -443,28 +443,6 @@
inter = inter.intersection(set(domains[v].getValues()))
assert len(inter) > 0
cls = domains[self.variable].setValues(inter)
- term = {}
- for l in [domains[x] for x in val]:
- if hasattr(l,'TBox'):
- TBox = l.TBox
- prop = l.property
- for item in TBox.values():
- term.setdefault(prop,[])
- term[prop].append(item)
- for prop in term:
- axioms = term[prop]
- ranges = [ax[0] for ax in axioms]
- res = []
- while axioms:
- r, comp = axioms.pop(0)
- if res:
- res = [x for x in res if eval('x %s r' % comp)]
- else:
- res = [x for x in r if eval('x %s r' % comp)]
- if not res:
- axioms.append((r,comp))
- if not res:
- raise ConsistencyFailure("Inconsistent use of intersectionOf")
class SomeValueConstraint(OneofPropertyConstraint):
Modified: pypy/dist/pypy/lib/pyontology/pyontology.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/pyontology.py (original)
+++ pypy/dist/pypy/lib/pyontology/pyontology.py Thu Oct 26 18:58:28 2006
@@ -883,18 +883,12 @@
self.variables[svar] = s_cls
def unionOf(self,s, var):
- var = self.flatten_rdf_list(var)
-
- res = []
- for val in self.variables[var].getValues():
- self.get_individuals_of(val)
- var_name = self.make_var(ClassDomain, val)
- val = self.variables[var_name].getValues()
- res.extend([x for x in val])
+ avar = self.flatten_rdf_list(var)
+ res = [self.mangle_name(x) for x in self.variables[avar]]
+ self.variables[avar] = ClassDomain(avar, var, res)
svar = self.make_var(ClassDomain, s)
- vals = list(self.variables[svar].getValues())
- res.extend(vals)
- self.variables[svar].setValues(res)
+ cons = UnionofConstraint(svar, avar)
+ self.constraints.append(cons)
def intersectionOf(self, s, var):
avar = self.flatten_rdf_list(var)
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 Thu Oct 26 18:58:28 2006
@@ -492,14 +492,14 @@
assert cls in O.variables[O.make_var(None, cls)]
def test_unionof():
- py.test.skip("Rewrite the test")
+ #py.test.skip("Rewrite the test")
O = Ontology()
cls = BNode('anon')
own1 = BNode('liist1')
own2 = BNode('liist2')
list1 = ['1', '2', '3']
list2 = ['3', '4', '5']
- own = [list1, list2]
+ own = [own1, own2]
O.oneOf( own1, list1)
O.oneOf( own2, list2)
O.unionOf(cls, own)
@@ -507,7 +507,7 @@
O.consistency()
res = list(O.rep._domains[cls].getValues())
res.sort()
- assert res == ['1', '2', '3', '4', '5']
+ assert set(res) == set([Individual(x,x) for x in ['1', '2', '3', '4', '5']])
def test_intersectionof():
py.test.skip("Rewrite the test")
More information about the pypy-svn
mailing list