{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0e4e4b7d", "metadata": {}, "outputs": [], "source": [ "import json\n", "with open('Step3_output_article_response_original_3.json', encoding=\"utf8\") as f:\n", " data_pos = json.load(f)\n", "with open('Step3_output_article_response_opposite_2.json', encoding=\"utf8\") as f:\n", " data_neg = json.load(f)\n", " " ] }, { "cell_type": "code", "execution_count": 16, "id": "e7b83fa4", "metadata": {}, "outputs": [], "source": [ "combined_list = []\n", "for art_id in range(len(data_pos)):\n", " entry = {}\n", " entry['article_id'] = art_id\n", " entry['article_name'] = data_pos[art_id]['title']\n", " entry['article_institute'] = data_pos[art_id]['universities']\n", " entry['article_abstract'] = data_pos[art_id]['abstract']\n", " \n", " entry['measures_positive'] = [l[0] for l in data_pos[art_id]['response'][0][:]]\n", " entry['responses_positive'] = [l[2] for l in data_pos[art_id]['response'][0][:]]\n", " entry['scores_positive'] = [l[3] for l in data_pos[art_id]['response'][0][:]]\n", " \n", " entry['measures_negative'] = [l[0] for l in data_neg[art_id]['response'][0][:]]\n", " entry['responses_negative'] = [l[2] for l in data_neg[art_id]['response'][0][:]]\n", " entry['scores_negative'] = [l[3] for l in data_neg[art_id]['response'][0][:]]\n", "\n", " combined_list += [entry]\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 21, "id": "24d0c9b5", "metadata": {}, "outputs": [], "source": [ "with open('output/Step4_article_response_all_combined_2.json', 'w', encoding=\"utf8\") as f:\n", " json.dump(combined_list, f, ensure_ascii=False)" ] }, { "cell_type": "code", "execution_count": 19, "id": "0cda7716", "metadata": {}, "outputs": [], "source": [ "import csv\n", "\n", "def write_csv(filename, score_lbl='scores_positive'):\n", " # Open the file in append mode\n", " with open(filename, mode='w', newline='', encoding=\"utf-8-sig\") as file:\n", " writer = csv.writer(file)\n", "\n", " labels = ['Value '+str(j) for j in range(64)]\n", "\n", " writer.writerow(['Institute'] + labels)\n", "\n", " for i in range(0, len(combined_list)):\n", " article = combined_list[i]\n", " uni = article['article_institute']\n", " rankings = article[score_lbl]\n", " writer.writerow([uni]+rankings)\n", " \n", "write_csv(filename='output/Step4_scores_positive_2.csv', score_lbl='scores_positive')\n", "write_csv(filename='output/Step4_scores_negative_2.csv', score_lbl='scores_negative')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.13" } }, "nbformat": 4, "nbformat_minor": 5 }