本文整理汇总了Python中opencontext_py.apps.entities.uri.models.URImanagement类的典型用法代码示例。如果您正苦于以下问题:Python URImanagement类的具体用法?Python URImanagement怎么用?Python URImanagement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URImanagement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_project_predicates_and_annotations_to_graph
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
示例2: mass_revise_category_uris
def mass_revise_category_uris(self):
""" Revises category uris in a mass edit
"""
for revision in self.REVISION_LIST:
search_old_db = revision['old']
replace_db = revision['new']
old_uri = URImanagement.convert_prefix_to_full_uri(search_old_db)
new_uri = URImanagement.convert_prefix_to_full_uri(replace_db)
Manifest.objects\
.filter(class_uri=search_old_db)\
.update(class_uri=replace_db)
LinkAnnotation.objects\
.filter(subject=search_old_db)\
.update(subject=replace_db)
LinkAnnotation.objects\
.filter(subject=old_uri)\
.update(subject=new_uri)
LinkAnnotation.objects\
.filter(object_uri=search_old_db)\
.update(object_uri=replace_db)
LinkAnnotation.objects\
.filter(object_uri=old_uri)\
.update(object_uri=new_uri)
LinkEntity.objects\
.filter(uri=old_uri)\
.update(uri=new_uri)
示例3: update_ontology_doc
def update_ontology_doc(self, filename):
""" Changes categories in the ontology document
"""
filepath = self.root_export_dir + '/' + filename
newfilepath = self.root_export_dir + '/rev-' + filename
if os.path.isfile(filepath):
print('Found: ' + filepath)
with open(filepath, 'r') as myfile:
data = myfile.read()
for revision in self.REVISION_LIST:
search_old_db = revision['old']
search_old_file = search_old_db.replace(self.PREFIXING['db-prefix'],
self.PREFIXING['file-prefix'])
replace_db = revision['new']
replace_file = replace_db.replace(self.PREFIXING['db-prefix'],
self.PREFIXING['file-prefix'])
data = data.replace(search_old_file, replace_file)
old_uri = URImanagement.convert_prefix_to_full_uri(search_old_db)
new_uri = URImanagement.convert_prefix_to_full_uri(replace_db)
data = data.replace(old_uri, new_uri)
file = codecs.open(newfilepath, 'w', 'utf-8')
file.write(data)
file.close()
else:
print('Ouch! Cannot find: '+ filepath)
示例4: make_list_cite_projects
def make_list_cite_projects(self, json_ld):
""" makes a string for citation of projects """
projects_list = []
cite_projects_list = []
if 'dc-terms:source' in json_ld:
for item in json_ld['dc-terms:source']:
cite_projects_list.append(item['label'])
proj_item = {}
if 'rdfs:isDefinedBy' in item:
proj_item['uuid'] = URImanagement.get_uuid_from_oc_uri(item['rdfs:isDefinedBy'],
False)
proj_item['uri'] = item['rdfs:isDefinedBy']
else:
proj_item['uuid'] = URImanagement.get_uuid_from_oc_uri(item['id'],
False)
proj_item['uri'] = item['id']
proj_item['label'] = item['label']
if 'count' in item:
proj_item['count'] = item['count']
else:
proj_item['count'] = False
projects_list.append(proj_item)
self.cite_projects = ', '.join(cite_projects_list)
self.projects_list = projects_list
return self.cite_projects
示例5: save_icons
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
示例6: get_identifier_list_variants
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
示例7: add_project_types_with_annotations_to_graph
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
示例8: get_identifier_list_variants
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: get_entity_parents
def get_entity_parents(self, identifier):
"""
Gets parent concepts for a given URI or UUID identified entity
"""
self.loop_count += 1
lequiv = LinkEquivalence()
identifiers = lequiv.get_identifier_list_variants(identifier)
p_for_superobjs = LinkAnnotation.PREDS_SBJ_IS_SUB_OF_OBJ
preds_for_superobjs = lequiv.get_identifier_list_variants(p_for_superobjs)
p_for_subobjs = LinkAnnotation.PREDS_SBJ_IS_SUPER_OF_OBJ
preds_for_subobjs = lequiv.get_identifier_list_variants(p_for_subobjs)
try:
# look for superior items in the objects of the assertion
# sorting by sort so we can privelage a certain hierarchy path
superobjs_anno = LinkAnnotation.objects.filter(subject__in=identifiers,
predicate_uri__in=preds_for_superobjs)\
.exclude(object_uri__in=identifiers)\
.order_by('sort', 'object_uri')[:1]
if(len(superobjs_anno) < 1):
superobjs_anno = False
except LinkAnnotation.DoesNotExist:
superobjs_anno = False
if(superobjs_anno is not False):
parent_id = superobjs_anno[0].object_uri
if(parent_id.count('/') > 1):
oc_uuid = URImanagement.get_uuid_from_oc_uri(parent_id)
if(oc_uuid is not False):
parent_id = oc_uuid
if(parent_id not in self.parent_entities):
self.parent_entities.append(parent_id)
if self.loop_count <= 50:
self.parent_entities = self.get_entity_parents(parent_id)
try:
"""
Now look for superior entities in the subject, not the object
sorting by sort so we can privelage a certain hierarchy path
"""
supersubj_anno = LinkAnnotation.objects.filter(object_uri__in=identifiers,
predicate_uri__in=preds_for_subobjs)\
.exclude(subject__in=identifiers)\
.order_by('sort', 'subject')[:1]
if(len(supersubj_anno) < 1):
supersubj_anno = False
except LinkAnnotation.DoesNotExist:
supersubj_anno = False
if supersubj_anno is not False:
parent_id = supersubj_anno[0].subject
if(parent_id.count('/') > 1):
oc_uuid = URImanagement.get_uuid_from_oc_uri(parent_id)
if(oc_uuid is not False):
parent_id = oc_uuid
if(parent_id not in self.parent_entities):
self.parent_entities.append(parent_id)
if self.loop_count <= 50:
self.parent_entities = self.get_entity_parents(parent_id)
return self.parent_entities
示例10: make_alt_uri
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
示例11: prep_delete_uuid
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
示例12: prep_merge_uuid
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
示例13: add_json_ld_link_annotations
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
示例14: make_trinomial_from_site_labels
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
parts = self.parse_trinomial(trinomial)
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']
dt.save()
print('Trinomial: ' + trinomial + ', from: ' + site.label)
示例15: get_item_media_files
def get_item_media_files(self, man_obj):
""" gets media file uris for archiving """
files_dict = LastUpdatedOrderedDict()
if isinstance(man_obj, Manifest):
med_files = Mediafile.objects\
.filter(uuid=man_obj.uuid,
file_type__in=self.ARCHIVE_FILE_TYPES)\
.order_by('-filesize')
# print('found files: ' + str(len(med_files)))
for act_type in self.ARCHIVE_FILE_TYPES:
for med_file in med_files:
if med_file.file_type == act_type:
extension = ''
frag = None
file_uri = med_file.file_uri
if '#' in file_uri:
file_ex = file_uri.split('#')
file_uri = file_ex[0]
frag = file_ex[-1]
if file_uri not in files_dict:
act_dict = LastUpdatedOrderedDict()
act_dict['filename'] = self.make_archival_file_name(med_file.file_type,
man_obj.slug,
file_uri)
act_dict['dc-terms:isPartOf'] = URImanagement.make_oc_uri(man_obj.uuid,
man_obj.item_type)
act_dict['type'] = []
files_dict[file_uri] = act_dict
files_dict[file_uri]['type'].append(med_file.file_type)
return files_dict