예제 #1
0
 def GetEntityName(self, uri):
     v = kb.uri2name(uri)
     if v:
         return v
     for m, doc in self.modules.iteritems():
         for p in kb.all_labels:
             name = doc.grLiteral(uri, p)
             if name:
                 return '.'.join((m, name))
     return None
예제 #2
0
    def GetNameAndIcon(self, value, tp = None):
        is_uri = IsUri(value)

        if is_uri:
            v = kb.uri2name(value)
            if v:
                is_uri = False
                value = v

        if tp:
            if tp.startswith('patterns.'):
                return value, 'iso_literal'

            v = kb.uri2name(tp)
            if v:
                tp = v
 
            roles = self.GetTypeRoles(tp)
            role = None
            if roles:
                if is_uri:
                    for v in roles.itervalues():
                        if value == v.get('uri'):
                            role = v
                            break
                else:
                    role = roles.get(value)

            if role:
                if tp.startswith('part2.'):
                    type_uri = role['type_uri']
                    if type_uri.startswith('xsd:'):
                        return role['name'], 'iso_syntax'
                    else:
                        return role['name'], kb.icons_map.get(kb.part2_itself[type_uri]['icon'], 'iso_unknown')
                else:
                    doc = self.GetEntityDoc(tp)
                    type_uri = roles[value]['type_uri']
                    restricted_by_value = roles[value].get('restricted_by_value', False)
                    type_label, type_icon = doc.infGetRestrictionNameAndIcon(type_uri, restricted_by_value)
                    return role['name'], type_icon
        else:
            uri = None
            if is_uri:
                uri = value
            else:
                path = value.split('.')
                if path[0] == 'part2':
                    if 'part2:'+path[1] in kb.part2_itself:
                        return path[1], kb.part2_itself['part2:'+path[1]]['icon']
                if len(path) > 1:
                    uri = self.GetEntityUri(path[0], path[1])
            if uri:
                doc = self.GetEntityDoc(uri)
                if doc:
                    name, tp_label, icon  = doc.infGetEntityVisual(uri)
                    if isinstance(name, list):
                        name = ', '.join(name)
                    return name, icon

        for k, v in appdata.project.annotations:
            if (is_uri and v == value) or (not is_uri and k == value):
                return k, 'iso_annotation'

        for k, v in appdata.project.roles:
            if (is_uri and v == value) or (not is_uri and k == value):
                return k, 'iso_role'

        return value, 'iso_unknown'