Example #1
0
 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
Example #2
0
 def save_authorship(self, row_num, man):
     """ Saves authorship information """
     authors = ''
     auth = Authorship()
     found = auth.get_authors(man.uuid,
                              man.project_uuid)
     if found:
         # save counts of different dc-terms:creator for use as table metadata
         for auth_id in auth.creators:
             if auth_id not in self.dc_creator_ids:
                 self.dc_creator_ids[auth_id] = 0
             self.dc_creator_ids[auth_id] += 1
         # save counts of different dc-terms:contributor for use as table metadata    
         for auth_id in auth.contributors:
             if auth_id not in self.dc_contributor_ids:
                 self.dc_contributor_ids[auth_id] = 0
             self.dc_contributor_ids[auth_id] += 1    
         all_author_ids = auth.creators + auth.contributors
         all_authors = []
         for auth_id in all_author_ids:
             author = self.deref_entity_label(auth_id)
             all_authors.append(author)
         authors = '; '.join(all_authors)
     # save Authors
     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 = 7
     cell.record = authors
     cell.save()
     cell = None
Example #3
0
 def add_source_cells(self, uuid, row_num, item_data):
     """ Adds source data records for an assertion """
     predicate_values = LastUpdatedOrderedDict()
     project_uuid = item_data[0].project_uuid
     for assertion in item_data:
         predicate_uuid = assertion.predicate_uuid
         object_uuid = assertion.object_uuid
         if assertion.object_type == 'xsd:string':
             try:
                 oc_str = OCstring.objects.get(uuid=object_uuid)
                 obj_val = oc_str.content
             except OCstring.DoesNotExist:
                 obj_val = ''
         elif assertion.object_type in ['xsd:integer', 'xsd:double']:
             # numeric value
             obj_val = str(assertion.data_num)
         elif assertion.object_type == 'xsd:date':
             obj_val = str(assertion.data_date)
         else:
             obj_val = str(self.deref_entity_label(object_uuid))
         if predicate_uuid not in predicate_values:
             # make a list, since some predicates are multi-valued
             predicate_values[predicate_uuid] = []
         predicate_values[predicate_uuid].append(obj_val)
     for predicate_uuid, val_list in predicate_values.items():
         field_num = self.get_add_predicate_field_number(predicate_uuid)
         cell = ExpCell()
         cell.table_id = self.table_id
         cell.uuid = uuid
         cell.project_uuid = project_uuid
         cell.row_num = row_num
         cell.field_num = field_num
         cell.record = self.multi_source_value_delim.join(val_list)  # semi-colon delim for multivalued predicates
         cell.save()
         cell = None
Example #4
0
 def save_authorship(self, row_num, man):
     """ Saves authorship information """
     authors = ''
     auth = Authorship()
     found = auth.get_authors(man.uuid, man.project_uuid)
     if found:
         # save counts of different dc-terms:creator for use as table metadata
         for auth_id in auth.creators:
             if auth_id not in self.dc_creator_ids:
                 self.dc_creator_ids[auth_id] = 0
             self.dc_creator_ids[auth_id] += 1
         # save counts of different dc-terms:contributor for use as table metadata
         for auth_id in auth.contributors:
             if auth_id not in self.dc_contributor_ids:
                 self.dc_contributor_ids[auth_id] = 0
             self.dc_contributor_ids[auth_id] += 1
         all_author_ids = auth.creators + auth.contributors
         all_authors = []
         for auth_id in all_author_ids:
             author = self.deref_entity_label(auth_id)
             all_authors.append(author)
         authors = '; '.join(all_authors)
     # save Authors
     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 = 7
     cell.record = authors
     cell.save()
     cell = None
Example #5
0
 def save_default_chrono(self, row_num, man, event_meta):
     """ Saves earliest / latest times for an item """
     earliest = ''
     latest = ''
     if event_meta is not False:
         times = []
         for event in event_meta:
             times.append(event.start)
             times.append(event.stop)
         earliest = min(times)
         latest = max(times)
         if self.dates_bce_ce is False:
             earliest = 1950 - earliest
             latest = 1950 - latest
         earliest = round(earliest, 0)
         latest = round(latest, 0)
     # save earliest
     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 = 11
     cell.record = str(earliest)
     cell.save()
     cell = None
     # save latest
     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 = 12
     cell.record = str(latest)
     cell.save()
     cell = None
Example #6
0
 def save_default_chrono(self, row_num, man, event_meta):
     """ Saves earliest / latest times for an item """
     earliest = ''
     latest = ''
     if event_meta is not False:
         times = []
         for event in event_meta:
             times.append(event.start)
             times.append(event.stop)
         earliest = min(times)
         latest = max(times)
         if self.dates_bce_ce is False:
             earliest = 1950 - earliest
             latest = 1950 - latest
         earliest = round(earliest, 0)
         latest = round(latest, 0)
     # save earliest
     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 = 11
     cell.record = str(earliest)
     cell.save()
     cell = None
     # save latest
     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 = 12
     cell.record = str(latest)
     cell.save()
     cell = None
Example #7
0
 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
Example #8
0
 def add_source_cells(self, uuid, row_num, item_data):
     """ Adds source data records for an assertion """
     predicate_values = LastUpdatedOrderedDict()
     project_uuid = item_data[0].project_uuid
     for assertion in item_data:
         predicate_uuid = assertion.predicate_uuid
         object_uuid = assertion.object_uuid
         if assertion.object_type == 'xsd:string':
             try:
                 oc_str = OCstring.objects.get(uuid=object_uuid)
                 obj_val = oc_str.content
             except OCstring.DoesNotExist:
                 obj_val = ''
         elif assertion.object_type in ['xsd:integer', 'xsd:double']:
             # numeric value
             obj_val = str(assertion.data_num)
         elif assertion.object_type == 'xsd:date':
             obj_val = str(assertion.data_date)
         else:
             obj_val = str(self.deref_entity_label(object_uuid))
         if predicate_uuid not in predicate_values:
             # make a list, since some predicates are multi-valued
             predicate_values[predicate_uuid] = []
         predicate_values[predicate_uuid].append(obj_val)
     for predicate_uuid, val_list in predicate_values.items():
         field_num = self.get_add_predicate_field_number(predicate_uuid)
         cell = ExpCell()
         cell.table_id = self.table_id
         cell.uuid = uuid
         cell.project_uuid = project_uuid
         cell.row_num = row_num
         cell.field_num = field_num
         cell.record = self.multi_source_value_delim.join(
             val_list)  # semi-colon delim for multivalued predicates
         cell.save()
         cell = None
Example #9
0
 def save_default_geo(self, row_num, man, geo_meta):
     """ Saves geo lat / lon data for an item """
     latitude = ''
     longitude = ''
     note = 'Best available location data'
     if geo_meta is not False:
         for geo in geo_meta:
             if geo.meta_type == 'oc-gen:discovey-location':
                 latitude = geo.latitude
                 longitude = geo.longitude
                 if geo.specificity < 0:
                     note = 'Location approximated '
                     note += 'as a security precaution (Zoom: ' + str(
                         abs(geo.specificity)) + ')'
                 break
     # save Latitude
     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 = 8
     cell.record = str(latitude)
     cell.save()
     cell = None
     # save Longitude
     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 = 9
     cell.record = str(longitude)
     cell.save()
     cell = None
     # save Note
     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 = 10
     cell.record = note
     cell.save()
     cell = None
Example #10
0
 def save_default_geo(self, row_num, man, geo_meta):
     """ Saves geo lat / lon data for an item """
     latitude = ''
     longitude = ''
     note = 'Best available location data'
     if geo_meta is not False:
         for geo in geo_meta:
             if geo.meta_type == 'oc-gen:discovey-location':
                 latitude = geo.latitude
                 longitude = geo.longitude
                 if geo.specificity < 0:
                     note = 'Location approximated '
                     note += 'as a security precaution (Zoom: ' + str(abs(geo.specificity)) + ')'
                 break
     # save Latitude
     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 = 8
     cell.record = str(latitude)
     cell.save()
     cell = None
     # save Longitude
     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 = 9
     cell.record = str(longitude)
     cell.save()
     cell = None
     # save Note
     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 = 10
     cell.record = note
     cell.save()
     cell = None
Example #11
0
 def save_basic_default_field_cells(self, row_num, man):
     """ Saves the default fields that do not involve containment lookups """
     # save 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 = 1
     cell.record = URImanagement.make_oc_uri(man.uuid, man.item_type)
     cell.save()
     cell = None
     # save label
     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 = 2
     cell.record = man.label
     cell.save()
     cell = None
     # save project label
     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 = 3
     cell.record = self.deref_entity_label(man.project_uuid)
     cell.save()
     cell = None
     # save project 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 = 4
     cell.record = URImanagement.make_oc_uri(man.project_uuid, 'projects')
     cell.save()
     cell = None
     # save item category / class
     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 = 5
     cell.record = self.deref_entity_label(man.class_uri)
     cell.save()
     cell = None
     # last updated
     if man.revised is datetime:
         last_update = man.revised
     else:
         last_update = man.record_updated
     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 = 6
     cell.record = last_update.strftime('%Y-%m-%d')
     cell.save()
     cell = None
Example #12
0
 def add_ld_cells(self, uuid, row_num, item_data, pred_ld_equiv_uri):
     """ Adds linked data records for an assertion """
     if self.do_boolean_multiple_ld_fields(pred_ld_equiv_uri):
         multi_ld_fields = True
     else:
         multi_ld_fields = False
     obj_values = LastUpdatedOrderedDict()
     obj_values['[URI]'] = []
     obj_values['[Label]'] = []
     obj_values['[Source]'] = []
     project_uuid = item_data[0].project_uuid
     for assertion in item_data:
         object_uuid = assertion.object_uuid
         if assertion.object_type == 'xsd:string':
             try:
                 oc_str = OCstring.objects.get(uuid=object_uuid)
                 obj_label = oc_str.content
             except OCstring.DoesNotExist:
                 obj_label = ''
         else:
             obj_label = self.deref_entity_label(object_uuid)
             obj_label = str(obj_label)
         if obj_label not in obj_values['[Source]']:
             obj_values['[Source]'].append(obj_label)
         obj_ld_found = False
         if object_uuid in self.ld_object_equivs:
             for obj_ld_equiv_uri in self.ld_object_equivs[object_uuid]:
                 obj_ld_found = True
                 if multi_ld_fields:
                     cell_value = self.boolean_multiple_ld_fields
                     field_num = self.get_add_ld_field_number('[Has]',
                                                              pred_ld_equiv_uri,
                                                              obj_ld_equiv_uri)
                     cell = ExpCell()
                     cell.table_id = self.table_id
                     cell.uuid = uuid
                     cell.project_uuid = project_uuid
                     cell.row_num = row_num
                     cell.field_num = field_num
                     cell.record = cell_value
                     cell.save()
                     cell = None
                 else:
                     # predicate not broken into seperate fields for different values
                     obj_equiv_label = self.deref_entity_label(obj_ld_equiv_uri)
                     if obj_equiv_label is False:
                         obj_equiv_label = obj_ld_equiv_uri
                     if obj_equiv_label not in obj_values['[Label]']:
                         obj_values['[Label]'].append(obj_equiv_label)
                     if obj_ld_equiv_uri not in obj_values['[URI]']:
                         obj_values['[URI]'].append(obj_ld_equiv_uri)
         if obj_ld_found is False:
             print('No linked data for object:' + object_uuid)
     if multi_ld_fields is False:
         # predicate not broken into seperate fields for different values
         for field_type, value_list in obj_values.items():
             if len(value_list) > 0:
                 try:
                     cell_value = '; '.join(value_list)
                 except:
                     # some messiness in the data, won't join into a string
                     cell_value = False
                     for val in value_list:
                         val = str(val)
                         if cell_value is False:
                             cell_value = val
                         else:
                             cell_value += '; ' + val
                 field_num = self.get_add_ld_field_number(field_type,
                                                          pred_ld_equiv_uri)
                 cell = ExpCell()
                 cell.table_id = self.table_id
                 cell.uuid = uuid
                 cell.project_uuid = project_uuid
                 cell.row_num = row_num
                 cell.field_num = field_num
                 cell.record = cell_value
                 cell.save()
                 cell = None
Example #13
0
 def save_basic_default_field_cells(self, row_num, man):
     """ Saves the default fields that do not involve containment lookups """
     # save 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 = 1
     cell.record = URImanagement.make_oc_uri(man.uuid, man.item_type)
     cell.save()
     cell = None
     # save label
     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 = 2
     cell.record = man.label
     cell.save()
     cell = None
     # save project label
     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 = 3
     cell.record = self.deref_entity_label(man.project_uuid)
     cell.save()
     cell = None
     # save project 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 = 4
     cell.record = URImanagement.make_oc_uri(man.project_uuid, 'projects')
     cell.save()
     cell = None
     # save item category / class
     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 = 5
     cell.record = self.deref_entity_label(man.class_uri)
     cell.save()
     cell = None
     # last updated
     if man.revised is datetime:
         last_update = man.revised
     else:
         last_update = man.record_updated
     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 = 6
     cell.record = last_update.strftime('%Y-%m-%d')
     cell.save()
     cell = None
Example #14
0
 def add_ld_cells(self, uuid, row_num, item_data, pred_ld_equiv_uri):
     """ Adds linked data records for an assertion """
     if self.do_boolean_multiple_ld_fields(pred_ld_equiv_uri):
         multi_ld_fields = True
     else:
         multi_ld_fields = False
     obj_values = LastUpdatedOrderedDict()
     obj_values['[URI]'] = []
     obj_values['[Label]'] = []
     obj_values['[Source]'] = []
     project_uuid = item_data[0].project_uuid
     for assertion in item_data:
         object_uuid = assertion.object_uuid
         if assertion.object_type == 'xsd:string':
             try:
                 oc_str = OCstring.objects.get(uuid=object_uuid)
                 obj_label = oc_str.content
             except OCstring.DoesNotExist:
                 obj_label = ''
         else:
             obj_label = self.deref_entity_label(object_uuid)
             obj_label = str(obj_label)
         if obj_label not in obj_values['[Source]']:
             obj_values['[Source]'].append(obj_label)
         obj_ld_found = False
         if object_uuid in self.ld_object_equivs:
             for obj_ld_equiv_uri in self.ld_object_equivs[object_uuid]:
                 obj_ld_found = True
                 if multi_ld_fields:
                     cell_value = self.boolean_multiple_ld_fields
                     field_num = self.get_add_ld_field_number(
                         '[Has]', pred_ld_equiv_uri, obj_ld_equiv_uri)
                     cell = ExpCell()
                     cell.table_id = self.table_id
                     cell.uuid = uuid
                     cell.project_uuid = project_uuid
                     cell.row_num = row_num
                     cell.field_num = field_num
                     cell.record = cell_value
                     cell.save()
                     cell = None
                 else:
                     # predicate not broken into seperate fields for different values
                     obj_equiv_label = self.deref_entity_label(
                         obj_ld_equiv_uri)
                     if obj_equiv_label is False:
                         obj_equiv_label = obj_ld_equiv_uri
                     if obj_equiv_label not in obj_values['[Label]']:
                         obj_values['[Label]'].append(obj_equiv_label)
                     if obj_ld_equiv_uri not in obj_values['[URI]']:
                         obj_values['[URI]'].append(obj_ld_equiv_uri)
         if obj_ld_found is False:
             print('No linked data for object:' + object_uuid)
     if multi_ld_fields is False:
         # predicate not broken into seperate fields for different values
         for field_type, value_list in obj_values.items():
             if len(value_list) > 0:
                 try:
                     cell_value = '; '.join(value_list)
                 except:
                     # some messiness in the data, won't join into a string
                     cell_value = False
                     for val in value_list:
                         val = str(val)
                         if cell_value is False:
                             cell_value = val
                         else:
                             cell_value += '; ' + val
                 field_num = self.get_add_ld_field_number(
                     field_type, pred_ld_equiv_uri)
                 cell = ExpCell()
                 cell.table_id = self.table_id
                 cell.uuid = uuid
                 cell.project_uuid = project_uuid
                 cell.row_num = row_num
                 cell.field_num = field_num
                 cell.record = cell_value
                 cell.save()
                 cell = None