本文整理汇总了Python中opencontext_py.apps.entities.uri.models.URImanagement.make_oc_uri方法的典型用法代码示例。如果您正苦于以下问题:Python URImanagement.make_oc_uri方法的具体用法?Python URImanagement.make_oc_uri怎么用?Python URImanagement.make_oc_uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opencontext_py.apps.entities.uri.models.URImanagement
的用法示例。
在下文中一共展示了URImanagement.make_oc_uri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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 make_oc_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
示例2: make_trinomial_from_site_labels
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [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
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)
示例3: save_context
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [as 别名]
def save_context(self, row_num, man, parent_list):
""" Save context information, will also add new context fields
as needed
"""
use_parents = False
context_uri = ''
if isinstance(parent_list, list):
if len(parent_list) > 0:
context_uri = URImanagement.make_oc_uri(parent_list[0], 'subjects')
use_parents = parent_list[::-1]
# save a record of the context URI
cell = ExpCell()
cell.table_id = self.table_id
cell.uuid = man.uuid
cell.project_uuid = man.project_uuid
cell.row_num = row_num
cell.field_num = 13
cell.record = context_uri
cell.save()
cell = None
if use_parents is not False:
pindex = 0
for parent_uuid in use_parents:
pindex += 1
context_label = self.deref_entity_label(parent_uuid)
field_num = self.get_add_context_field_number(pindex)
cell = ExpCell()
cell.table_id = self.table_id
cell.uuid = man.uuid
cell.project_uuid = man.project_uuid
cell.row_num = row_num
cell.field_num = field_num
cell.record = context_label
cell.save()
cell = None
示例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 make_oc_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: make_table_dc_creator_list
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [as 别名]
def make_table_dc_creator_list(self, proj_uuid_counts):
""" makes a list of dublin core creators
from a project uuid + counts list """
dc_creators = []
for proj_uuid_count in proj_uuid_counts:
project_uuid = proj_uuid_count['project_uuid']
proj_count = proj_uuid_count['num_uuids']
auth = Authorship()
auth.get_project_authors(project_uuid)
if len(auth.creators) < 1 and \
len(auth.contributors) > 0:
auth.creators = auth.contributors
if len(auth.creators) > 0:
for auth_uuid in auth.creators:
auth_man = False
try:
auth_man = Manifest.objects.get(uuid=auth_uuid)
except Manifest.DoesNotExist:
auth_man = False
if auth_man is not False:
i = len(dc_creators) + 1
item = LastUpdatedOrderedDict()
item['id'] = URImanagement.make_oc_uri(auth_uuid, 'persons')
item['count'] = proj_count
dc_creators.append(item)
return dc_creators
示例6: make_json_ld
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [as 别名]
def make_json_ld(self):
""" makes a JSON-LD object for the table metadata
Need oc-table namespace
need to include the cc-rel namespace
need to add this name space
http://www.w3.org/2003/01/geo/ as geo:lat, geo:lon
"""
json_ld = LastUpdatedOrderedDict()
if self.exp_tab is not False:
json_ld['id'] = URImanagement.make_oc_uri(self.public_table_id, 'tables')
json_ld['uuid'] = self.public_table_id
json_ld['label'] = self.exp_tab.label
json_ld['fields'] = self.exp_tab.field_count
json_ld['rows'] = self.exp_tab.row_count
json_ld['dc-terms:identifier'] = self.table_id
json_ld['dc-terms:issued'] = self.exp_tab.created.date().isoformat()
json_ld['dc-terms:modified'] = self.exp_tab.updated.date().isoformat()
json_ld['dc-terms:abstract'] = self.exp_tab.abstract
json_ld = self.get_link_annotations(json_ld)
stable_ids = self.get_stable_ids()
if len(stable_ids) > 0:
json_ld['owl:sameAs'] = stable_ids
json_ld['has-fields'] = self.get_field_list()
"""
for key, objects in self.exp_tab.meta_json.items():
json_ld[key] = objects
"""
return json_ld
示例7: add_general_json_ld
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [as 别名]
def add_general_json_ld(self):
""" adds general (manifest) information to the JSON-LD object """
self.json_ld['id'] = URImanagement.make_oc_uri(self.uuid, self.item_type)
self.json_ld['uuid'] = self.uuid
self.json_ld['slug'] = self.slug
self.json_ld['label'] = self.label
# add multilingual alternative labels
if isinstance(self.manifest.localized_json, dict):
if len(self.manifest.localized_json) > 0:
json_ld['skos:altLabel'] = self.manifest.localized_json
if self.manifest.item_type in PartsJsonLD.ITEM_TYPE_CLASS_LIST \
and len(self.manifest.class_uri) > 1:
self.json_ld['category'] = [
self.manifest.class_uri
]
if self.manifest.item_type == 'projects':
# now add the project specific data to the JSON-LD
self.add_project_json_ld()
elif self.manifest.item_type == 'documents':
# now add document specific information to the JSON-LD
self.add_document_json_ld()
elif self.manifest.item_type == 'predicates':
# now add the predicate specific data the JSON-LD
self.add_predicate_json_ld()
elif self.manifest.item_type == 'types':
self.add_type_json_ld()
示例8: make_trinomial_from_site_labels
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [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')
示例9: get_item_media_files
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [as 别名]
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
示例10: make_save_doi_by_uuid
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [as 别名]
def make_save_doi_by_uuid(self, uuid, metadata=None):
""" makes an saves an DOI identifier by a uuid """
ok = False
oc_uri = None
dois = StableIdentifer.objects.filter(uuid=uuid,
stable_type='doi')[:1]
if len(dois) < 1:
# the item doesn't yet have an ARK id, so make one!
oc_item = OCitem()
exists = oc_item.check_exists(uuid)
if oc_item.exists:
if metadata is None:
metadata = self.make_doi_metadata_by_uuid(uuid, oc_item)
if isinstance(metadata, dict):
if '_target' in metadata:
oc_uri = metadata['_target']
else:
oc_uri = URImanagement.make_oc_uri(oc_item.manifest.uuid,
oc_item.item_type)
if isinstance(oc_uri, str):
print('Make DOI id for: ' + oc_uri)
ezid_response = self.ezid.mint_identifier(oc_uri, metadata, 'doi')
if self.do_test:
print('EZID response: ' + str(ezid_response))
if isinstance(ezid_response, str):
if '|' in ezid_response:
resp_ex = ezid_response.split('|')
for resp_id in resp_ex:
if 'doi:' in resp_id:
ok = self.save_oc_item_stable_id(oc_item, resp_id, 'doi')
else:
pass
else:
ok = self.save_oc_item_stable_id(oc_item, ezid_response, 'doi')
return ok
示例11: prep_item_dc_metadata
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [as 别名]
def prep_item_dc_metadata(self):
""" prepared dublin core metadata for an item,
this needs to happen before we prep dc metadata
for associated items and sets of items
"""
if self.is_valid:
# make some uris
self.uri = URImanagement.make_oc_uri(self.manifest.uuid,
self.manifest.item_type)
self.project_uri = URImanagement.make_oc_uri(self.manifest.project_uuid,
'projects')
project_ent = self.get_entity(self.manifest.project_uuid)
if not isinstance(self.label, str):
self.label = self.manifest.label
self.title = self.make_dcterms_title(self.manifest.label,
self.context)
self.description = 'An archaeological site record'
context = self.remove_label_from_context(self.manifest.label,
self.context)
if isinstance(context, str):
self.description += ' from: ' + context
if project_ent is not False:
self.parent_project_uri = URImanagement.make_oc_uri(project_ent.parent_project_uuid,
'projects')
self.description += '; part of the "' + project_ent.label
self.description += '" data publication.'
if self.geo_meta is not None and self.geo_meta is not False:
if len(self.geo_meta) > 0:
geo = self.geo_meta[0]
if isinstance(geo.note, str):
if len(geo.note) > 0:
# self.description += ' ' + geo.note
pass
if geo.specificity < 0:
self.description += ' Location data approximated as a security precaution.'
if self.manifest.uuid != geo.uuid:
rel_meta = self.get_entity(geo.uuid)
if rel_meta is not False:
self.description += ' Location data provided through relationship to the'
self.description += ' related place: ' + rel_meta.label
self.description += ' (' + rel_meta.uri + ')'
示例12: make_all_identifiers
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [as 别名]
def make_all_identifiers(self, identifier):
""" makes all identifiers
used with an export table, based on a given identifier
if the given identifier has a '_' or '/' character,
it is either internal to Open Context ('_') or from
an expernal URI ('/')
"""
if '/' in identifier:
id_ex = identifier.split('/')
self.table_id = id_ex[1] + '_' + id_ex[0]
self.public_table_id = identifier
self.uri = URImanagement.make_oc_uri(self.public_table_id, 'tables')
elif '_' in identifier:
id_ex = identifier.split('_')
self.table_id = identifier
self.public_table_id = id_ex[1] + '/' + id_ex[0]
self.uri = URImanagement.make_oc_uri(self.public_table_id, 'tables')
else:
self.table_id = identifier
self.public_table_id = identifier
self.uri = URImanagement.make_oc_uri(self.public_table_id, 'tables')
示例13: prep_delete_uuid
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_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
示例14: prep_merge_uuid
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_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
示例15: make_type_relations
# 需要导入模块: from opencontext_py.apps.entities.uri.models import URImanagement [as 别名]
# 或者: from opencontext_py.apps.entities.uri.models.URImanagement import make_oc_uri [as 别名]
def make_type_relations(self, sub_type_pred_uuid,
sub_type_f_num,
rel_pred,
obj_type_pred_uuid,
obj_type_f_num):
""" Makes semantic relationships between
different types in an import
"""
rels = {}
sub_type_list = ImportCell.objects\
.filter(source_id=self.source_id,
field_num=sub_type_f_num)
for sub_type_obj in sub_type_list:
sub_type_text = sub_type_obj.record
row = sub_type_obj.row_num
if len(sub_type_text) > 0:
tm = TypeManagement()
tm.project_uuid = self.project_uuid
tm.source_id = self.source_id
sub_type = tm.get_make_type_within_pred_uuid(sub_type_pred_uuid,
sub_type_text)
obj_type_list = ImportCell.objects\
.filter(source_id=self.source_id,
field_num=obj_type_f_num,
row_num=row)[:1]
if len(obj_type_list) > 0:
obj_type_text = obj_type_list[0].record
if len(obj_type_text) > 0 \
and sub_type_text != obj_type_text:
tmo = TypeManagement()
tmo.project_uuid = self.project_uuid
tmo.source_id = self.source_id
obj_type = tmo.get_make_type_within_pred_uuid(obj_type_pred_uuid,
obj_type_text)
# make a uri for this, since we're making a link assertion
obj_uri = URImanagement.make_oc_uri(obj_type.uuid, 'types')
# the following bit is so we don't make the
# same link assertions over and over.
rel_id = str(sub_type.uuid) + ' ' + str(obj_type.uuid)
if rel_id not in rels:
rels[rel_id] = {'subject': sub_type.uuid,
'object_uri': obj_uri}
# now make the link data annotation relating these types.
for rel_id, rel in rels.items():
new_la = LinkAnnotation()
new_la.subject = rel['subject']
new_la.subject_type = 'types'
new_la.project_uuid = self.project_uuid
new_la.source_id = self.source_id
new_la.predicate_uri = rel_pred
new_la.object_uri = rel['object_uri']
new_la.creator_uuid = ''
new_la.save()