Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/none_type #27

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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("/"):
Expand Down Expand Up @@ -466,4 +470,4 @@ def stop_session(self, sess):
# 'author (1942–2018)',
# 'wikidata id': 'Q17714',
# 'wikidata label': 'Stephen Hawking',
# 'youtube channel': 'UCPyd4mR0p8zHd8Z0HvHc0fw'}
# 'youtube channel': 'UCPyd4mR0p8zHd8Z0HvHc0fw'}
Loading