From 9898c8a14380e6b53d54814efc271bec48fc6d9c Mon Sep 17 00:00:00 2001 From: Steven Tischer Date: Mon, 8 Jun 2026 20:16:02 +0200 Subject: [PATCH] add papers and abstract to get_data_2.py --- llm_evaluations/bio_generation/get_data_2.py | 54 ++++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/llm_evaluations/bio_generation/get_data_2.py b/llm_evaluations/bio_generation/get_data_2.py index bbaf27b4..0318b6d0 100644 --- a/llm_evaluations/bio_generation/get_data_2.py +++ b/llm_evaluations/bio_generation/get_data_2.py @@ -1,8 +1,8 @@ import requests, json import helpers -# AUTHOR_OPEN_ALEXID = helpers.get_all_author_ids_from_specific_university("University of Duisburg-Essen") -AUTHOR_OPEN_ALEXID = ["A5007170803"] +AUTHOR_OPEN_ALEXID = helpers.get_all_author_ids_from_specific_university("University of Duisburg-Essen") +#AUTHOR_OPEN_ALEXID = ["A5093075883"] ANZAHL_TOP_TOPICS = 5 WORKS_PAGE_SIZE = 100 @@ -12,9 +12,17 @@ ES_HEADERS = { "Content-Type": "application/json", } +WORK_SOURCE_FIELDS = [ + "title", + "display_name", + "abstract_inverted_index", + "cited_by_count", + "primary_topic", +] + def write_data_to_file(author_id, data): - with open(f"data/{author_id}.json", "w") as f: + with open(f"data2/{author_id}.json", "w") as f: json.dump(data, f) @@ -60,7 +68,7 @@ def fetch_author_works(author_id): while True: payload = { "query": authorship_query, - "_source": ["primary_topic"], + "_source": WORK_SOURCE_FIELDS, "from": page * WORKS_PAGE_SIZE, "size": WORKS_PAGE_SIZE, } @@ -107,12 +115,46 @@ def count_primary_topics(works): return topics_sorted[:ANZAHL_TOP_TOPICS] +def reconstruct_abstract(inverted_index): + if not inverted_index: + return None + + position_to_word = {} + for word, positions in inverted_index.items(): + for position in positions: + position_to_word[position] = word + + words_in_order = [] + for position in sorted(position_to_word.keys()): + words_in_order.append(position_to_word[position]) + + return " ".join(words_in_order) + + +def build_papers(works): + papers = [] + for work in works: + name = work.get("title") or work.get("display_name") + abstract = reconstruct_abstract(work.get("abstract_inverted_index")) + + papers.append({ + "name": name, + "abstract": abstract, + "stats": { + "cited_by_count": work.get("cited_by_count"), + }, + }) + return papers + + def main(): if len(AUTHOR_OPEN_ALEXID) == 0: print("Keine Autoren-IDs gefunden. Abbruch!") raise SystemExit(1) - for author_id in AUTHOR_OPEN_ALEXID: + #for author_id in AUTHOR_OPEN_ALEXID: + for i in range(100): + author_id = AUTHOR_OPEN_ALEXID[i % len(AUTHOR_OPEN_ALEXID)] print(f"Rufe Daten für Autor: {author_id} ab...") display_name = fetch_author_display_name(author_id) if display_name is None: @@ -121,10 +163,12 @@ def main(): works = fetch_author_works(author_id) top_topics = count_primary_topics(works) + papers = build_papers(works) author_data = { "display_name": display_name, "topics": top_topics, + "papers": papers, } print(f"Schreibe Daten für Autor: {display_name}...")