From 7aa31cf63e17efe194e501bc37068a2207ab8f38 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 25 Apr 2024 19:45:00 +0300 Subject: Pep8 formatting for response file. --- gn3/llms/response.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'gn3/llms/response.py') diff --git a/gn3/llms/response.py b/gn3/llms/response.py index 11cbd94..93320e9 100644 --- a/gn3/llms/response.py +++ b/gn3/llms/response.py @@ -1,11 +1,10 @@ # pylint: skip-file -import string import json import os -basedir = os.path.abspath(os.path.dirname(__file__)) +basedir = os.path.abspath(os.path.dirname(__file__)) class DocIDs(): @@ -26,21 +25,20 @@ class DocIDs(): 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'] + 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 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(): @@ -48,6 +46,7 @@ class DocIDs(): else: return doc_id + class RespContext(): def __init__(self, context): self.cntxt = context @@ -66,10 +65,9 @@ class RespContext(): 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 \ No newline at end of file + return result -- cgit v1.2.3 From 167706bb417627b1d9fcacb7cdcebeafe886c1ba Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 16 May 2024 13:17:18 +0300 Subject: Remove unused imports for llm.response file --- gn3/llms/response.py | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'gn3/llms/response.py') diff --git a/gn3/llms/response.py b/gn3/llms/response.py index 93320e9..7fce75b 100644 --- a/gn3/llms/response.py +++ b/gn3/llms/response.py @@ -45,29 +45,3 @@ class DocIDs(): 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 - 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 From 92ab53e9f0b10ebf7423626e37b3fe73eb8c0b65 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 16 May 2024 14:05:02 +0300 Subject: Refactor code for llm:response --- gn3/llms/response.py | 60 ++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'gn3/llms/response.py') diff --git a/gn3/llms/response.py b/gn3/llms/response.py index 7fce75b..2f00312 100644 --- a/gn3/llms/response.py +++ b/gn3/llms/response.py @@ -1,46 +1,42 @@ - -# pylint: skip-file +""" Module contains code for parsing references doc_ids """ +# pylint: disable=C0301 import json import os - basedir = os.path.abspath(os.path.dirname(__file__)) class DocIDs(): + """ Class Method to Parse document id and names""" 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): + """ + init method for Docids + * doc_ids.json: opens doc)ids for gn references + * sugar_doc_ids: open doci_ids for diabetes references + """ + self.doc_ids = self.load_file("doc_ids.json") + self.sugar_doc_ids = self.load_file("all_files.json") + self.format_doc_ids(self.sugar_doc_ids) + + def load_file(self, file_name): + """Method to load and read doc_id files""" 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 + with open(file_path, "rb") as file_handler: + return json.load(file_handler) 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): + raise FileNotFoundError(f"{file_path}-- FIle does not exist\n") + + def format_doc_ids(self, docs): + """method to format doc_ids for list items""" + for _key, val in docs.items(): + if isinstance(val, list): + for doc_obj in val: + doc_name = doc_obj["filename"].removesuffix(".pdf").removesuffix(".txt").replace("_", "") + self.doc_ids.update({doc_obj["id"]: doc_name}) + + def get_info(self, doc_id): + """ interface to make read from doc_ids""" if doc_id in self.doc_ids.keys(): return self.doc_ids[doc_id] else: -- cgit v1.2.3 From f911db6b69b16ac5df57b27d213fa88a4c848f50 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 16 May 2024 14:21:47 +0300 Subject: Delete response file * File is obsolete functionality move to process.py file --- gn3/llms/response.py | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 gn3/llms/response.py (limited to 'gn3/llms/response.py') diff --git a/gn3/llms/response.py b/gn3/llms/response.py deleted file mode 100644 index 2f00312..0000000 --- a/gn3/llms/response.py +++ /dev/null @@ -1,43 +0,0 @@ -""" Module contains code for parsing references doc_ids """ -# pylint: disable=C0301 -import json -import os - -basedir = os.path.abspath(os.path.dirname(__file__)) - - -class DocIDs(): - """ Class Method to Parse document id and names""" - def __init__(self): - """ - init method for Docids - * doc_ids.json: opens doc)ids for gn references - * sugar_doc_ids: open doci_ids for diabetes references - """ - self.doc_ids = self.load_file("doc_ids.json") - self.sugar_doc_ids = self.load_file("all_files.json") - self.format_doc_ids(self.sugar_doc_ids) - - def load_file(self, file_name): - """Method to load and read doc_id files""" - file_path = os.path.join(basedir, file_name) - if os.path.isfile(file_path): - with open(file_path, "rb") as file_handler: - return json.load(file_handler) - else: - raise FileNotFoundError(f"{file_path}-- FIle does not exist\n") - - def format_doc_ids(self, docs): - """method to format doc_ids for list items""" - for _key, val in docs.items(): - if isinstance(val, list): - for doc_obj in val: - doc_name = doc_obj["filename"].removesuffix(".pdf").removesuffix(".txt").replace("_", "") - self.doc_ids.update({doc_obj["id"]: doc_name}) - - def get_info(self, doc_id): - """ interface to make read from doc_ids""" - if doc_id in self.doc_ids.keys(): - return self.doc_ids[doc_id] - else: - return doc_id -- cgit v1.2.3