def showAnnotations(ro_config, ro_dir, annotations, outstr):
    sname_prev = None
    for (asubj,apred,aval) in annotations:
        # log.debug("Annotations: asubj %s, apred %s, aval %s"%
        #           (repr(asubj), repr(apred), repr(aval)))
        if apred != ORE.aggregates:
            (aname, atype) = getAnnotationByUri(ro_config, apred)
            sname = ro_manifest.getComponentUriRel(ro_dir, str(asubj))
            log.debug("Annotations: sname %s, aname %s"%(sname, aname))
            if sname == "":
                sname = ro_manifest.getRoUri(ro_dir)
            if sname != sname_prev:
                print "\n<"+str(sname)+">"
                sname_prev = sname
            outstr.write("  %s %s\n"%(aname, formatAnnotationValue(aval, atype)))
    return
def _getRoAnnotations(ro_dir):
    """
    Returns iterator over annotations applied to the RO as an entity.

    Each value returned by the iterator is a (subject,predicate,object) triple.
    """
    ro_graph = ro_manifest.readManifestGraph(ro_dir)
    subject  = ro_manifest.getRoUri(ro_dir)
    log.debug("getRoAnnotations %s"%str(subject))
    for ann_node in ro_graph.subjects(predicate=RO.annotatesAggregatedResource, object=subject):
        ann_uri   = ro_graph.value(subject=ann_node, predicate=AO.body)
        ann_graph = readAnnotationBody(ro_dir, ro_manifest.getComponentUriRel(ro_dir, ann_uri))
        if ann_graph:
            for (p, v) in ann_graph.predicate_objects(subject=subject):
                #log.debug("Triple: %s %s %s"%(subject,p,v))
                yield (subject, p, v)
    return
def createAnnotationGraphBody(ro_config, ro_dir, rofile, anngraph):
    """
    Create a new annotation body for a single resource in a research object, based
    on a supplied graph value.

    Existing annotations for the same resource are not touched; if an annotation is being
    added or replaced, it is the calling program'sresponsibility to update the manifest to
    reference the active annotations.  A new name is allocated for the created annotation,
    graph which is returned as the result of this function.

    ro_config   is the research object manager configuration, supplied as a dictionary
    ro_dir      is the research object root directory
    rofile      is the name of the Research Object component to be annotated, possibly
                relative to the RO root directory.
    anngraph    is an annotation graph that is to be saved.

    Returns the name of the annotation body created relative to the RO
    manifest and metadata directory.
    """
    # Determine name for annotation body
    log.debug("createAnnotationGraphBody: %s, %s"%(ro_dir, rofile))
    annotation_filename = None
    name_index = 0
    name_suffix = os.path.basename(rofile)
    if name_suffix in [".",""]:
        name_suffix = os.path.basename(os.path.normpath(ro_dir))
    today = datetime.date.today()
    while annotation_filename == None:
        name_index += 1
        name = ("Ann-%04d%02d%02d-%04d-%s.rdf"%
                (today.year, today.month, today.day, name_index, name_suffix))
        if not os.path.exists(makeAnnotationFilename(ro_dir, name)):
            annotation_filename = name
    # Create annotation body file
    log.debug("createAnnotationGraphBody: %s"%(annotation_filename))
    anngraph.serialize(destination=makeAnnotationFilename(ro_dir, annotation_filename),
        format='xml', base=ro_manifest.getRoUri(ro_dir), xml_base="..")
    return annotation_filename