示例#1
0
 def add_table_file_download(self, table_id, file_uri):
     """ adds a file_uri for a pre-cached table download """
     ex_tabs = ExpTable.objects.filter(table_id=table_id)[:1]
     for ex_tab in ex_tabs:
         if ExpTable.PREDICATE_DUMP in ex_tab.meta_json:
             dump_list = ex_tab.meta_json[ExpTable.PREDICATE_DUMP]
         else:
             # no predicate for a data dump, so look for it
             dump_list = []
         mm = ManageMediafiles()
         ok = mm.get_head_info(file_uri)
         if ok:
             dump_item = LastUpdatedOrderedDict()
             dump_item['id'] = file_uri
             dump_item['dc-terms:hasFormat'] = mm.mime_type_uri
             dump_item['dcat:size'] = float(mm.filesize)
             print('Found: ' + str(dump_item))
             dump_list.append(dump_item)
             ex_tab.meta_json[ExpTable.PREDICATE_DUMP] = dump_list
             ex_tab.save()
             man_items = Manifest.objects.filter(uuid=table_id)[:1]
             if len(man_items) > 0:
                 man_obj = man_items[0]
                 new_anno = LinkAnnotation()
                 new_anno.subject = man_obj.uuid
                 new_anno.subject_type = man_obj.item_type
                 new_anno.project_uuid = man_obj.project_uuid
                 new_anno.source_id = 'download-file-relate'
                 new_anno.predicate_uri = ExpTable.PREDICATE_DUMP
                 new_anno.object_uri = file_uri
                 new_anno.sort = len(dump_list)
                 new_anno.obj_extra = dump_item
                 new_anno.save()
示例#2
0
 def add_table_file_download(self, table_id, file_uri):
     """ adds a file_uri for a pre-cached table download """
     ex_tabs = ExpTable.objects.filter(table_id=table_id)[:1]
     for ex_tab in ex_tabs:
         if ExpTable.PREDICATE_DUMP in ex_tab.meta_json:
             dump_list = ex_tab.meta_json[ExpTable.PREDICATE_DUMP]
         else:
             # no predicate for a data dump, so look for it
             dump_list = []
         mm = ManageMediafiles()
         ok = mm.get_head_info(file_uri)
         if ok:
             dump_item = LastUpdatedOrderedDict()
             dump_item['id'] = file_uri
             dump_item['dc-terms:hasFormat'] = mm.mime_type_uri
             dump_item['dcat:size'] = float(mm.filesize)
             print('Found: ' + str(dump_item))
             dump_list.append(dump_item)
             ex_tab.meta_json[ExpTable.PREDICATE_DUMP] = dump_list
             ex_tab.save()
             man_items = Manifest.objects.filter(uuid=table_id)[:1]
             if len(man_items) > 0:
                 man_obj = man_items[0]
                 new_anno = LinkAnnotation()
                 new_anno.subject = man_obj.uuid
                 new_anno.subject_type = man_obj.item_type
                 new_anno.project_uuid = man_obj.project_uuid
                 new_anno.source_id = 'download-file-relate'
                 new_anno.predicate_uri = ExpTable.PREDICATE_DUMP
                 new_anno.object_uri = file_uri
                 new_anno.sort = len(dump_list)
                 new_anno.obj_extra = dump_item
                 new_anno.save()
示例#3
0
 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()
示例#4
0
 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()
示例#5
0
 def generate_table_metadata(self, table_id, overwrite=False):
     """ makes metadata for a specific table """
     ex_id = ExpTableIdentifiers()
     ex_id.make_all_identifiers(table_id)
     table_ids = [ex_id.table_id,
                  ex_id.public_table_id]
     try:
         ex_tab = ExpTable.objects.get(table_id=table_id)
     except ExpTable.DoesNotExist:
         print('No ExpTable object for: ' + ex_id.public_table_id)
         ex_tab = None
     try:
         man_obj = Manifest.objects.get(uuid=ex_id.public_table_id)
     except Manifest.DoesNotExist:
         print('No manifest object for: ' + ex_id.public_table_id)
         man_obj = None
     if ex_tab is not None and man_obj is not None:
         proj_uuid_counts = None
         for meta_pred in self.metadata_predicates:
             if overwrite:
                 num_old_delete = LinkAnnotation.objects\
                                                .filter(subject__in=table_ids,
                                                        predicate_uri=meta_pred)\
                                                .delete()
                 print('Deleted annoations ' + str(num_old_delete) + ' for ' + meta_pred)
                 add_meta_for_pred = True
             else:
                 num_exists = LinkAnnotation.objects\
                                            .filter(subject__in=table_ids,
                                                    predicate_uri=meta_pred)[:1]
                 if len(num_exists) < 1:
                     add_meta_for_pred = True
                 else:
                     add_meta_for_pred = False
             if add_meta_for_pred:
                 if meta_pred == 'dc-terms:contributor':
                     print('Getting contributors for ' + table_id)
                     sorted_author_list = self.get_table_author_counts(table_id)
                     contrib_sort = 0
                     for s_author in sorted_author_list:
                         contrib_sort += 1
                         obj_extra = LastUpdatedOrderedDict()
                         obj_extra['count'] = s_author['count']
                         la = LinkAnnotation()
                         la.subject = man_obj.uuid
                         la.subject_type = man_obj.item_type
                         la.project_uuid = man_obj.project_uuid
                         la.source_id = 'exp-table-manage'
                         la.predicate_uri = meta_pred
                         la.object_uri = URImanagement.make_oc_uri(s_author['uuid'], 'persons')
                         la.creator_uuid = '0'
                         la.sort = contrib_sort
                         la.obj_extra = obj_extra
                         la.save()
                 if meta_pred in ['dc-terms:creator',
                                  'dc-terms:source']:
                     # need to get projects for this
                     if proj_uuid_counts is None:
                         # only get this if not gotten yet
                         print('Getting projects for ' + table_id)
                         proj_uuid_counts = self.get_table_project_uuid_counts(table_id)
                     if meta_pred == 'dc-terms:creator':
                         print('Getting creators for ' + table_id)
                         dc_creator_list = self.make_table_dc_creator_list(proj_uuid_counts)
                         create_sort = 0
                         for dc_creator in dc_creator_list:
                             create_sort += 1
                             obj_extra = LastUpdatedOrderedDict()
                             obj_extra['count'] = dc_creator['count']
                             la = LinkAnnotation()
                             la.subject = man_obj.uuid
                             la.subject_type = man_obj.item_type
                             la.project_uuid = man_obj.project_uuid
                             la.source_id = 'exp-table-manage'
                             la.predicate_uri = meta_pred
                             la.object_uri = dc_creator['id']
                             la.creator_uuid = '0'
                             la.sort = create_sort
                             la.obj_extra = obj_extra
                             la.save()
                     if meta_pred == 'dc-terms:source':
                         print('Getting sources for ' + table_id)
                         proj_sort = 0
                         for proj_uuid_count in proj_uuid_counts:
                             proj_sort += 1
                             obj_extra = LastUpdatedOrderedDict()
                             obj_extra['count'] = proj_uuid_count['num_uuids']
                             la = LinkAnnotation()
                             la.subject = man_obj.uuid
                             la.subject_type = man_obj.item_type
                             la.project_uuid = man_obj.project_uuid
                             la.source_id = 'exp-table-manage'
                             la.predicate_uri = meta_pred
                             la.object_uri = URImanagement.make_oc_uri(proj_uuid_count['project_uuid'],
                                                                       'projects')
                             la.creator_uuid = '0'
                             la.sort = proj_sort
                             la.obj_extra = obj_extra
                             la.save()
                 if meta_pred == 'dc-terms:subject':
                     print('Getting subjects for ' + table_id)
                     dc_subject_list = self.make_table_dc_subject_category_list(table_id)
                     subj_sort = 0
                     for dc_subject in dc_subject_list:
                         subj_sort += 1
                         obj_extra = LastUpdatedOrderedDict()
                         obj_extra['count'] = dc_subject['count']
                         la = LinkAnnotation()
                         la.subject = man_obj.uuid
                         la.subject_type = man_obj.item_type
                         la.project_uuid = man_obj.project_uuid
                         la.source_id = 'exp-table-manage'
                         la.predicate_uri = meta_pred
                         la.object_uri = dc_subject['id']
                         la.creator_uuid = '0'
                         la.sort = subj_sort
                         la.obj_extra = obj_extra
                         la.save()
示例#6
0
 def generate_table_metadata(self, table_id, overwrite=False):
     """ makes metadata for a specific table """
     ex_id = ExpTableIdentifiers()
     ex_id.make_all_identifiers(table_id)
     table_ids = [ex_id.table_id, ex_id.public_table_id]
     try:
         ex_tab = ExpTable.objects.get(table_id=table_id)
     except ExpTable.DoesNotExist:
         print('No ExpTable object for: ' + ex_id.public_table_id)
         ex_tab = None
     try:
         man_obj = Manifest.objects.get(uuid=ex_id.public_table_id)
     except Manifest.DoesNotExist:
         print('No manifest object for: ' + ex_id.public_table_id)
         man_obj = None
     if ex_tab is not None and man_obj is not None:
         proj_uuid_counts = None
         for meta_pred in self.metadata_predicates:
             if overwrite:
                 num_old_delete = LinkAnnotation.objects\
                                                .filter(subject__in=table_ids,
                                                        predicate_uri=meta_pred)\
                                                .delete()
                 print('Deleted annoations ' + str(num_old_delete) +
                       ' for ' + meta_pred)
                 add_meta_for_pred = True
             else:
                 num_exists = LinkAnnotation.objects\
                                            .filter(subject__in=table_ids,
                                                    predicate_uri=meta_pred)[:1]
                 if len(num_exists) < 1:
                     add_meta_for_pred = True
                 else:
                     add_meta_for_pred = False
             if add_meta_for_pred:
                 if meta_pred == 'dc-terms:contributor':
                     print('Getting contributors for ' + table_id)
                     sorted_author_list = self.get_table_author_counts(
                         table_id)
                     contrib_sort = 0
                     for s_author in sorted_author_list:
                         contrib_sort += 1
                         obj_extra = LastUpdatedOrderedDict()
                         obj_extra['count'] = s_author['count']
                         la = LinkAnnotation()
                         la.subject = man_obj.uuid
                         la.subject_type = man_obj.item_type
                         la.project_uuid = man_obj.project_uuid
                         la.source_id = 'exp-table-manage'
                         la.predicate_uri = meta_pred
                         la.object_uri = URImanagement.make_oc_uri(
                             s_author['uuid'], 'persons')
                         la.creator_uuid = '0'
                         la.sort = contrib_sort
                         la.obj_extra = obj_extra
                         la.save()
                 if meta_pred in ['dc-terms:creator', 'dc-terms:source']:
                     # need to get projects for this
                     if proj_uuid_counts is None:
                         # only get this if not gotten yet
                         print('Getting projects for ' + table_id)
                         proj_uuid_counts = self.get_table_project_uuid_counts(
                             table_id)
                     if meta_pred == 'dc-terms:creator':
                         print('Getting creators for ' + table_id)
                         dc_creator_list = self.make_table_dc_creator_list(
                             proj_uuid_counts)
                         create_sort = 0
                         for dc_creator in dc_creator_list:
                             create_sort += 1
                             obj_extra = LastUpdatedOrderedDict()
                             obj_extra['count'] = dc_creator['count']
                             la = LinkAnnotation()
                             la.subject = man_obj.uuid
                             la.subject_type = man_obj.item_type
                             la.project_uuid = man_obj.project_uuid
                             la.source_id = 'exp-table-manage'
                             la.predicate_uri = meta_pred
                             la.object_uri = dc_creator['id']
                             la.creator_uuid = '0'
                             la.sort = create_sort
                             la.obj_extra = obj_extra
                             la.save()
                     if meta_pred == 'dc-terms:source':
                         print('Getting sources for ' + table_id)
                         proj_sort = 0
                         for proj_uuid_count in proj_uuid_counts:
                             proj_sort += 1
                             obj_extra = LastUpdatedOrderedDict()
                             obj_extra['count'] = proj_uuid_count[
                                 'num_uuids']
                             la = LinkAnnotation()
                             la.subject = man_obj.uuid
                             la.subject_type = man_obj.item_type
                             la.project_uuid = man_obj.project_uuid
                             la.source_id = 'exp-table-manage'
                             la.predicate_uri = meta_pred
                             la.object_uri = URImanagement.make_oc_uri(
                                 proj_uuid_count['project_uuid'],
                                 'projects')
                             la.creator_uuid = '0'
                             la.sort = proj_sort
                             la.obj_extra = obj_extra
                             la.save()
                 if meta_pred == 'dc-terms:subject':
                     print('Getting subjects for ' + table_id)
                     dc_subject_list = self.make_table_dc_subject_category_list(
                         table_id)
                     subj_sort = 0
                     for dc_subject in dc_subject_list:
                         subj_sort += 1
                         obj_extra = LastUpdatedOrderedDict()
                         obj_extra['count'] = dc_subject['count']
                         la = LinkAnnotation()
                         la.subject = man_obj.uuid
                         la.subject_type = man_obj.item_type
                         la.project_uuid = man_obj.project_uuid
                         la.source_id = 'exp-table-manage'
                         la.predicate_uri = meta_pred
                         la.object_uri = dc_subject['id']
                         la.creator_uuid = '0'
                         la.sort = subj_sort
                         la.obj_extra = obj_extra
                         la.save()