spaCy/spacy/lang/th/__init__.py

38 lines
1.0 KiB
Python
Raw Normal View History

2017-09-26 14:36:27 +00:00
# coding: utf8
from __future__ import unicode_literals
from .tokenizer_exceptions import TOKENIZER_EXCEPTIONS
from .tag_map import TAG_MAP
from .stop_words import STOP_WORDS
2017-09-26 15:41:20 +00:00
from ...tokens import Doc
2017-09-26 14:36:27 +00:00
from ...language import Language
from ...attrs import LANG
2017-09-26 14:36:27 +00:00
2017-10-11 00:22:49 +00:00
2017-09-26 14:36:27 +00:00
class ThaiDefaults(Language.Defaults):
lex_attr_getters = dict(Language.Defaults.lex_attr_getters)
lex_attr_getters[LANG] = lambda text: "th"
2017-10-11 00:22:49 +00:00
tokenizer_exceptions = dict(TOKENIZER_EXCEPTIONS)
tag_map = TAG_MAP
stop_words = STOP_WORDS
2017-09-26 14:36:27 +00:00
class Thai(Language):
lang = "th"
2017-10-11 00:22:49 +00:00
Defaults = ThaiDefaults
def make_doc(self, text):
try:
from pythainlp.tokenize import word_tokenize
except ImportError:
raise ImportError(
"The Thai tokenizer requires the PyThaiNLP library: "
"https://github.com/PyThaiNLP/pythainlp"
)
words = [x for x in list(word_tokenize(text, "newmm"))]
return Doc(self.vocab, words=words, spaces=[False] * len(words))
2017-10-11 00:22:49 +00:00
2017-09-26 14:36:27 +00:00
__all__ = ["Thai"]