Example #1
0
    def removeSimpleAnnotation(self, rofile, attrname, attrvalue):
        """
        Remove a simple annotation or multiple matching annotations a research object.

        rofile      names the annotated file or resource, possibly relative to the RO.
        attrname    names the attribute in a form recognized by getAnnotationByName
        attrvalue   is the attribute value to be deleted, or Nomne to delete all vaues
        """
        assert self._isLocal()
        ro_dir = self.getRoFilename()
        ro_graph = self._loadManifest()
        subject = self.getComponentUri(rofile)
        (predicate,
         valtype) = ro_annotation.getAnnotationByName(self.roconfig, attrname)
        val = attrvalue and ro_annotation.makeAnnotationValue(
            self.roconfig, attrvalue, valtype)
        add_annotations = []
        remove_annotations = []
        log.debug("removeSimpleAnnotation subject %s, predicate %s, val %s" %
                  (str(subject), str(predicate), val))
        # Scan for annotation graph resources containing this annotation
        for ann_node in self._iterAnnotations(subject=subject):
            ann_uri = ro_graph.value(subject=ann_node, predicate=AO.body)
            log.debug("removeSimpleAnnotation ann_uri %s" % (str(ann_uri)))
            if self.isRoMetadataRef(ann_uri):
                ann_graph = self._readAnnotationBody(
                    self.getComponentUriRel(ann_uri))
                log.debug("removeSimpleAnnotation ann_graph %s" % (ann_graph))
                if (subject, predicate, val) in ann_graph:
                    ann_graph.remove((subject, predicate, val))
                    if (subject, None, None) in ann_graph:
                        # Triples remain in annotation body: write new body and update RO graph
                        ann_name = self._createAnnotationGraphBody(
                            rofile, ann_graph)
                        remove_annotations.append(ann_node)
                        add_annotations.append(ann_name)
                    else:
                        # Remove annotation from RO graph
                        remove_annotations.append(ann_node)
        # Update RO manifest graph if needed
        if add_annotations or remove_annotations:
            for a in remove_annotations:
                self._removeAnnotationFromManifest(a)
            for a in add_annotations:
                self._addAnnotationToManifest(rofile, a)
            self._updateManifest()
        return
Example #2
0
    def removeSimpleAnnotation(self, rofile, attrname, attrvalue):
        """
        Remove a simple annotation or multiple matching annotations a research object.

        rofile      names the annotated file or resource, possibly relative to the RO.
        attrname    names the attribute in a form recognized by getAnnotationByName
        attrvalue   is the attribute value to be deleted, or Nomne to delete all vaues
        """
        assert self._isLocal()
        ro_dir    = self.getRoFilename()
        ro_graph  = self._loadManifest()
        subject     = self.getComponentUri(rofile)
        (predicate,valtype) = ro_annotation.getAnnotationByName(self.roconfig, attrname)
        val         = attrvalue and ro_annotation.makeAnnotationValue(self.roconfig, attrvalue, valtype)
        add_annotations    = []
        remove_annotations = []
        log.debug("removeSimpleAnnotation subject %s, predicate %s, val %s"%
                  (str(subject), str(predicate), val))
        # Scan for annotation graph resources containing this annotation
        for ann_node in self._iterAnnotations(subject=subject):
            ann_uri   = ro_graph.value(subject=ann_node, predicate=AO.body)
            log.debug("removeSimpleAnnotation ann_uri %s"%(str(ann_uri)))
            if self.isRoMetadataRef(ann_uri):
                ann_graph = self._readAnnotationBody(self.getComponentUriRel(ann_uri))
                log.debug("removeSimpleAnnotation ann_graph %s"%(ann_graph))
                if (subject, predicate, val) in ann_graph:
                    ann_graph.remove((subject, predicate, val))
                    if (subject, None, None) in ann_graph:
                        # Triples remain in annotation body: write new body and update RO graph
                        ann_name = self._createAnnotationGraphBody(rofile, ann_graph)
                        remove_annotations.append(ann_node)
                        add_annotations.append(ann_name)
                    else:
                        # Remove annotation from RO graph
                        remove_annotations.append(ann_node)
        # Update RO manifest graph if needed
        if add_annotations or remove_annotations:
            for a in remove_annotations:
                self._removeAnnotationFromManifest(a)
            for a in add_annotations:
                self._addAnnotationToManifest(rofile, a)
            self._updateManifest()
        return
    def replaceSimpleAnnotation(self, rofile, attrname, attrvalue):
        """
        Replace a simple annotation in a research object.

        rofile      names the file or resource to be annotated, possibly relative to the RO.
        attrname    names the attribute in a form recognized by getAnnotationByName
        attrvalue   is a new value to be associated with the attribute
        """
        assert self._isLocal()
        ro_dir   = self.getRoFilename()
        ro_graph = self._loadManifest()
        subject  = self.getComponentUri(rofile)
        (predicate,valtype) = ro_annotation.getAnnotationByName(self.roconfig, attrname)
        log.debug("Replace annotation: subject %s, predicate %s, value %s"%
                  (repr(subject), repr(predicate), repr(attrvalue)))
        ro_graph.remove((subject, predicate, None))
        ro_graph.add((subject, predicate,
                      ro_annotation.makeAnnotationValue(self.roconfig, attrvalue, valtype)))
        self._updateManifest()
        return
Example #4
0
    def replaceSimpleAnnotation(self, rofile, attrname, attrvalue):
        """
        Replace a simple annotation in a research object.

        rofile      names the file or resource to be annotated, possibly relative to the RO.
        attrname    names the attribute in a form recognized by getAnnotationByName
        attrvalue   is a new value to be associated with the attribute
        """
        assert self._isLocal()
        ro_dir = self.getRoFilename()
        ro_graph = self._loadManifest()
        subject = self.getComponentUri(rofile)
        (predicate,
         valtype) = ro_annotation.getAnnotationByName(self.roconfig, attrname)
        log.debug("Replace annotation: subject %s, predicate %s, value %s" %
                  (repr(subject), repr(predicate), repr(attrvalue)))
        ro_graph.remove((subject, predicate, None))
        ro_graph.add(
            (subject, predicate,
             ro_annotation.makeAnnotationValue(self.roconfig, attrvalue,
                                               valtype)))
        self._updateManifest()
        self.roannotations = None  # Flush cached annotation graph
        return