예제 #1
0
    def addKeyword(self, name, title="", description="", shortDescription="", uid=""):
        """Create a keyword in the current ontology. If 'uid' is specified, the referenced keyword is registered as 'name'.

        Exceptions:
            ValidationException : 'name' is not a valid XML NCName.
            NameError           : Keyword 'name' already exists in current ontology.
            AttributeError      : 'uid' references no keyword in current ontology.
        """
        if not owl.isXMLNCName(name):
            raise ValidationException("Invalid name for keyword specified")

        if self.isUsedName(name):
            raise NameError, "Keyword '%s' already exists in current ontology" % name

        storage = self.getStorage()
        if not uid:
            uid = generateUniqueId('Keyword')
            storage.invokeFactory('Keyword', uid)
        kw = getattr(storage, uid)
        if not title:
            title = name
        kw.setName(name)
        kw.setTitle(title)
        kw.setKwDescription(description)
        kw.setShortAdditionalDescription(shortDescription)
        kw.unmarkCreationFlag()
        kw.reindexObject()
        zLOG.LOG(PROJECTNAME, zLOG.INFO,
                 "Added keyword %s." % name)

        return kw
예제 #2
0
    def addRelation(self, name, weight=0.0, types=[], inverses=[], uid=""):
        """Create a keyword relation 'name' in the Plone Relations library, if non-existant.

        'weight' is set in any case if in [0,1]. For each item in the 'types' list from {'transitive', 'symmetric', 'functional', 'inversefunctional'} an appropiate rule is created in the Relations ruleset. For each relation name in the 'inverses' list an InverseImplicator rule is created in the Relations ruleset. The inverse keyword relation is created in the Plone Relations library if non-existant. Rules for inferring types for the inverse relation are created. If 'uid' is specified, the referenced relation ruleset is registered as relation 'name'.

        Exceptions:
            ValidationException : 'name' is not a valid XML NCName.
            NameError           : Relation 'name' already exists in current ontology.
            AttributeError      : 'uid' references no relation in current ontology.
        """
        if not owl.isXMLNCName(name):
            raise ValidationException("Invalid name for relation specified")

        if self.isUsedName(name, 'Ruleset'):
            raise NameError, "Relation '%s' already exists in current ontology" % name

        relations_library = getToolByName(self, 'relations_library')

        if not uid:
            uid = generateUniqueId('Ruleset')
            relations_library.invokeFactory('Ruleset', uid)

        ruleset = relations_library.getRuleset(uid)
        ruleset.setTitle(name)
        ruleset.reindexObject()
        ruleset.unmarkCreationFlag()

        self.setWeight  (name, weight)

        if type(types) != ListType:
            types = [types]
        self.setTypes   (name, types)

        if type(inverses) != ListType:
            inverses = [inverses]
        self.setInverses(name, inverses)

        zLOG.LOG(PROJECTNAME, zLOG.INFO,
                 "Added relation %s." % name)

        return ruleset