def processLanguage(self, results, language, path=("",)):
     result = {}
     for element in results.keys():
         (identifier, children) = results[element]
         (lang, text) = element.split(LANG_SEPARATOR, 1)
         if lang == language:
             extended_path = PATH_SEPARATOR.join(path)
             extended_path = PATH_SEPARATOR.join((extended_path, text))
             result[extended_path] = identifier
             result.update(self.processLanguage(children, language, path + (text,)))
     return result
Example #2
0
 def processLanguage(self, results, language, path=('', )):
     result = {}
     for element in results.keys():
         (identifier, children) = results[element]
         (lang, text) = element.split(LANG_SEPARATOR, 1)
         if lang == language:
             extended_path = PATH_SEPARATOR.join(path)
             extended_path = PATH_SEPARATOR.join((extended_path, text))
             result[extended_path] = identifier
             result.update(
                 self.processLanguage(children, language, path + (text, )))
     return result
    def buildPathIndex(self):
        pathIndex = {}
        for (language, children) in self.taxonomy.data.items():
            if language == self.taxonomy.default_language:
                for (path, identifier) in children.items():
                    parent_path = path.split(PATH_SEPARATOR)[:-1]
                    parent_identifier = children.get(PATH_SEPARATOR.join(parent_path))
                    if not parent_identifier in pathIndex:
                        pathIndex[parent_identifier] = set()
                    pathIndex[parent_identifier].add(identifier)

        if None not in pathIndex:
            raise ValueError("No root node!")

        return self.buildFinalPathIndex(pathIndex[None], pathIndex)
Example #4
0
    def buildPathIndex(self):
        pathIndex = {}
        for (language, children) in self.taxonomy.data.items():
            if language == self.taxonomy.default_language:
                for (path, identifier) in children.items():
                    parent_path = path.split(PATH_SEPARATOR)[:-1]
                    parent_identifier = children.get(
                        PATH_SEPARATOR.join(parent_path))
                    if parent_identifier not in pathIndex:
                        pathIndex[parent_identifier] = set()
                    pathIndex[parent_identifier].add(identifier)

        if None not in pathIndex:
            raise ValueError("No root node!")

        return self.buildFinalPathIndex(pathIndex[None], pathIndex)