import json


def mal_categorizer(df, filename='attack_dictionary'):
    """Malware categorizer loads dictionary file and categorizes the attack names
    
    Args:
    df = pandas dataframe
    filename = name of malware dictionary
    
    Returns:
    df = new pandas dataframe with labeled categories (labels_2cat & labels_5cat)
    """
    
    with open(f'./data/{filename}.json') as f_in:
            attack_dict = json.load(f_in)
            
    df['labels_5cat'] = df['attack_name'].map(attack_dict)
    df['labels_2cat'] = df.labels_5cat.apply(lambda label: 'normal' if label == 'normal' else 'malicious')
    
    return df