[pypy-svn] r26993 - in pypy/dist/pypy/lib/pyontology: . test
ale at codespeak.net
ale at codespeak.net
Tue May 9 12:30:25 CEST 2006
Author: ale
Date: Tue May 9 12:30:24 2006
New Revision: 26993
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:
Converted functionalporperty, symmentricproperty and inverefunctinalproperty
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 Tue May 9 12:30:24 2006
@@ -172,10 +172,10 @@
subdom = domains[self.variable]
superdom = domains[self.object]
vals = superdom.getValues()
- for val in subdom.getValues():
- if not val in vals:
- vals.append(val)
- superdom.setValues(vals)
+ for (key, val) in subdom.getValues():
+ if not (key, val) in superdom:
+ for v in val:
+ superdom.addValue(key, v)
class EquivalentPropertyConstraint(SubClassConstraint):
@@ -304,11 +304,11 @@
if hasattr(dom, '_dict'):
val = Linkeddict(vals)
if self.variable in val.keys() and not self.object in val.keys():
- vals +=[(self.object,v) for v in val[self.variable]]
- dom.setValues(vals)
+ vals +=[dom.addValue(self.object,v) for v in val[self.variable]]
+ #dom.setValues(vals)
elif not self.variable in val.keys() and self.object in val.keys():
- vals +=[(self.variable,v) for v in val[self.object]]
- dom.setValues(vals)
+ vals +=[dom.addValue(self.variable,v) for v in val[self.object]]
+ #dom.setValues(vals)
elif self.variable in val.keys() and self.object in val.keys():
if not val[self.object] == val[self.variable]:
raise ConsistencyFailure("Sameas failure: The two individuals (%s, %s) \
Modified: pypy/dist/pypy/lib/pyontology/pyontology.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/pyontology.py (original)
+++ pypy/dist/pypy/lib/pyontology/pyontology.py Tue May 9 12:30:24 2006
@@ -110,7 +110,7 @@
def __init__(self, name='', values=[], bases = []):
ClassDomain.__init__(self, name, values, bases)
- self._dict = Linkeddict()
+ self._dict = {}
self.range = []
self.domain = []
@@ -123,7 +123,9 @@
self._dict[key].append(val)
def setValues(self, values):
- self._dict = Linkeddict(values)
+ for key, val in values:
+ print val
+ self.addValue(key, val)
def removeValues(self, values):
for k,v in values:
@@ -168,25 +170,52 @@
def __init__(self, name='', values=[], bases = []):
Property.__init__(self, name, values, bases)
- self.constraint = FunctionalCardinality(name)
+# self.constraint = FunctionalCardinality(name)
+ def addValue(self, key, val):
+ Property.addValue(self, key, val)
+ if len(self._dict[key]) > 1:
+ raise ConsistencyFailure("FunctionalProperties can only have one value")
+
class InverseFunctionalProperty(Property):
def __init__(self, name='', values=[], bases = []):
Property.__init__(self, name, values, bases)
self.constraint = InverseFunctionalCardinality(name)
+ def addValue(self, key, val):
+ Property.addValue(self, key, val)
+ valuelist = [set(x) for x in self._dict.values()]
+ res = set()
+ for vals in valuelist:
+ if vals & res:
+ raise ConsistencyFailure("Only unique values in InverseFunctionalProperties")
+ res = res | vals
+
class TransitiveProperty(Property):
def __init__(self, name='', values=[], bases = []):
Property.__init__(self, name, values, bases)
- self.constraint = TransitiveConstraint(name)
+ #self.constraint = TransitiveConstraint(name)
+ def addValue(self, key, val):
+ Property.addValue(self, key, val)
+ if val in self._dict.keys():
+ for v in self._dict[val]:
+ Property.addValue(self, key, v)
+ for k in self._dict.keys():
+ if key in self._dict[k]:
+ Property.addValue(self, k, val)
+
class SymmetricProperty(Property):
def __init__(self, name='', values=[], bases = []):
Property.__init__(self, name, values, bases)
- self.constraint = SymmetricConstraint(name)
+# self.constraint = SymmetricConstraint(name)
+
+ def addValue(self, key, val):
+ Property.addValue(self, key, val)
+ Property.addValue(self, val, key)
class Restriction(ClassDomain):
""" A owl:restriction is an anonymous class that links a class to a restriction on a property
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 Tue May 9 12:30:24 2006
@@ -225,9 +225,8 @@
O.variables['p_'].setValues([('individ_',42)])
#assert len(O.constraints) == 2
#add another valueof the property
- O.variables['p_'].setValues([('individ_',42),('individ_',43)])
+ py.test.raises(ConsistencyFailure, O.variables['p_'].setValues,[('individ_',42),('individ_',43)])
#check that consistency raises
- py.test.raises(ConsistencyFailure, O.consistency)
def test_inversefunctionalproperty():
@@ -250,12 +249,9 @@
sub = URIRef('individ2')
obj = URIRef('c')
O.type(sub, obj)
- O.variables['p_'].setValues([('individ_',42),('individ2_',42)])
- #check that consistency raises
- py.test.raises(ConsistencyFailure, O.consistency)
+ py.test.raises(ConsistencyFailure, O.variables['p_'].setValues, [('individ_',42),('individ2_',42)])
def test_Transitiveproperty():
- #py.test.skip("in transit")
O = Ontology()
#Make functional property
sub = URIRef('subRegionOf')
@@ -277,9 +273,7 @@
O.consistency()
assert 'Chianti_' in O.variables['subRegionOf_']._dict['Italy_']
-def test_symmetricproperty():
- #py.test.skip("in transit")
-
+def test_symmetricproperty():
O = Ontology()
#Make functional property
sub = URIRef('friend')
More information about the Pypy-commit
mailing list