示例#1
0
def from_synapse_annotations(annotations):
    """Transforms a Synapse-style Annotation object to a simple flat dictionary."""
    def process_user_defined_annotations(kvps, annos, func):
        """
        for each annotation of a given class (date, string, double, ...), process the
        annotation with the given function and add it to the dict 'annos'.
        """
        for k, v in kvps.iteritems():
            ## don't overwrite system keys which won't be lists
            if k in ['id', 'etag', 'creationDate', 'uri'
                     ] or (k in annos and not isinstance(annos[k], list)):
                warnings.warn(
                    'A user defined annotation, "%s", has the same name as a system defined annotation and will be dropped. Try syn._getRawAnnotations to get annotations in native Synapse format.'
                    % k)
            else:
                annos.setdefault(k, []).extend([func(elem) for elem in v])

    # Flatten the raw annotations to consolidate doubleAnnotations, longAnnotations,
    # stringAnnotations and dateAnnotations into one dictionary
    annos = dict()
    for key, value in annotations.iteritems():
        if key == 'dateAnnotations':
            process_user_defined_annotations(
                value, annos, lambda x: from_unix_epoch_time(float(x)))
        elif key in ['stringAnnotations', 'longAnnotations']:
            process_user_defined_annotations(value, annos, lambda x: x)
        elif key == 'doubleAnnotations':
            process_user_defined_annotations(value, annos, lambda x: float(x))
        elif key == 'blobAnnotations':
            pass  ## TODO: blob annotations not supported
        else:
            annos[key] = value
    return annos
示例#2
0
def from_synapse_annotations(annotations):
    """Transforms a Synapse-style Annotation object to a simple flat dictionary."""
    
    def process_user_defined_annotations(kvps, annos, func):
        """
        for each annotation of a given class (date, string, double, ...), process the
        annotation with the given function and add it to the dict 'annos'.
        """
        for k,v in kvps.iteritems():
            ## don't overwrite system keys which won't be lists
            if k in ['id', 'etag', 'creationDate', 'uri'] or (k in annos and not isinstance(annos[k], list)):
                warnings.warn('A user defined annotation, "%s", has the same name as a system defined annotation and will be dropped. Try syn._getRawAnnotations to get annotations in native Synapse format.' % k)
            else:
                annos.setdefault(k,[]).extend([func(elem) for elem in v])

    # Flatten the raw annotations to consolidate doubleAnnotations, longAnnotations,
    # stringAnnotations and dateAnnotations into one dictionary
    annos = dict()
    for key, value in annotations.iteritems():
        if key=='dateAnnotations':
            process_user_defined_annotations(value, annos, lambda x: from_unix_epoch_time(float(x)))
        elif key in ['stringAnnotations','longAnnotations']:
            process_user_defined_annotations(value, annos, lambda x: x)
        elif key == 'doubleAnnotations':
            process_user_defined_annotations(value, annos, lambda x: float(x))
        elif key=='blobAnnotations':
            pass ## TODO: blob annotations not supported
        else:
            annos[key] = value
    return annos
def from_synapse_annotations(annotations):
    """Transforms a Synapse-style Annotation object to a simple flat dictionary."""
    
    # Flatten the raw annotations to consolidate doubleAnnotations, longAnnotations,
    # stringAnnotations and dateAnnotations into one dictionary
    annos = dict()
    for key, value in annotations.iteritems():
        if key=='dateAnnotations':
            for k,v in value.iteritems():
                # print "%s=>%s\n" % (k,v,)
                annos.setdefault(k,[]).extend([from_unix_epoch_time(float(t)) for t in v])
        elif key in ['stringAnnotations','longAnnotations','doubleAnnotations']:
            for k,v in value.iteritems():
                annos.setdefault(k,[]).extend(v)
        elif key=='blobAnnotations':
            pass ## TODO: blob annotations not supported
        else:
            annos[key] = value
    return annos
def from_synapse_annotations(annotations):
    """Transforms a Synapse-style Annotation object to a simple flat dictionary."""
    
    # Flatten the raw annotations to consolidate doubleAnnotations, longAnnotations,
    # stringAnnotations and dateAnnotations into one dictionary
    annos = dict()
    for key, value in annotations.iteritems():
        if key=='dateAnnotations':
            for k,v in value.iteritems():
                annos.setdefault(k,[]).extend([from_unix_epoch_time(float(t)) for t in v])
        elif key in ['stringAnnotations','longAnnotations']:
            for k,v in value.iteritems():
                annos.setdefault(k,[]).extend(v)
        elif key == 'doubleAnnotations':
            for k,v in value.iteritems():
                annos.setdefault(k,[]).extend(float(element) for element in v)
        elif key=='blobAnnotations':
            pass ## TODO: blob annotations not supported
        else:
            annos[key] = value
    return annos