当前位置: 首页>>代码示例>>Python>>正文


Python Entity.label方法代码示例

本文整理汇总了Python中opencontext_py.apps.entities.entity.models.Entity.label方法的典型用法代码示例。如果您正苦于以下问题:Python Entity.label方法的具体用法?Python Entity.label怎么用?Python Entity.label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在opencontext_py.apps.entities.entity.models.Entity的用法示例。


在下文中一共展示了Entity.label方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_vocabulary_entity_from_proj_context

# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import label [as 别名]
 def get_vocabulary_entity_from_proj_context(self, object_id, item_type):
     """ get a predicate or type from the project_context """
     # id_keys are used to look for identifiers in json_ld items that can be
     # used to reference object_ids
     ent = False
     id_keys = [
         '@id',
         'id',
         'uuid',
         'slug',
         'owl:sameAs'
     ]
     # print('try to look for ' + object_id + ' ' + item_type)
     # print('proj_context: ' + str(self.proj_context_json_ld))
     if isinstance(self.proj_context_json_ld, dict) \
        and item_type in self.ITEM_TYPE_PROJ_VOCAB_LIST:
         if '@graph' in self.proj_context_json_ld:
             vocab = self.proj_context_json_ld['@graph']
         else:
             vocab = []
             for key, item in self.proj_context_json_ld:
                 if key != '@context':
                     vocab.append(item)
         for item in vocab:
             id_match = False
             for id_key in id_keys:
                 id_match = False
                 if id_key in item:
                     if object_id == item[id_key]:
                         # the object id matches an identifer
                         id_match = True
                         break
             if id_match:
                 # print('found this: ' + str(item))
                 ent = Entity()
                 ent.item_json_ld = item
                 ent.slug_uri = None
                 if 'id' in item:
                     ent.uri = item['id']
                 elif '@id' in item:
                     ent.uri = item['@id']
                 elif 'owl:sameAs' in item:
                     ent.uri = item['owl:sameAs']
                 if isinstance(ent.uri, str):
                     # identify the item_type by looking at the URI
                     for act_type in self.ITEM_TYPE_PROJ_VOCAB_LIST:
                         if ('/' + act_type + '/') in ent.uri:
                             ent.item_type = act_type
                 if 'uuid' in item:
                     ent.uuid = item['uuid']
                 if 'slug' in item:
                     ent.slug = item['slug']
                     if ent.item_type == 'predicates':
                         # make a predicate slug URI
                         ent.slug_uri = 'oc-pred:' + ent.slug
                 if 'label' in item:
                     ent.label = item['label']
                 break
     return ent
开发者ID:ekansa,项目名称:open-context-py,代码行数:61,代码来源:partsjsonld.py


注:本文中的opencontext_py.apps.entities.entity.models.Entity.label方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。