34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
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)
|