61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
|
|
from fluents import dataset
|
|
|
|
_dim_annotation_handlers = {}
|
|
|
|
def get_dim_annotations(dimname, annotation, ids):
|
|
"""Returns a list of annotations corresponding to the given ids in
|
|
dimension dimname"""
|
|
global _dim_annotation_handlers
|
|
|
|
if _dim_annotation_handlers.has_key(dimname):
|
|
return _dim_annotation_handlers[dimname].get_annotations(annotation, ids)
|
|
return None
|
|
|
|
def set_dim_handler(dimname, handler):
|
|
"""Set the handler for the given dimension."""
|
|
global _dim_annotation_handlers
|
|
_dim_annotation_handlers[dimname] = handler
|
|
|
|
def get_dim_handler(dimname):
|
|
"""Get the handler for the given dimension."""
|
|
global _dim_annotation_handlers
|
|
if _dim_annotation_handlers.has_key(dimname):
|
|
return _dim_annotation_handlers[dimname]
|
|
else:
|
|
return None
|
|
|
|
|
|
class AnnotationHandler:
|
|
def __init__(self):
|
|
pass
|
|
|
|
def get_annotations(self, annotationname, ids, default=None):
|
|
return None
|
|
|
|
def get_annotation_names(self):
|
|
return []
|
|
|
|
|
|
class DictAnnotationHandler(AnnotationHandler):
|
|
|
|
def __init__(self, d={}):
|
|
self._dict = d
|
|
|
|
def get_annotations(self, annotationname, ids, default=None):
|
|
d = self._dict
|
|
retval = []
|
|
for id in ids:
|
|
if d[annotationname].has_key(id):
|
|
retval.append(d[annotationname][id])
|
|
else:
|
|
retval.append(default)
|
|
return retval
|
|
|
|
def add_annotations(self, annotationname, d):
|
|
self._dict[annotationname] = d
|
|
|
|
def get_annotation_names(self):
|
|
return self._dict.keys()
|
|
|