text_plain_output_1.png
import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

def get_number_of_elements_nested_list(list_of_keyword_lists):
    counter = 0
    for lst in list_of_keyword_lists:
        counter += len(lst)
    return counter
def evaluate_text_via_list_of_list_of_keywords(text, list_of_keyword_lists):
    num_keyword_lists = len(list_of_keyword_lists)
    len_text = len(text)
    arr_keyword_list_hits = np.zeros(num_keyword_lists)
    for num_word in range(len_text):
        for num_keyword_list in range(num_keyword_lists):
            if text[num_word] in list_of_keyword_lists[num_keyword_list]:
                arr_keyword_list_hits[num_keyword_list] += 1
    return arr_keyword_list_hits
def evaluate_journal_by_keywords(df_paper, list_of_keyword_lists):
    """
    df_paper                 pd.DataFrame with Covid 19 papers
    list_of_keyword_lists    Nested list. Contains multiple lists with keywords. Each list is a subgroup/clustering of keywords.
    """
    num_entries = df_paper.shape[0]
    dct_abstracts = {}
    num_keywords = get_number_of_elements_nested_list(list_of_keyword_lists)
    for num_paper in range(num_entries):
        if type(df_paper.iloc[num_paper, 8]) != float:
            txt_abstract = df_paper.iloc[num_paper, 8].split()
            idx = num_paper
            arr_keyword_list_hits = evaluate_text_via_list_of_list_of_keywords(txt_abstract, list_of_keyword_lists)
            int_keyword_frequency = sum(arr_keyword_list_hits)
            num_keyword_sources = len(arr_keyword_list_hits[arr_keyword_list_hits > 0])
            num_keyword_lists = len(list_of_keyword_lists)
            numerator = num_keyword_sources + int_keyword_frequency
            denominator = num_keyword_lists + num_keywords
            abstract_score = numerator / denominator
            dct_abstracts.update({num_paper: {'Abstract Score': abstract_score}})
    return dct_abstracts

data_dir = '../input/CORD-19-research-challenge/'
data_file = 'metadata.csv'
data = pd.read_csv(data_dir + data_file)

lst_corona = ['Corona', 'corona', 'corona virus', 'coronavirus', 'corona viruses', 'coronaviruses', 'Coronaviridae', 'coronaviridae', 'COVID-19', 'Covid-19', 'covid-19', 'COVID', 'COV', 'SARS']
lst_genetics = ['genetics']
lst_origin = ['origin', 'member', 'family']
lst_evolution = ['evolution', 'development', 'develops', 'developed']
lst_task = [lst_genetics, lst_origin, lst_evolution]
lst_subtask_1_genome = ['Genome', 'genome']
lst_subtask_1_dissemination = ['dissemination', 'Dissemination', 'propagation', 'Propagation', 'spread', 'Spread', 'spreading', 'Spreading']
lst_subtask_1_treatment = ['treatment', 'Treatment', 'diagnostic', 'Diagnostic', 'diagnostics', 'Diagnostics', 'therapeutics', 'Therapeutics']
lst_subtask_1_variation = ['Difference', 'in contrast', 'variation', 'deviation', 'shows mutations', 'enrichment', 'similarities']
lst_subtask_1_reference = ['Accession number', 'reference', 'sample', 'identification of']
lst_subtask_1_known = ['Known', 'already published', 'already reported']
lst_subtask_1 = [lst_subtask_1_genome, lst_subtask_1_dissemination, lst_subtask_1_treatment, lst_subtask_1_variation, lst_subtask_1_reference, lst_subtask_1_known, lst_corona]
lst_subtask_2_ = []
lst_subtask_2_ = []
lst_subtask_2_ = []
lst_subtask_2_ = []
lst_subtask_2_ = []
lst_subtask_2 = []
lst_subtask_3_2_livestock = ['farm', 'wildlife', 'wild animal', 'undomesticated', 'livestock']
lst_subtask_3_2_area = ['Southeast-Asia']
lst_subtask_3_2_control = ['surveil', 'control', 'screen', 'check', 'monitor', 'examine']
lst_subtask_3_2 = [lst_subtask_3_2_livestock, lst_subtask_3_2_area, lst_subtask_3_2_control, lst_corona]
lst_subtask_3_1_host = ['host', 'organism', 'human']
lst_subtask_3_2_infection = ['infection', 'disease', 'respiratory syndrom']
lst_subtask_3_3_lab = ['experimental', 'laboratory', 'under conditions']
lst_subtask_3 = [lst_subtask_3_1_host, lst_subtask_3_2_infection, lst_subtask_3_3_lab, lst_corona]
lst_subtask_4_host = ['animal', 'host', 'hosts', 'Host', 'Hosts', 'human', 'Human', 'Humans', 'humans', 'CoV-Host', 'organism']
lst_subtask_4_transmission = ['pathogen', 'spill-over', 'intraspecies', 'interaction', 'host-shift', 'spread', 'evolution', 'transmission', 'infection']
lst_subtask_4_evidence = ['evidence', 'proof', 'association', 'connection', 'associated']
lst_subtask_4 = [lst_subtask_4_host, lst_subtask_4_transmission, lst_subtask_4_evidence, lst_corona]
lst_subtask_5_ = []
lst_subtask_5_ = []
lst_subtask_5_ = []
lst_subtask_5_ = []
lst_subtask_5 = []
lst_subtask_6_ = []
lst_subtask_6_ = []
lst_subtask_6_ = []
lst_subtask_6_ = []
lst_subtask_6_ = []
lst_subtask_6 = []

dct_res = evaluate_journal_by_keywords(data, lst_subtask_1)

lst_ranked = sorted(dct_res, key=lambda x: dct_res[x]['Abstract Score'], reverse=True)
lst_ranked[:3]