Ejemplo n.º 1
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
Ejemplo n.º 2
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()