From 3fa31b50af2861382fbe2c76406f5a04c3fefc93 Mon Sep 17 00:00:00 2001 From: SoloDShelby Date: Fri, 19 Jul 2024 14:41:40 +0300 Subject: Evaluation code for paper 1 --- gnqa/paper1_eval/src/apis/resp.py | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 gnqa/paper1_eval/src/apis/resp.py (limited to 'gnqa/paper1_eval/src/apis/resp.py') diff --git a/gnqa/paper1_eval/src/apis/resp.py b/gnqa/paper1_eval/src/apis/resp.py new file mode 100644 index 0000000..5d6ee24 --- /dev/null +++ b/gnqa/paper1_eval/src/apis/resp.py @@ -0,0 +1,75 @@ + +# pylint: skip-file +import string +import json +import os + + +basedir = os.path.abspath(os.path.dirname(__file__)) + + +class DocIDs(): + def __init__(self): + # open doc ids for GN refs + self.doc_ids = self.loadFile("doc_ids.json") + # open doc ids for Diabetes references + self.sugar_doc_ids = self.loadFile("all_files.json") + # format is not what I prefer, it needs to be rebuilt + self.formatDocIDs(self.sugar_doc_ids) + + def loadFile(self, file_name): + file_path = os.path.join(basedir, file_name) + if os.path.isfile(file_path): + f = open(file_path, "rb") + result = json.load(f) + f.close() + return result + else: + raise Exception("\n{0} -- File does not exist\n".format(file_path)) + + def formatDocIDs(self, values): + for _key, _val in values.items(): + if isinstance(_val, list): + for theObject in _val: + docName = self.formatDocumentName(theObject['filename']) + docID = theObject['id'] + self.doc_ids.update({docID: docName}) + + def formatDocumentName(self, val): + result = val.removesuffix('.pdf') + result = result.removesuffix('.txt') + result = result.replace('_', ' ') + return result + + + def getInfo(self, doc_id): + if doc_id in self.doc_ids.keys(): + return self.doc_ids[doc_id] + else: + return doc_id + +class RespContext(): + def __init__(self, context): + self.cntxt = context + self.theObj = {} + + def parseIntoObject(self, info): + # check for obj, arr, or val + for key, val in info.items(): + if isinstance(val, list): + self.parseIntoObject(val) + elif isinstance(val, str) or isinstance(val, int): + self.theObj[key] = val + self.theObj[key] = self.val + + +def createAccordionFromJson(theContext): + result = '' + # loop thru json array + ndx = 0 + for docID, summaryLst in theContext.items(): + # item is a key with a list + comboTxt = '' + for entry in summaryLst: + comboTxt += '\t' + entry['text'] + return result -- cgit v1.2.3