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