本文整理汇总了Python中opencontext_py.apps.entities.uri.models.URImanagement.prefix_common_uri方法的典型用法代码示例。如果您正苦于以下问题:Python URImanagement.prefix_common_uri方法的具体用法?Python URImanagement.prefix_common_uri怎么用?Python URImanagement.prefix_common_uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opencontext_py.apps.entities.uri.models.URImanagement
的用法示例。
在下文中一共展示了URImanagement.prefix_common_uri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_identifier_list_variants
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [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.startswith('http://') or identifier.startswith('https://')):
oc_uuid = URImanagement.get_uuid_from_oc_uri(identifier)
if oc_uuid:
output_list.append(oc_uuid)
prefix_id = URImanagement.prefix_common_uri(identifier)
if prefix_id:
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
m_cache = MemoryCache()
ent = m_cache.get_entity(identifier)
if ent:
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
示例2: get_identifier_list_variants
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [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
示例3: save_icons
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def save_icons(self, predicate_uri='oc-gen:hasIcon'):
""" Saves icons in the general Open Context namespace """
data = False
if(self.graph is not False and self.vocabulary_uri is not False):
data = []
if(self.replace_old):
# delete old relations from this vocabulary using this predicate
LinkAnnotation.objects.filter(source_id=self.vocabulary_uri,
predicate_uri=predicate_uri).delete()
if(predicate_uri == 'oc-gen:hasIcon'):
# for subClassOf predicates
full_pred_uri = URImanagement.convert_prefix_to_full_uri(predicate_uri)
icon_pred = URIRef(full_pred_uri)
for s, p, o in self.graph.triples((None,
icon_pred,
None)):
subject_uri = s.__str__() # get the URI of the subject as a string
object_uri = o.__str__() # get the URI of the object as a string
act_t = {'s': subject_uri,
'o': object_uri}
if(subject_uri != object_uri):
data.append(act_t)
if(len(data) > 0):
for act_t in data:
newr = LinkAnnotation()
# make the subject a prefixed URI if common
newr.subject = URImanagement.prefix_common_uri(act_t['s'])
newr.subject_type = 'uri'
newr.project_uuid = '0'
newr.source_id = self.vocabulary_uri
newr.predicate_uri = predicate_uri
newr.object_uri = act_t['o']
newr.save()
return data
示例4: add_project_predicates_and_annotations_to_graph
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def add_project_predicates_and_annotations_to_graph(self, graph):
""" gets the project predicates and their
annotations with database calls
"""
pred_sql_dict_list = self.get_working_project_predicates()
la_preds = self.get_link_annotations_for_preds(pred_sql_dict_list)
if isinstance(pred_sql_dict_list, list):
for sql_dict in pred_sql_dict_list:
act_pred = LastUpdatedOrderedDict()
act_pred['@id'] = 'oc-pred:' + sql_dict['slug']
act_pred['owl:sameAs'] = URImanagement.make_oc_uri(sql_dict['predicate_uuid'],
'predicates')
act_pred['label'] = sql_dict['label']
act_pred['uuid'] = sql_dict['predicate_uuid']
act_pred['slug'] = sql_dict['slug']
if isinstance(sql_dict['class_uri'], str):
if len(sql_dict['class_uri']) > 0:
act_pred['oc-gen:predType'] = sql_dict['class_uri']
pred_found = False
for la_pred in la_preds:
if la_pred.subject == sql_dict['predicate_uuid']:
pred_found = True
# prefix common URIs for the predicate of the link annotation
la_pred_uri = URImanagement.prefix_common_uri(la_pred.predicate_uri)
if la_pred_uri not in act_pred:
act_pred[la_pred_uri] = []
la_object_item = self.make_object_dict_item(la_pred.object_uri)
act_pred[la_pred_uri].append(la_object_item)
else:
if pred_found:
# because this list is sorted by la_pred.subject, we're done
# finding any more annotations on act_pred item
break
graph.append(act_pred)
return graph
示例5: add_project_types_with_annotations_to_graph
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def add_project_types_with_annotations_to_graph(self, graph):
""" adds project types that have annotations """
type_sql_dict_list = self.get_working_project_types()
if isinstance(type_sql_dict_list, list):
# consolidate things so a given type is given once in the list
# of a graph. To do so, we first put everything in a all_types
# dict
all_types = LastUpdatedOrderedDict()
for sql_dict in type_sql_dict_list:
type_uri = URImanagement.make_oc_uri(sql_dict['type_uuid'],
'types')
if type_uri not in all_types:
act_type = LastUpdatedOrderedDict()
act_type['@id'] = type_uri
act_type['label'] = sql_dict['type_label']
act_type['owl:sameAs'] = URImanagement.make_oc_uri(sql_dict['type_slug'],
'types')
act_type['uuid'] = sql_dict['type_uuid']
act_type['slug'] = sql_dict['type_slug']
else:
act_type = all_types[type_uri]
la_pred_uri = URImanagement.prefix_common_uri(sql_dict['predicate_uri'])
if la_pred_uri not in act_type:
act_type[la_pred_uri] = []
la_object_item = self.make_object_dict_item(sql_dict['object_uri'])
act_type[la_pred_uri].append(la_object_item)
all_types[type_uri] = act_type
for type_uri, act_type in all_types.items():
graph.append(act_type)
return graph
示例6: augment_projects
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def augment_projects(self):
""" adds some additional informaiton about projects
to make them easier to display
"""
uuids = []
for proj_r in self.raw_records:
uuids.append(proj_r.uuid)
# now query the database for all the records with these uuids
proj_objs = Project.objects\
.filter(uuid__in=uuids)
# now make a dict object to easily get project info by a UUID key
proj_obj_dict = {}
for proj_obj in proj_objs:
proj_obj_dict[proj_obj.uuid] = proj_obj
# now query the database for all of the dc related predicates
le = LinkEquivalence()
subjects = le.get_identifier_list_variants(uuids)
predicates = le.get_identifier_list_variants(self.DC_META_PREDS)
dc_annos = LinkAnnotation.objects\
.filter(subject__in=subjects,
predicate_uri__in=predicates)
# now make a dict object to easily get annotations by UUID key
dc_anno_dict = {}
for dc_anno in dc_annos:
dc_pred = URImanagement.prefix_common_uri(dc_anno.predicate_uri)
dc_pred = dc_pred.replace('dc-terms:', '') # remove namespace prefix
if dc_anno.subject not in dc_anno_dict:
dc_anno_dict[dc_anno.subject] = {}
if dc_pred not in dc_anno_dict[dc_anno.subject]:
dc_anno_dict[dc_anno.subject][dc_pred] = []
if dc_anno.object_uri not in dc_anno_dict[dc_anno.subject][dc_pred]:
dc_anno_dict[dc_anno.subject][dc_pred].append(dc_anno.object_uri)
# now add information we got from queries and organized into dicts
# to the project response objects
for proj_r in self.raw_records:
if proj_r.uuid in proj_obj_dict:
# add projects objects from the database
proj_r.extra = proj_obj_dict[proj_r.uuid]
if proj_r.uuid in dc_anno_dict:
# add annotations from the database
proj_r.dc = {'meta': []}
for pred, object_uris in dc_anno_dict[proj_r.uuid].items():
proj_r.dc[pred] = []
for object_uri in object_uris:
ent = Entity()
found = ent.dereference(object_uri)
if found:
obj_obj = {'id': object_uri,
'label': ent.label}
if ent.item_type == 'uri':
obj_obj['href'] = ent.uri
else:
obj_obj['href'] = self.base_url \
+ '/' + ent.item_type \
+ '/' + ent.uuid
proj_r.dc[pred].append(obj_obj)
if pred != 'creator' and pred != 'temporal':
proj_r.dc['meta'].append(obj_obj)
self.records.append(proj_r) # now append the augmented record
示例7: make_alt_uri
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def make_alt_uri(self, uri):
""" makes an alternative URI, changing a prefixed to a full
uri or a full uri to a prefix
"""
output = uri
if(uri[:7] == 'http://' or uri[:8] == 'https://'):
output = URImanagement.prefix_common_uri(uri)
else:
output = URImanagement.convert_prefix_to_full_uri(uri)
return output
示例8: prep_delete_uuid
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def prep_delete_uuid(self, delete_uuid):
""" Prepares some information needed to delete a uuid
"""
ok_delete = False
delete_obj = self.get_manifest(delete_uuid)
if delete_obj is not False:
ok_delete = True
self.delete_manifest_obj = delete_obj
self.delete_uri = URImanagement.make_oc_uri(delete_uuid,
delete_obj.item_type)
self.delete_prefix_uri = URImanagement.prefix_common_uri(self.delete_uri)
return ok_delete
示例9: prep_merge_uuid
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def prep_merge_uuid(self, merge_into_uuid):
""" Prepares some information needed to delete a uuid
"""
ok_merge = False
merge_obj = self.get_manifest(merge_into_uuid)
if merge_obj is not False:
ok_merge = True
self.merge_manifest_obj = merge_obj
self.merge_uri = URImanagement.make_oc_uri(merge_into_uuid,
merge_obj.item_type)
self.merge_prefix_uri = URImanagement.prefix_common_uri(self.merge_uri)
return ok_merge
示例10: add_json_ld_link_annotations
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def add_json_ld_link_annotations(self, json_ld):
"""
adds linked data annotations (typically referencing URIs from
outside Open Context)
"""
if not self.link_annotations or not len(self.link_annotations):
# No link annotations, so skip out.
return json_ld
# We have link annotations.
parts_json_ld = PartsJsonLD()
parts_json_ld.proj_context_json_ld = self.proj_context_json_ld
parts_json_ld.manifest_obj_dict = self.manifest_obj_dict
for la in self.link_annotations:
tcheck = URImanagement.get_uuid_from_oc_uri(la.object_uri, True)
if not tcheck:
# this item is NOT from open context
item_type = False
else:
# an Open Context item
item_type = tcheck['item_type']
if item_type == 'persons':
# add a stable ID to person items, but only if they are ORCID IDs
parts_json_ld.stable_id_predicate = ItemKeys.PREDICATES_FOAF_PRIMARYTOPICOF
parts_json_ld.stable_id_prefix_limit = StableIdentifer.ID_TYPE_PREFIXES['orcid']
# this shortens URIs in item-context declared namespaces
# to make a compact URI (prefixed), as the act_pred
act_pred = URImanagement.prefix_common_uri(la.predicate_uri)
if act_pred not in self.dc_author_preds \
and act_pred not in self.dc_inherit_preds \
and act_pred not in self.dc_metadata_preds:
# the act_prec is not a dublin core predicate, so we're OK to add it
# now, not later.
json_ld = parts_json_ld.addto_predicate_list(
json_ld,
act_pred,
la.object_uri,
item_type
)
else:
# we've got dublin core assertions, cache these in the dict_object
# dc_assertions so they get added LAST, after other asserttions
self.dc_assertions = parts_json_ld.addto_predicate_list(
self.dc_assertions,
act_pred,
la.object_uri,
item_type
)
return json_ld
示例11: save_hierarchy
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def save_hierarchy(self, predicate_uri='rdfs:subClassOf'):
""" Saves hierarchic relations from a vocabulary,
defaulting to subClassOf predicates """
data = False
if(self.graph is not False and self.vocabulary_uri is not False):
data = []
if(self.replace_old):
# delete old relations from this vocabulary using this predicate
LinkAnnotation.objects.filter(source_id=self.vocabulary_uri,
predicate_uri=predicate_uri).delete()
if(predicate_uri == 'rdfs:subClassOf'):
# for subClassOf predicates
for s, p, o in self.graph.triples((None,
RDFS.subClassOf,
None)):
subject_uri = s.__str__() # get the URI of the subject as a string
object_uri = o.__str__() # get the URI of the object as a string
act_t = {'s': subject_uri,
'o': object_uri}
if(subject_uri != object_uri):
data.append(act_t)
elif(predicate_uri == 'rdfs:subPropertyOf'):
# for subPropertyOf predicates
for s, p, o in self.graph.triples((None,
RDFS.subPropertyOf,
None)):
subject_uri = s.__str__() # get the URI of the subject as a string
object_uri = o.__str__() # get the URI of the object as a string
act_t = {'s': subject_uri,
'o': object_uri}
if(subject_uri != object_uri):
data.append(act_t)
if(len(data) > 0):
for act_t in data:
newr = LinkAnnotation()
# make the subject a prefixed URI if common
newr.subject = URImanagement.prefix_common_uri(act_t['s'])
newr.subject_type = 'uri'
newr.project_uuid = '0'
newr.source_id = self.vocabulary_uri
newr.predicate_uri = predicate_uri
newr.object_uri = act_t['o']
newr.save()
return data
示例12: validate_class_uri
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def validate_class_uri(self, class_uri):
""" validates a class_uri as actually
identifiying a known class. Useful for making sure data
entry is OK for the manifest table
"""
output = False
if len(class_uri) > 0:
le = LinkEquivalence()
class_list = le.get_identifier_list_variants(class_uri)
link_entities = LinkEntity.objects\
.filter(uri__in=class_list,
vocab_uri__in=self.VALID_OC_CLASS_VOCABS)[:1]
if len(link_entities) > 0:
# OK! We found it. now make it prefixed for use in the manifest table
full_class_uri = link_entities[0].uri
output = URImanagement.prefix_common_uri(full_class_uri)
else:
if self.allow_blank:
# we are allowing blank values for no class_uri to be OK
output = ''
return output
示例13: save_entity_comments
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def save_entity_comments(self):
""" saves comments about an entity """
if self.graph is not False and self.vocabulary_uri is not False:
lequiv = LinkEquivalence()
# get all the varients of RDFS:comments
comment_uris = lequiv.get_identifier_list_variants('rdfs:comment')
# now get all the entities from this vocabulary (that may be the subject of a comment)
raw_subject_uris = LinkEntity.objects.filter(vocab_uri=self.vocabulary_uri)
lequiv = LinkEquivalence()
subject_uris = lequiv.get_identifier_list_variants(raw_subject_uris)
if self.replace_old:
# delete the old comments
LinkAnnotation.objects\
.filter(subject__in=subject_uris,
predicate_uri__in=comment_uris)\
.delete()
for s, p, o in self.graph.triples((None,
RDFS.comment,
None)):
subject_uri = s.__str__() # get the URI of the subject as a string
comment = o.__str__() # get the comment from the object as a string
# update the entity's comment
link_ent = False
try:
link_ent = LinkEntity.objects.get(uri=subject_uri)
except LinkEntity.DoesNotExist:
link_ent = False
if link_ent is not False:
lang = Languages()
newr = LinkAnnotation()
# make the subject a prefixed URI if common
newr.subject = URImanagement.prefix_common_uri(subject_uri)
newr.subject_type = 'uri'
newr.project_uuid = '0'
newr.source_id = self.vocabulary_uri
newr.predicate_uri = 'rdfs:comment'
newr.obj_extra = {}
newr.obj_extra[lang.DEFAULT_LANGUAGE] = comment
newr.save()
示例14: dereference
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def dereference(self, identifier, link_entity_slug=False):
""" Dereferences an entity identified by an identifier, checks if a URI,
if, not a URI, then looks in the OC manifest for the item
"""
output = False
try_manifest = True
identifier = URImanagement.convert_prefix_to_full_uri(identifier)
if(link_entity_slug or (len(identifier) > 8)):
if(link_entity_slug or (identifier[:7] == 'http://' or identifier[:8] == 'https://')):
try:
try_manifest = False
ld_entity = LinkEntity.objects.get(Q(uri=identifier) | Q(slug=identifier))
except LinkEntity.DoesNotExist:
ld_entity = False
if(ld_entity is not False):
output = True
self.uri = ld_entity.uri
self.slug = ld_entity.slug
self.label = ld_entity.label
self.item_type = 'uri'
self.alt_label = ld_entity.alt_label
self.entity_type = ld_entity.ent_type
self.vocab_uri = ld_entity.vocab_uri
self.ld_object_ok = True
try:
vocab_entity = LinkEntity.objects.get(uri=self.vocab_uri)
except LinkEntity.DoesNotExist:
vocab_entity = False
if(vocab_entity is not False):
self.vocabulary = vocab_entity.label
if self.get_icon:
prefix_uri = URImanagement.prefix_common_uri(ld_entity.uri)
icon_anno = LinkAnnotation.objects\
.filter(Q(subject=ld_entity.uri)
| Q(subject=identifier)
| Q(subject=prefix_uri),
predicate_uri='oc-gen:hasIcon')[:1]
if len(icon_anno) > 0:
self.icon = icon_anno[0].object_uri
else:
try_manifest = True
# couldn't find the item in the linked entities table
identifier = URImanagement.get_uuid_from_oc_uri(identifier)
if(try_manifest):
try:
manifest_item = Manifest.objects.get(Q(uuid=identifier) | Q(slug=identifier))
except Manifest.DoesNotExist:
manifest_item = False
if(manifest_item is not False):
output = True
self.uri = URImanagement.make_oc_uri(manifest_item.uuid, manifest_item.item_type)
self.uuid = manifest_item.uuid
self.slug = manifest_item.slug
self.label = manifest_item.label
self.item_type = manifest_item.item_type
self.class_uri = manifest_item.class_uri
self.project_uuid = manifest_item.project_uuid
if(manifest_item.item_type == 'media' and self.get_thumbnail):
# a media item. get information about its thumbnail.
try:
thumb_obj = Mediafile.objects.get(uuid=manifest_item.uuid, file_type='oc-gen:thumbnail')
except Mediafile.DoesNotExist:
thumb_obj = False
if thumb_obj is not False:
self.thumbnail_media = thumb_obj
self.thumbnail_uri = thumb_obj.file_uri
elif(manifest_item.item_type == 'types'):
tl = TypeLookup()
tl.get_octype_without_manifest(identifier)
self.content = tl.content
elif(manifest_item.item_type == 'predicates'):
try:
oc_pred = Predicate.objects.get(uuid=manifest_item.uuid)
except Predicate.DoesNotExist:
oc_pred = False
if(oc_pred is not False):
self.data_type = oc_pred.data_type
elif(manifest_item.item_type == 'subjects' and self.get_context):
try:
subj = Subject.objects.get(uuid=manifest_item.uuid)
except Subject.DoesNotExist:
subj = False
if subj is not False:
self.context = subj.context
return output
示例15: dereference
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import prefix_common_uri [as 别名]
def dereference(self, identifier, link_entity_slug=False):
""" Dereferences an entity identified by an identifier, checks if a URI,
if, not a URI, then looks in the OC manifest for the item
"""
output = False
if isinstance(identifier, str):
# only try to dereference if the identifier is a string.
try_manifest = True
identifier = URImanagement.convert_prefix_to_full_uri(identifier)
if (settings.CANONICAL_HOST + '/tables/') in identifier:
identifier = identifier.replace((settings.CANONICAL_HOST + '/tables/'), '')
if link_entity_slug or (len(identifier) > 8):
if link_entity_slug or (identifier[:7] == 'http://' or identifier[:8] == 'https://'):
ent_equivs = EntityEquivalents()
uris = ent_equivs.make_uri_variants(identifier)
ld_entities = LinkEntity.objects.filter(Q(uri__in=uris) | Q(slug=identifier))[:1]
if len(ld_entities) > 0:
ld_entity = ld_entities[0]
else:
ld_entity = False
if ld_entity is not False:
output = True
self.uri = ld_entity.uri
self.slug = ld_entity.slug
self.label = ld_entity.label
self.item_type = 'uri'
self.alt_label = ld_entity.alt_label
self.entity_type = ld_entity.ent_type
self.vocab_uri = ld_entity.vocab_uri
self.ld_object_ok = True
try:
if 'https://' in self.vocab_uri:
alt_vocab_uri = self.vocab_uri.replace('https://', 'http://')
else:
alt_vocab_uri = self.vocab_uri.replace('http://', 'https://')
vocab_entity = LinkEntity.objects.get(Q(uri=self.vocab_uri) | Q(uri=alt_vocab_uri))
except LinkEntity.DoesNotExist:
vocab_entity = False
if vocab_entity is not False:
self.vocabulary = vocab_entity.label
if self.get_icon:
prefix_uri = URImanagement.prefix_common_uri(ld_entity.uri)
icon_anno = LinkAnnotation.objects\
.filter(Q(subject=ld_entity.uri)
| Q(subject=identifier)
| Q(subject=prefix_uri),
predicate_uri='oc-gen:hasIcon')[:1]
if len(icon_anno) > 0:
self.icon = icon_anno[0].object_uri
else:
try_manifest = True
# couldn't find the item in the linked entities table
identifier = URImanagement.get_uuid_from_oc_uri(identifier)
if try_manifest:
try:
manifest_item = Manifest.objects.get(Q(uuid=identifier) | Q(slug=identifier))
except Manifest.DoesNotExist:
manifest_item = False
if manifest_item is not False:
output = True
self.uri = URImanagement.make_oc_uri(manifest_item.uuid, manifest_item.item_type)
self.uuid = manifest_item.uuid
self.slug = manifest_item.slug
self.label = manifest_item.label
self.item_type = manifest_item.item_type
self.class_uri = manifest_item.class_uri
self.project_uuid = manifest_item.project_uuid
if manifest_item.item_type == 'media' and self.get_thumbnail:
# a media item. get information about its thumbnail.
try:
thumb_obj = Mediafile.objects.get(uuid=manifest_item.uuid, file_type='oc-gen:thumbnail')
except Mediafile.DoesNotExist:
thumb_obj = False
if thumb_obj is not False:
self.thumbnail_media = thumb_obj
self.thumbnail_uri = thumb_obj.file_uri
elif manifest_item.item_type in ['persons', 'projects', 'tables'] \
or self.get_stable_ids:
# get stable identifiers for persons or projects by default
stable_ids = StableIdentifer.objects.filter(uuid=manifest_item.uuid)
if len(stable_ids) > 0:
self.stable_id_uris = []
doi_uris = []
orcid_uris = []
other_uris = []
for stable_id in stable_ids:
if stable_id.stable_type in StableIdentifer.ID_TYPE_PREFIXES:
prefix = StableIdentifer.ID_TYPE_PREFIXES[stable_id.stable_type]
else:
prefix = ''
stable_uri = prefix + stable_id.stable_id
if stable_id.stable_type == 'orcid':
orcid_uris.append(stable_uri)
elif stable_id.stable_type == 'doi':
doi_uris.append(stable_uri)
else:
other_uris.append(stable_uri)
# now list URIs in order of importance, with ORCIDs and DOIs
# first, followed by other stable URI types (Arks or something else)
self.stable_id_uris = orcid_uris + doi_uris + other_uris
#.........这里部分代码省略.........