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

Fixed errors related with spacy models not found #2220

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions chatterbot/comparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ def __init__(self, language):
)
raise OptionalDependencyImportError(message)

self.nlp = spacy.load(self.language.ISO_639_1)
if hasattr(language, 'SPACY_MODEL'):
self.nlp = spacy.load(self.language.SPACY_MODEL)
else:
self.nlp = spacy.load(self.language.ISO_639_1.lower())

def compare(self, statement_a, statement_b):
"""
Expand Down Expand Up @@ -127,7 +130,10 @@ def __init__(self, language):
)
raise OptionalDependencyImportError(message)

self.nlp = spacy.load(self.language.ISO_639_1)
if hasattr(language, 'SPACY_MODEL'):
self.nlp = spacy.load(self.language.SPACY_MODEL)
else:
self.nlp = spacy.load(self.language.ISO_639_1.lower())

def compare(self, statement_a, statement_b):
"""
Expand Down
20 changes: 20 additions & 0 deletions chatterbot/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ACH:
ISO_639_1 = ''
ISO_639 = 'ach'
ENGLISH_NAME = 'Acoli'
SPACY_MODEL = ''


class ADA:
Expand All @@ -38,6 +39,7 @@ class AFH:
ISO_639_1 = ''
ISO_639 = 'afh'
ENGLISH_NAME = 'Afrihili'
SPACY_MODEL = ''


class AFR:
Expand Down Expand Up @@ -326,6 +328,7 @@ class CAT:
ISO_639_1 = ''
ISO_639 = 'cat'
ENGLISH_NAME = 'Catalan'
SPACY_MODEL = 'ca_core_news_sm'


class CEB:
Expand Down Expand Up @@ -362,6 +365,7 @@ class CHI:
ISO_639_1 = 'zh'
ISO_639 = 'chi'
ENGLISH_NAME = 'Chinese'
SPACY_MODEL = 'zh_core_web_sm'


class CHK:
Expand Down Expand Up @@ -494,6 +498,7 @@ class DAN:
ISO_639_1 = ''
ISO_639 = 'dan'
ENGLISH_NAME = 'Danish'
SPACY_MODEL = 'da_core_news_sm'


class DAR:
Expand Down Expand Up @@ -548,6 +553,7 @@ class DUT:
ISO_639_1 = 'nl'
ISO_639 = 'dut'
ENGLISH_NAME = 'Dutch'
SPACY_MODEL = 'nl_core_news_sm'


class DYU:
Expand Down Expand Up @@ -584,6 +590,7 @@ class ENG:
ISO_639_1 = 'en'
ISO_639 = 'eng'
ENGLISH_NAME = 'English'
SPACY_MODEL = 'en_core_web_sm'


class EPO:
Expand Down Expand Up @@ -656,6 +663,7 @@ class FRE:
ISO_639_1 = ''
ISO_639 = 'fre'
ENGLISH_NAME = 'French'
SPACY_MODEL = 'fr_core_news_sm'


class FRR:
Expand Down Expand Up @@ -716,6 +724,7 @@ class GER:
ISO_639_1 = 'de'
ISO_639 = 'ger'
ENGLISH_NAME = 'German'
SPACY_MODEL = 'de_core_news_sm'


class GEZ:
Expand Down Expand Up @@ -782,6 +791,7 @@ class GRE:
ISO_639_1 = 'el'
ISO_639 = 'gre'
ENGLISH_NAME = 'Greek'
SPACY_MODEL = 'el_core_news_sm'


class GRN:
Expand Down Expand Up @@ -974,6 +984,7 @@ class ITA:
ISO_639_1 = ''
ISO_639 = 'ita'
ENGLISH_NAME = 'Italian'
SPACY_MODEL = 'it_core_news_sm'


class JAV:
Expand All @@ -992,6 +1003,7 @@ class JPN:
ISO_639_1 = 'ja'
ISO_639 = 'jpn'
ENGLISH_NAME = 'Japanese'
SPACY_MODEL = 'ja_core_news_sm'


class JPR:
Expand Down Expand Up @@ -1250,6 +1262,7 @@ class LIT:
ISO_639_1 = ''
ISO_639 = 'lit'
ENGLISH_NAME = 'Lithuanian'
SPACY_MODEL = 'lt_core_news_sm'


class LOL:
Expand Down Expand Up @@ -1316,6 +1329,7 @@ class MAC:
ISO_639_1 = ''
ISO_639 = 'mac'
ENGLISH_NAME = 'Macedonian'
SPACY_MODEL = 'mk_core_news_sm'


class MAD:
Expand Down Expand Up @@ -1544,6 +1558,7 @@ class NNO:
ISO_639_1 = ''
ISO_639 = 'nno'
ENGLISH_NAME = 'NorwegianNynorsk'
SPACY_MODEL = 'nb_core_news_sm'


class NOB:
Expand Down Expand Up @@ -1694,6 +1709,7 @@ class POL:
ISO_639_1 = ''
ISO_639 = 'pol'
ENGLISH_NAME = 'Polish'
SPACY_MODEL = 'pl_core_news_sm'


class PON:
Expand All @@ -1706,6 +1722,7 @@ class POR:
ISO_639_1 = 'pt'
ISO_639 = 'por'
ENGLISH_NAME = 'Portuguese'
SPACY_MODEL = 'pt_core_news_sm'


class PUS:
Expand Down Expand Up @@ -1754,6 +1771,7 @@ class RUM:
ISO_639_1 = ''
ISO_639 = 'rum'
ENGLISH_NAME = 'Romanian'
SPACY_MODEL = 'ro_core_news_sm'


class RUN:
Expand All @@ -1772,6 +1790,7 @@ class RUS:
ISO_639_1 = 'ru'
ISO_639 = 'rus'
ENGLISH_NAME = 'Russian'
SPACY_MODEL = 'ru_core_news_sm'


class SAD:
Expand Down Expand Up @@ -1940,6 +1959,7 @@ class SPA:
ISO_639_1 = 'es'
ISO_639 = 'spa'
ENGLISH_NAME = 'Spanish'
SPACY_MODEL = 'es_core_news_sm'


class SRD:
Expand Down
5 changes: 4 additions & 1 deletion chatterbot/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def __init__(self, language=None):

self.punctuation_table = str.maketrans(dict.fromkeys(string.punctuation))

self.nlp = spacy.load(self.language.ISO_639_1.lower())
if hasattr(language, 'SPACY_MODEL'):
self.nlp = spacy.load(self.language.SPACY_MODEL)
else:
self.nlp = spacy.load(self.language.ISO_639_1.lower())

def get_text_index_string(self, text):
"""
Expand Down