예제 #1
0
 def clear_source(self):
     """ Clears a prior import if the start_row is 1.
         This makes sure new entities and assertions are made for
         this source_id, and we don't duplicate things
     """
     if self.start_row <= 1:
         # get rid of "subjects" related assertions made from this source
         unimport = UnImport(self.source_id, self.project_uuid)
         unimport.delete_media_entities()
예제 #2
0
 def clear_source(self):
     """ Clears a prior import if the start_row is 1.
         This makes sure new entities and assertions are made for
         this source_id, and we don't duplicate things
     """
     if self.start_row <= 1:
         # get rid of "subjects" related assertions made from this source
         unimport = UnImport(self.source_id,
                             self.project_uuid)
         unimport.delete_person_entities()
예제 #3
0
 def clear_source(self):
     """ Clears a prior import if the start_row is 1.
         This makes sure new entities and assertions are made for
         this source_id, and we don't duplicate things
     """
     if self.start_row <= 1:
         # will clear an import of descriptions
         unimport = UnImport(self.source_id,
                             self.project_uuid)
         unimport.delete_links_assertions()
         unimport.delete_predicate_links(False)
     return True
예제 #4
0
 def note_unimport_ok(self, raw_p_sources):
     """ Checks to see if it's OK to unimport a given source """
     p_sources = []
     for p_source in raw_p_sources:
         # checks to see if the source can be reloaded from Refine
         unimp = UnImport(p_source.source_id, p_source.project_uuid)
         p_source.undo_ok = unimp.delete_ok
         p_sources.append(p_source)
     return p_sources
예제 #5
0
def update_contexts_subjects(project_uuid, source_id, all_contexts_df):
    """Updates the database to have subjects and contexts """
    print('Unimport project: {}, source: {}'.format(project_uuid, source_id))
    unimp = UnImport(source_id, project_uuid)
    unimp.delete_ok = True
    unimp.delete_all()
    update_indx = (all_contexts_df['parent_uuid'].notnull())
    new_contexts_df = all_contexts_df[update_indx].copy()
    ordered_classes = CLASS_CONTEXT_IMPORT_ORDER.copy()
    ordered_classes += [
        c for c in new_contexts_df['class_uri'].unique().tolist()
        if c not in CLASS_CONTEXT_IMPORT_ORDER
    ]
    new_contexts_df.sort_values(by=(PATH_CONTEXT_COLS + ['label']),
                                inplace=True,
                                na_position='first')
    new_contexts_df[DB_LOAD_RESULT_A_COL] = np.nan
    # First Create records for data with a parent in Open Context
    oc_par_index = (
        new_contexts_df['parent_uuid_source'] == UUID_SOURCE_OC_LOOKUP)
    parent_uuids = new_contexts_df[oc_par_index]['parent_uuid'].unique(
    ).tolist()
    print('Loading contexts that are children of {} contexts in DB.'.format(
        len(parent_uuids)))
    new_contexts_df = load_context_dataframe(project_uuid,
                                             source_id,
                                             new_contexts_df,
                                             parent_uuids=parent_uuids)
    for class_uri in ordered_classes:
        print('Loading contexts for class_uri: {}'.format(class_uri))
        new_contexts_df = load_context_dataframe(
            project_uuid,
            source_id,
            new_contexts_df,
            class_uri=class_uri,
        )

    # Now sort the assertions we just created.
    # Now sort the assertions for the items just impacted.
    asor = AssertionSorting()
    asor.re_rank_assertions_by_source(project_uuid, source_id)

    return new_contexts_df
예제 #6
0
def purge_data_from_source(project_uuid, source_id):
    print('Unimport project: {}, source: {}'.format(project_uuid, source_id))
    unimp = UnImport(source_id, project_uuid)
    unimp.delete_ok = True
    unimp.delete_all()
    print('Unimport data from importer project: {}, source: {}'.format(
        project_uuid, source_id))
    ImportCell.objects.filter(
        project_uuid=project_uuid,
        source_id=source_id,
    ).delete()
    ImportField.objects.filter(
        project_uuid=project_uuid,
        source_id=source_id,
    ).delete()
    ImportFieldAnnotation.objects.filter(
        project_uuid=project_uuid,
        source_id=source_id,
    ).delete()
    ImportSource.objects.filter(
        project_uuid=project_uuid,
        source_id=source_id,
    ).delete()
예제 #7
0
 def clear_source(self):
     """ Clears a prior import if the start_row is 1.
         This makes sure new entities and assertions are made for
         this source_id, and we don't duplicate things
     """
     if self.start_row <= 1:
         # will clear an import of descriptions
         print('Clearing old description assertions...')
         unimport = UnImport(self.source_id,
                             self.project_uuid)
         unimport.COMPLEX_DESCRIPTION_SOURCE_SUFFIX = ProcessGeneral.COMPLEX_DESCRIPTION_SOURCE_SUFFIX
         ok = unimport.delete_describe_assertions()
         if ok:
             print('Assertions deleted...')
         else:
             print('Something horrible happened!')
         unimport.delete_predicate_vars()
         unimport.delete_types_entities()
         unimport.delete_strings()
     return True
예제 #8
0
 def clear_source(self):
     """ Clears a prior import if the start_row is 1.
         This makes sure new entities and assertions are made for
         this source_id, and we don't duplicate things
     """
     if self.start_row <= 1:
         # will clear an import of descriptions
         unimport = UnImport(self.source_id, self.project_uuid)
         unimport.delete_links_assertions()
         unimport.delete_predicate_links(False)
     return True