本文整理汇总了Python中opencontext_py.apps.entities.entity.models.Entity.dereference方法的典型用法代码示例。如果您正苦于以下问题:Python Entity.dereference方法的具体用法?Python Entity.dereference怎么用?Python Entity.dereference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opencontext_py.apps.entities.entity.models.Entity
的用法示例。
在下文中一共展示了Entity.dereference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_parent_slug_by_slug
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def get_parent_slug_by_slug(self, child_slug):
""" gets the slug for a parent item
from a child item's slug
"""
self.recurse_count = 0
self.contexts_list = []
self.contexts = {}
output = False
ent = Entity()
found = ent.dereference(child_slug)
if found:
self.get_parents_by_child_uuid(ent.uuid, False)
if len(self.contexts_list) > 0:
parent_uuid = self.contexts_list[0]
# clear class so we can use this again
self.contexts_list = []
self.contexts = {}
self.recurse_count = 0
ent_p = Entity()
found_p = ent_p.dereference(parent_uuid)
if found_p:
output = ent_p.slug
else:
print('Cannot dereference parent_uuid: ' + parent_uuid)
else:
# print('No parent item found. (Root Context)')
pass
else:
print('Cannot find the item for slug: ' + child_slug)
return output
示例2: get_entity_db
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def get_entity_db(self, identifier, context_id, is_path=False):
""" returns an entity object
via database calls
"""
output = False
found = False
entity = Entity()
if is_path:
found = entity.context_dereference(identifier)
else:
found = entity.dereference(identifier)
if found is False:
# case of linked data slugs
found = entity.dereference(identifier, identifier)
if found:
if is_path:
self.entities[context_id] = entity
else:
self.entities[identifier] = entity
if entity.uuid is not False:
self.entities[entity.uuid] = entity
if entity.slug is not False:
self.entities[entity.slug] = entity
output = entity
return output
示例3: make_dict_from_anno_obj
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def make_dict_from_anno_obj(self, anno_obj):
""" returns an ordered dict for an import field annotation object """
anno_dict = LastUpdatedOrderedDict()
anno_dict['id'] = anno_obj.id
sub_field_obj = self.get_field_object(anno_obj.field_num)
if sub_field_obj is not False:
anno_dict['subject'] = self.make_dict_from_field_obj(sub_field_obj)
anno_dict['subject']['id'] = anno_obj.field_num
else:
anno_dict['subject'] = False
if anno_obj.predicate_field_num > 0:
pred_field_obj = self.get_field_object(anno_obj.predicate_field_num)
anno_dict['predicate'] = self.make_dict_from_field_obj(pred_field_obj)
anno_dict['predicate']['id'] = anno_obj.predicate_field_num
anno_dict['predicate']['type'] = 'import-field'
else:
anno_dict['predicate'] = LastUpdatedOrderedDict()
anno_dict['predicate']['id'] = anno_obj.predicate
ent = Entity()
found = ent.dereference(anno_obj.predicate)
if found:
anno_dict['predicate']['label'] = ent.label
anno_dict['predicate']['type'] = ent.item_type
elif anno_obj.predicate == ImportFieldAnnotation.PRED_CONTAINED_IN:
anno_dict['predicate']['label'] = 'Contained in'
elif anno_obj.predicate == ImportFieldAnnotation.PRED_DESCRIBES:
anno_dict['predicate']['label'] = 'Describes'
elif anno_obj.predicate == ImportFieldAnnotation.PRED_VALUE_OF:
anno_dict['predicate']['label'] = 'Value of'
elif anno_obj.predicate == ImportFieldAnnotation.PRED_MEDIA_PART_OF:
anno_dict['predicate']['label'] = 'Media part of'
elif anno_obj.predicate == ImportFieldAnnotation.PRED_DOC_Text:
anno_dict['predicate']['label'] = 'Has document text'
elif anno_obj.predicate == ImportFieldAnnotation.PRED_DRAFT_CONTAINS:
anno_dict['predicate']['label'] = 'Contains (part. hierarchy)'
elif anno_obj.predicate == ImportFieldAnnotation.PRED_COMPLEX_DES:
anno_dict['predicate']['label'] = 'Has Complex Description'
elif anno_obj.predicate == ImportFieldAnnotation.PRED_OBS_NUM:
anno_dict['predicate']['label'] = 'Is Observation Number Of'
else:
anno_dict['predicate']['label'] = False
anno_dict['predicate']['type'] = False
if anno_obj.object_field_num > 0:
obj_field_obj = self.get_field_object(anno_obj.object_field_num)
anno_dict['object'] = self.make_dict_from_field_obj(obj_field_obj)
anno_dict['object']['id'] = anno_obj.object_field_num
anno_dict['object']['type'] = 'import-field'
else:
anno_dict['object'] = LastUpdatedOrderedDict()
anno_dict['object']['id'] = anno_obj.object_uuid
ent = Entity()
found = ent.dereference(anno_obj.object_uuid)
if found:
anno_dict['object']['label'] = ent.label
anno_dict['object']['type'] = ent.item_type
else:
anno_dict['object']['label'] = False
anno_dict['object']['type'] = False
return anno_dict
示例4: get_containment_children
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def get_containment_children(self,
entity_obj,
depth=1,
first_time=True):
""" gets a spatial containment
hierarchy. If the entity_obj.item_type = 'projects'
then the get the project's root parents.
It the entity_obj.item_type is subjects, then get
items containtained by the uuid
"""
cont = Containment()
if entity_obj.item_type == 'projects':
tree = self.make_containment_item(entity_obj)
tree['children'] = []
child_list = cont.get_project_top_level_contexts(entity_obj.uuid)
for child_uuid in child_list:
child_ent = Entity()
found = child_ent.dereference(child_uuid)
if found:
if depth > 1:
child = self.get_containment_children(child_ent,
depth - 1,
False)
else:
child = self.make_containment_item(child_ent)
tree['children'].append(child)
if first_time:
output = []
output.append(tree)
else:
output = tree
elif entity_obj.item_type == 'subjects':
tree = self.make_containment_item(entity_obj)
tree['children'] = []
path_dict = cont.get_children_by_parent_uuid(entity_obj.uuid,
False)
for path_key, child_list in path_dict.items():
for child_uuid in child_list:
child_ent = Entity()
found = child_ent.dereference(child_uuid)
if found:
if depth > 1:
child = self.get_containment_children(child_ent,
depth - 1,
False)
else:
child = self.make_containment_item(child_ent)
tree['children'].append(child)
if first_time:
output = []
output.append(tree)
else:
output = tree
else:
output = []
return output
示例5: html_view
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def html_view(request, identifier):
rp = RootPath()
base_url = rp.get_baseurl()
uri = 'http://opencontext.org/vocabularies/' + str(identifier)
lequiv = LinkEquivalence()
id_list = lequiv.get_identifier_list_variants(uri)
lequiv = LinkEquivalence()
id_s_list = lequiv.get_identifier_list_variants(uri + '/')
for id_s in id_s_list:
if id_s not in id_list:
# add the slashed version to the list
id_list.append(id_s)
entity = False
for test_id in id_list:
ent = Entity()
found = ent.dereference(test_id)
if found is False:
found = ent.dereference(test_id, test_id)
if found:
entity = ent
break
if entity is not False:
t_vocab = TemplateVocab()
t_vocab.create_template_for_entity(entity)
t_vocab.make_json_for_html()
req_neg = RequestNegotiation('text/html')
req_neg.supported_types = ['application/ld+json',
'application/json']
if 'HTTP_ACCEPT' in request.META:
req_neg.check_request_support(request.META['HTTP_ACCEPT'])
if req_neg.supported:
if 'json' in req_neg.use_response_type:
# content negotiation requested JSON or JSON-LD
json_obj = t_vocab.make_json_obj()
return HttpResponse(json.dumps(json_obj,
ensure_ascii=False, indent=4),
content_type=req_neg.use_response_type + "; charset=utf8")
else:
template = loader.get_template('vocabularies/view.html')
context = {
'item': t_vocab,
'base_url': base_url,
'page_title': 'Open Context: Vocabularies + Ontologies',
'act_nav': 'vocabularies',
'nav_items': settings.NAV_ITEMS
}
return HttpResponse(template.render(context, request))
else:
# client wanted a mimetype we don't support
return HttpResponse(req_neg.error_message,
content_type="text/plain; charset=utf8",
status=415)
else:
raise Http404
示例6: make_object_dict_item
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def make_object_dict_item(self, identifier):
""" makes a dict item for the object of a predicate """
item = LastUpdatedOrderedDict()
item['id'] = identifier
item['label'] = False
ent = Entity()
found = ent.dereference(identifier)
if found is False:
found = ent.dereference(identifier, identifier)
if found:
item['label'] = ent.label
item['slug'] = ent.slug
return item
示例7: _get_cache_entity_db
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def _get_cache_entity_db(self, identifier):
"""Get an entity object from the database, if successful, cache it."""
found = False
entity = Entity()
entity.get_context = True
entity.get_thumbnail = True
found = entity.dereference(identifier)
if not found:
# case of linked data slugs
found = entity.dereference(identifier, identifier)
if not found:
return False
else:
# cache the entity now
return self.cache_entity(entity)
示例8: get_identifier_list_variants
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def get_identifier_list_variants(self, id_list):
""" makes different variants of identifiers
for a list of identifiers
"""
output_list = []
if not isinstance(id_list, list):
id_list = [str(id_list)]
for identifier in id_list:
output_list.append(identifier)
if(identifier[:7] == 'http://' or identifier[:8] == 'https://'):
oc_uuid = URImanagement.get_uuid_from_oc_uri(identifier)
if oc_uuid is not False:
output_list.append(oc_uuid)
else:
prefix_id = URImanagement.prefix_common_uri(identifier)
output_list.append(prefix_id)
elif ':' in identifier:
full_uri = URImanagement.convert_prefix_to_full_uri(identifier)
output_list.append(full_uri)
else:
# probably an open context uuid or a slug
ent = Entity()
found = ent.dereference(identifier)
if found:
full_uri = ent.uri
output_list.append(full_uri)
prefix_uri = URImanagement.prefix_common_uri(full_uri)
if prefix_uri != full_uri:
output_list.append(prefix_uri)
return output_list
示例9: create_template_for_entity
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def create_template_for_entity(self, entity):
""" creates a template for diplaying a
concept or vocabulary entity, either in
HTML or in JSON
"""
self.entity = entity
self.uri = entity.uri
self.vocab_uri = entity.vocab_uri
self.project_uuid = entity.project_uuid
# add the version control uri
for vocab_key, version_uri in self.VERSION_CONTROL_LINKS.items():
if vocab_key == self.vocab_uri:
self.version_control_uri = version_uri
break
self.get_comments() # always get comments for the entity
if self.uri == self.vocab_uri:
# we have a vocabulary so do vocab methods
self.vocab_entity = entity
self.get_root_entities()
else:
# we have a concept in a vocabulary, so do
# concept methods
ent_voc = Entity()
vocab_found = ent_voc.dereference(self.vocab_uri)
if vocab_found:
# found the parent vocab entity
self.vocab_entity = ent_voc
self.get_entity_parents()
self.get_entity_children()
示例10: id_summary
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def id_summary(request, identifier):
""" Returns JSON data for entities
limited by certain criteria
"""
lequiv = LinkEquivalence()
id_list = lequiv.get_identifier_list_variants(identifier)
entity_obj = False
for test_id in id_list:
ent = Entity()
ent.get_stable_ids = True
found = ent.dereference(test_id)
if found:
entity_obj = LastUpdatedOrderedDict()
entity_obj['id'] = ent.uri
entity_obj['label'] = ent.label
entity_obj['uuid'] = ent.uuid
entity_obj['slug'] = ent.slug
entity_obj['item_type'] = ent.item_type
entity_obj['class_uri'] = ent.class_uri
entity_obj['data_type'] = ent.data_type
entity_obj['vocab_uri'] = ent.vocab_uri
entity_obj['project_uuid'] = ent.project_uuid
entity_obj['stable_id_uris'] = ent.stable_id_uris
break
if entity_obj is not False:
json_output = json.dumps(entity_obj,
indent=4,
ensure_ascii=False)
return HttpResponse(json_output,
content_type='application/json; charset=utf8')
else:
raise Http404
示例11: make_trinomial_from_site_labels
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def make_trinomial_from_site_labels(self,
project_uuid,
state_prefix=''):
""" makes trinomial identifiers from a site label """
ent = Entity()
found = ent.dereference(project_uuid)
if found:
proj_label = ent.label
sites = Manifest.objects\
.filter(project_uuid=project_uuid,
class_uri='oc-gen:cat-site')
for site in sites:
trinomial = str(state_prefix) + site.label
if '*' in trinomial:
# for North Carolina, only the part before the '*' is a trinomial
tr_ex = trinomial.split('*')
trinomial = tr_ex[0]
print('working on (' + site.uuid + '): ' + trinomial)
parts = self.parse_trinomial(trinomial)
if 'Tennessee' in proj_label:
trinomial = parts['state'] + parts['county'] + str(parts['site'])
dt = Trinomial()
dt.uri = URImanagement.make_oc_uri(site.uuid, site.item_type)
dt.uuid = site.uuid
dt.label = site.label
dt.project_label = proj_label
dt.trinomial = trinomial
dt.state = parts['state']
dt.county = parts['county']
dt.site = parts['site']
try:
dt.save()
print('Trinomial: ' + trinomial + ', from: ' + site.label)
except:
print('Trinomial: ' + trinomial + ' not valid as a trinomial')
示例12: get_jsonldish_parents
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def get_jsonldish_parents(self, uuid, add_original=True):
"""
Gets parent projects for a project.
Returns a list of dictionary objects similar to JSON-LD expectations
This is useful for faceted search
If add_original is true, add the original UUID for the entity
that's the childmost item, at the bottom of the hierarchy
"""
output = False
raw_parents = self.get_parents(uuid)
if(add_original):
# add the original identifer to the list of parents, at lowest rank
raw_parents.insert(0, uuid)
if len(raw_parents) > 0:
# reverse the order of the list, to make top most concept
# first
output = []
parents = raw_parents[::-1]
for par_id in parents:
ent = Entity()
found = ent.dereference(par_id)
if(found):
p_item = LastUpdatedOrderedDict()
p_item['id'] = ent.uri
p_item['slug'] = ent.slug
p_item['label'] = ent.label
if(ent.data_type is not False):
p_item['type'] = ent.data_type
else:
p_item['type'] = '@id'
output.append(p_item)
return output
示例13: make_dict_from_field_obj
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def make_dict_from_field_obj(self, field_obj):
""" returns an ordered dict for a field_obj """
field_dict = LastUpdatedOrderedDict()
field_dict['field_num'] = field_obj.field_num
field_dict['label'] = field_obj.label
field_dict['ref_name'] = field_obj.ref_name
field_dict['field_type'] = field_obj.field_type
field_dict['field_data_type'] = field_obj.field_data_type
field_dict['field_value_cat'] = field_obj.field_value_cat
field_dict['obs_num'] = field_obj.obs_num
field_dict['value_prefix'] = field_obj.value_prefix
field_dict['unique_count'] = field_obj.unique_count
field_dict['f_uuid'] = field_obj.f_uuid
if self.get_examples:
field_dict['examples'] = self.get_example_entities(field_obj.field_num,
field_obj.value_prefix)
field_dict['ex_csv'] = ', '.join(field_dict['examples'])
if len(field_obj.field_value_cat) > 0:
ent = Entity()
ent.get_icon = True
found = ent.dereference(field_obj.field_value_cat)
if found:
field_dict['field_value_cat_label'] = ent.label
field_dict['field_value_cat_icon'] = ent.icon
return field_dict
示例14: get_subject_type_fields
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def get_subject_type_fields(self, field_num_list=False):
""" Gets a list of subject-type field objects,
limited by a list of field_num if not false
"""
self.get_examples = True
if field_num_list is not False:
imp_fields = ImportField.objects\
.filter(source_id=self.source_id,
field_type__in=self.DEFAULT_SUBJECT_TYPE_FIELDS,
field_num__in=field_num_list)
else:
imp_fields = ImportField.objects\
.filter(source_id=self.source_id,
field_type__in=self.DEFAULT_SUBJECT_TYPE_FIELDS)
for field_obj in imp_fields:
if field_obj.field_type == 'media':
self.has_media_field = True
if field_obj.field_type == 'documents':
self.has_doc_field = True
if field_obj.field_type == 'complex-description':
self.has_complex_des_field = True
field_obj.examples = self.get_example_entities(field_obj.field_num,
field_obj.value_prefix)
field_obj.ex_csv = ', '.join(field_obj.examples)
if len(field_obj.field_value_cat) > 0:
ent = Entity()
ent.get_icon = True
found = ent.dereference(field_obj.field_value_cat)
if found:
field_obj.field_value_cat_label = ent.label
field_obj.field_value_cat_icon = ent.icon
else:
field_obj.field_value_cat_icon = False
field_obj.field_value_cat_label = ''
self.fields.append(field_obj)
示例15: contain_children
# 需要导入模块: from opencontext_py.apps.entities.entity.models import Entity [as 别名]
# 或者: from opencontext_py.apps.entities.entity.models.Entity import dereference [as 别名]
def contain_children(request, identifier):
""" Returns JSON data with
spatial containment for a given
uuid identiffied entity
"""
ent = Entity()
found = ent.dereference(identifier)
if found:
depth = 1
recursive = False
if 'depth' in request.GET:
try:
depth = int(float(request.GET['depth']))
except:
depth = 1
et = EntityTemplate()
children = et.get_containment_children(ent,
depth)
json_output = json.dumps(children,
indent=4,
ensure_ascii=False)
return HttpResponse(json_output,
content_type='application/json; charset=utf8')
else:
raise Http404