From c7d47bb39ef0e0af26a6deeca66a326dccba5c50 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Wed, 29 May 2024 17:30:47 +0100 Subject: [PATCH] fix/none_type closes #26 --- __init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index b13105f..e450111 100644 --- a/__init__.py +++ b/__init__.py @@ -124,6 +124,7 @@ def register_from_file(cls): cls.register_infobox_intent(fn.split(".intent")[0], samples, lang) def get_infobox(self, query, context=None): + context = context or {} time_keys = ["died", "born"] data = self.extract_and_search(query, context) # handles translation # parse infobox @@ -147,12 +148,14 @@ def extract_and_search(self, query, context=None): """ extract search term from query and perform search """ + context = context or {} + # match the full query data = self.get_data(query, context) if data: return data - # extract the best keyword with some regexes or fallback to RAKE + # extract the best keyword lang = context.get("lang", "en-us") kw = self.extract_keyword(query, lang) return self.get_data(kw, context) @@ -172,6 +175,7 @@ def get_data(self, query: str, context: dict): return data def get_image(self, query, context=None): + context = context or {} data = self.extract_and_search(query, context) image = data.get("Image") or f"{os.path.dirname(__file__)}/logo.png" if image.startswith("/"): @@ -466,4 +470,4 @@ def stop_session(self, sess): # 'author (1942–2018)', # 'wikidata id': 'Q17714', # 'wikidata label': 'Stephen Hawking', - # 'youtube channel': 'UCPyd4mR0p8zHd8Z0HvHc0fw'} \ No newline at end of file + # 'youtube channel': 'UCPyd4mR0p8zHd8Z0HvHc0fw'}