Raise custom ImportError if importing janome fails

This commit is contained in:
Ines Montani 2017-05-03 09:43:29 +02:00 committed by GitHub
parent 949ad6594b
commit d730eb0c0d
1 changed files with 4 additions and 1 deletions

View File

@ -14,6 +14,9 @@ class Japanese(Language):
lang = 'ja'
def make_doc(self, text):
from janome.tokenizer import Tokenizer
try:
from janome.tokenizer import Tokenizer
except ImportError:
raise ImportError("The Japanese tokenizer requires the Janome library: https://github.com/mocobeta/janome")
words = [x.surface for x in Tokenizer().tokenize(text)]
return Doc(self.vocab, words=words, spaces=[False]*len(words))