<jupyter_start><jupyter_text>Load gold standard data<jupyter_code>import pickle
import pandas as pd
from newsplease import NewsPlease

def load_obj(month, idx):
    month = str(month).zfill(2)
    idx = str(idx).zfill(5)
    with open("../data/texts/{}/{}.pkl".format(month, idx), "rb") as f:
        return pickle.load(f)
    
def load_dict(month):
    month = str(month).zfill(2)
    with open("../data/metadata/matching/{}.pkl".format(month), "rb") as f:
        return pickle.load(f)
gs = pd.read_csv('../data/gold-standard/gold_standard.csv')

gs_articles = {}

for i in range(len(gs)):
    article = load_obj(gs['month'][i], gs['ids'][i])
    gs_articles[i] = article<jupyter_output><empty_output><jupyter_text>Load metadata for one gold standard<jupyter_code>gs = pd.read_csv('../data/gold-standard/gold_standard.csv')
gs_sample = gs.iloc[1]

def match_metadata(gs_sample):
    month = str(gs_sample['month']).zfill(2)
    idx = gs_sample['ids']
    matching_dictionary = load_dict(month)
    print('This sample matches these rows in {}.csv: {}'.format(month, matching_dictionary[idx]))
    df = pd.read_csv("../data/metadata/variables/{}.csv".format(month))
    return df.iloc[matching_dictionary[idx]]
    
match_metadata(gs_sample)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16601101494885917, 'fraction_numerical': 0.003933910306845004, 'mean_word_length': 4.578947368421052, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '657855', 'license': 'MIT', 'n_tokens_mistral': 465, 'n_tokens_neox': 455, 'n_words': 81, 'path': 'notebooks/0-jmb-quickstart.ipynb', 'repo_name': 'rrupam/WRI', 'size': '1271'}