예제 #1
0
 def manageBroaderRelations(self, relTermSubject, tagSubject):
     tagsBroaderList = utils.genToList(
         self.relatedTerm.rdfGraph.getBroader(tagSubject))
     thisPrefLabelList = utils.genToList(
         self.relatedTerm.rdfGraph.getPrefLabel(relTermSubject))
     for broaderKey in tagsBroaderList:  # is a key, not a tag, and actually just one
         relTermsOfBroader = utils.genToList(
             self.relatedTerm.rdfGraph.getRelatedMatch(broaderKey))
         for broaderRelTerm in relTermsOfBroader:
             if self.relatedTerm.rdfGraph.isInTermScheme(
                     broaderRelTerm
             ) and not broaderRelTerm == relTermSubject:
                 prefLabelList = utils.genToList(
                     self.relatedTerm.rdfGraph.getPrefLabel(broaderRelTerm))
                 altLabelList = utils.genToList(
                     self.relatedTerm.rdfGraph.getAltLabel(broaderRelTerm))
                 for prefLabel in prefLabelList:  # adding those to broader
                     if prefLabel.language == 'en' and prefLabel not in thisPrefLabelList:
                         self.relatedTerm.addBroaderLiteralEN(
                             relTermSubject, str(prefLabel))
                     elif prefLabel.language == 'de' and prefLabel not in thisPrefLabelList:
                         self.relatedTerm.addBroaderLiteralDE(
                             relTermSubject, str(prefLabel))
                 for altLabel in altLabelList:  # adding those to broader
                     if altLabel.language == 'en' and altLabel not in thisPrefLabelList:
                         self.relatedTerm.addBroaderLiteralEN(
                             relTermSubject, str(altLabel))
                     elif altLabel.language == 'de' and altLabel not in thisPrefLabelList:
                         self.relatedTerm.addBroaderLiteralDE(
                             relTermSubject, str(altLabel))
예제 #2
0
 def manageNarrowerRelations(self, relTermSubject, keySubject):
     keysNarrowerList = utils.genToList(
         self.relatedTerm.rdfGraph.getNarrower(keySubject))
     thisPrefLabelList = utils.genToList(
         self.relatedTerm.rdfGraph.getPrefLabel(relTermSubject))
     for narrowerTag in keysNarrowerList:  # is a tag, not a key
         relTermsOfNarrower = utils.genToList(
             self.relatedTerm.rdfGraph.getRelatedMatch(narrowerTag))
         for narrowerRelTerm in relTermsOfNarrower:
             if self.relatedTerm.rdfGraph.isInTermScheme(
                     narrowerRelTerm
             ) and not narrowerRelTerm == relTermSubject:
                 prefLabelList = utils.genToList(
                     self.relatedTerm.rdfGraph.getPrefLabel(
                         narrowerRelTerm))
                 altLabelList = utils.genToList(
                     self.relatedTerm.rdfGraph.getAltLabel(narrowerRelTerm))
                 for prefLabel in prefLabelList:  # adding those to narrower
                     if prefLabel.language == 'en' and prefLabel not in thisPrefLabelList:
                         self.relatedTerm.addNarrowerLiteralEN(
                             relTermSubject, str(prefLabel))
                     elif prefLabel.language == 'de' and prefLabel not in thisPrefLabelList:
                         self.relatedTerm.addNarrowerLiteralDE(
                             relTermSubject, str(prefLabel))
                 for altLabel in altLabelList:  # adding those to narrower
                     if altLabel.language == 'en' and altLabel not in thisPrefLabelList:
                         self.relatedTerm.addNarrowerLiteralEN(
                             relTermSubject, str(altLabel))
                     elif altLabel.language == 'de' and altLabel not in thisPrefLabelList:
                         self.relatedTerm.addNarrowerLiteralDE(
                             relTermSubject, str(altLabel))
예제 #3
0
def apiTerms():
    term = request.args.get('term', '')
    prettyPrint = request.args.get('format', '')

    listRelatedMatches = []

    if websiteRdfGraph is None or term is None or len(term) == 0:
        return jsonify({})

    # subject will only be term subject and not tag subject, because of language
    listRelatedMatches.extend(websiteRdfGraph.getSubByPrefLabelLang(
        term, 'en'))
    listRelatedMatches.extend(websiteRdfGraph.getSubByPrefLabelLang(
        term, 'de'))
    listRelatedMatches.extend(websiteRdfGraph.getSubByAltLabelLang(term, 'en'))
    listRelatedMatches.extend(websiteRdfGraph.getSubByAltLabelLang(term, 'de'))
    listRelatedMatches.extend(websiteRdfGraph.getSubByBroaderLang(term, 'en'))
    listRelatedMatches.extend(websiteRdfGraph.getSubByBroaderLang(term, 'de'))
    listRelatedMatches.extend(websiteRdfGraph.getSubByNarrowerLang(term, 'en'))
    listRelatedMatches.extend(websiteRdfGraph.getSubByNarrowerLang(term, 'de'))

    termRelated = {'en': [], 'de': []}
    termBroader = {'en': [], 'de': []}
    termNarrower = {'en': [], 'de': []}

    for relSubject in listRelatedMatches:
        termRelated = addLiteralToLangDict(
            termRelated,
            utils.genToList(websiteRdfGraph.getPrefLabel(relSubject)))
        termRelated = addLiteralToLangDict(
            termRelated,
            utils.genToList(websiteRdfGraph.getAltLabel(relSubject)))
        termBroader = addLiteralToLangDict(
            termBroader,
            utils.genToList(websiteRdfGraph.getBroader(relSubject)))
        termNarrower = addLiteralToLangDict(
            termNarrower,
            utils.genToList(websiteRdfGraph.getNarrower(relSubject)))

    retDict = {}
    retDict['termRelated'] = termRelated
    retDict['termBroader'] = termBroader
    retDict['termNarrower'] = termNarrower

    if prettyPrint is not None and prettyPrint.lower() == 'json_pretty':
        jsonDump = json.dumps(retDict, indent=3, sort_keys=True)
    else:
        jsonDump = json.dumps(retDict)
    putToUniqueIP(request.remote_addr)
    logger.info('IP: ' + request.remote_addr + ", API terms: " + term)
    return Response(jsonDump, mimetype='application/json')
예제 #4
0
 def removeDuplicates(self, relTermSubject):
     altLabelList = utils.genToList(
         self.relatedTerm.rdfGraph.getAltLabel(relTermSubject))
     broaderList = utils.genToList(
         self.relatedTerm.rdfGraph.getBroader(relTermSubject))
     narrowerList = utils.genToList(
         self.relatedTerm.rdfGraph.getNarrower(relTermSubject))
     for altLabel in altLabelList:
         if altLabel in broaderList or altLabel in narrowerList:
             self.relatedTerm.removeAltLabelLiteral(relTermSubject,
                                                    altLabel)
     for narrower in narrowerList:
         if narrower in broaderList:
             self.relatedTerm.removeNarrowerLiteral(relTermSubject,
                                                    narrower)
예제 #5
0
 def isInScheme(self, subject, obj):
     refScheme = URIRef(obj)
     generator = utils.genToList(self.getInScheme(subject))
     for item in generator:
         if item == refScheme:
             return True
     return False
예제 #6
0
 def finalize(self):
     relTermGen = self.relatedTerm.rdfGraph.getSubByScheme(
         self.termSchemeName)
     relTermList = utils.genToList(relTermGen)
     for relTermSubject in relTermList:
         self.manageRelations(relTermSubject)
         self.removeDuplicates(relTermSubject)
     return self.save()
예제 #7
0
 def manageRelations(self, relTermSubject):
     keyTagSubjectList = utils.genToList(
         self.relatedTerm.rdfGraph.getRelatedMatch(relTermSubject))
     for keyTagSubject in keyTagSubjectList:  # will just be one most of times
         if self.relatedTerm.rdfGraph.isInKeyScheme(
                 keyTagSubject):  # if is key
             self.manageNarrowerRelations(relTermSubject, keyTagSubject)
         elif self.relatedTerm.rdfGraph.isInTagScheme(
                 keyTagSubject):  # else if its tag
             self.manageBroaderRelations(relTermSubject, keyTagSubject)
예제 #8
0
    def handleTags(self, tagList):
        tagsToUpdate = []
        depricatedTags = []

        # split the tags up into those that need updatecheck, are depricated or new. The new ones will be in 'tagList'
        rdfTagsSubjects = utils.genToList(
            self.rdfGraph.getSubByScheme(self.tagSchemeName))
        for tagSubject in rdfTagsSubjects:
            tag = tagSubject.split('Tag:')[1]
            if tag in tagList:
                tagsToUpdate.append(self.osmWikiBase + 'Tag:' + tag)
                tagList.remove(tag)
            else:
                depricatedTags.append(self.osmWikiBase + 'Tag:' + tag)

        self.bt.printMessage('\nCreating new tags:')
        self.handleNewTags(tagList)
        self.bt.printMessage('\nResetting depricated tags:')
        self.handleDepricated(depricatedTags)
        self.bt.printMessage('\nUpdate existing tags:')
        self.handleUpdateTags(tagsToUpdate)
예제 #9
0
    def handleKeys(self, keyList):
        keysToUpdate = []
        depricatedKeys = []

        # split the keys up into those that need updatecheck, are depricated or new. The new ones will be in 'keyList'
        rdfKeysSubjects = utils.genToList(
            self.rdfGraph.getSubByScheme(self.keySchemeName))
        for keySubject in rdfKeysSubjects:
            key = keySubject.split('Key:')[1]
            if key in keyList:
                keysToUpdate.append(self.osmWikiBase + 'Key:' + key)
                keyList.remove(key)
            else:
                depricatedKeys.append(self.osmWikiBase + 'Key:' + key)

        self.bt.printMessage('\nCreating new keys:')
        self.handleNewKeys(keyList)
        self.bt.printMessage('\nResetting depricated keys:')
        self.handleDepricated(depricatedKeys)
        self.bt.printMessage('\nUpdate existing keys:')
        self.handleUpdateKeys(keysToUpdate)
예제 #10
0
 def getTagsOfRelTerm(self, rdfGraph, relTermSubject):
     '''Returns a list of subjects, that point to this RelatedTerm 'subject'.'''
     generatorList = rdfGraph.getRelatedMatch(relTermSubject)
     return utils.genToList(generatorList)
예제 #11
0
 def getSubByNarrowerLang(self, obj, language):
     generatorList = self.graph.subjects(predicate=SKOS.narrower,
                                         object=Literal(obj, lang=language))
     return utils.genToList(generatorList)
예제 #12
0
 def getSubByAltLabelLang(self, obj, language):
     generatorList = self.graph.subjects(predicate=SKOS.altLabel,
                                         object=Literal(obj, lang=language))
     return utils.genToList(generatorList)