spaCy/spacy/lang/ja/__init__.py

23 lines
639 B
Python
Raw Normal View History

2017-05-03 07:56:21 +03:00
# encoding: utf8
from __future__ import unicode_literals, print_function
2017-05-08 23:29:04 +03:00
from ...language import Language
from ...attrs import LANG
from ...tokens import Doc
2017-05-03 07:56:21 +03:00
class Japanese(Language):
lang = 'ja'
def make_doc(self, text):
try:
from janome.tokenizer import Tokenizer
except ImportError:
2017-05-03 10:44:38 +03:00
raise ImportError("The Japanese tokenizer requires the Janome library: "
"https://github.com/mocobeta/janome")
2017-05-03 07:56:21 +03:00
words = [x.surface for x in Tokenizer().tokenize(text)]
return Doc(self.vocab, words=words, spaces=[False]*len(words))
2017-05-03 12:07:29 +03:00
2017-05-08 16:50:46 +03:00
__all__ = ['Japanese']