* annotations.py: Annotation class for two-way annotations. Does only support

exactly two dimensions.
This commit is contained in:
2006-04-16 22:06:29 +00:00
parent 5853216df4
commit eb45c125aa
3 changed files with 53 additions and 1 deletions

33
system/annotations.py Normal file
View File

@@ -0,0 +1,33 @@
import logger
class Annotations:
def __init__(self, *dimensions):
""" Initializes a new Annotation with the given dimension labels.
dimensions is a list of dimension labels.
"""
if len(dimensions) == 2:
logger.log('error', 'Annotations only supports two dimensions.')
self.dimensions = {}
for d in dimensions:
self.dimensions[d] = {}
def add_annotations(self, dim, id, ann_dim, annotations):
if not self.dimensions[dim]:
logger.log('warning', 'Annotations object does not contain dimension %s' % dim)
return None
for a in annotations:
self.annotations[ann_dim][a].add(id)
self.annotations[dim][id] = annotations
def get_annotations(self, dim, id):
if not self.dimensions[dim]:
logger.log('warning', 'Annotations object does not contain dimension %s' % dim)
return None
if self.dimensions[dim].has_key(id):
return self.dimensions[dim][id].values()
return None
def has_dimension(self, dim):
return self.dimensions.has_key(dim)