2017-03-16 19:13:08 +03:00
|
|
|
# coding: utf8
|
2017-04-15 13:05:47 +03:00
|
|
|
from __future__ import unicode_literals
|
2017-03-16 19:13:08 +03:00
|
|
|
|
2017-04-16 21:35:00 +03:00
|
|
|
from . import util
|
2017-03-17 20:47:05 +03:00
|
|
|
from .deprecated import resolve_model_name
|
2017-03-22 12:02:14 +03:00
|
|
|
from .cli import info
|
2016-01-15 20:01:02 +03:00
|
|
|
|
2017-04-15 13:05:47 +03:00
|
|
|
from . import en, de, zh, es, it, hu, fr, pt, nl, sv, fi, bn, he
|
2017-03-18 21:30:03 +03:00
|
|
|
|
2017-03-15 19:33:57 +03:00
|
|
|
|
2017-04-16 21:35:00 +03:00
|
|
|
_languages = (en.English, de.German, es.Spanish, pt.Portuguese, fr.French,
|
|
|
|
it.Italian, hu.Hungarian, zh.Chinese, nl.Dutch, sv.Swedish,
|
|
|
|
fi.Finnish, bn.Bengali, he.Hebrew)
|
|
|
|
|
|
|
|
|
|
|
|
for _lang in _languages:
|
|
|
|
util.set_lang_class(_lang.lang, _lang)
|
2017-02-01 01:27:29 +03:00
|
|
|
|
2016-03-25 20:54:45 +03:00
|
|
|
|
2016-10-18 20:23:31 +03:00
|
|
|
def load(name, **overrides):
|
2017-04-16 21:35:00 +03:00
|
|
|
if overrides.get('path') in (None, False, True):
|
|
|
|
data_path = util.get_data_path()
|
|
|
|
model_name = resolve_model_name(name)
|
|
|
|
model_path = data_path / model_name
|
|
|
|
if not model_path.exists():
|
|
|
|
model_path = None
|
|
|
|
util.print_msg(
|
|
|
|
"Only loading the '{}' tokenizer.".format(name),
|
|
|
|
title="Warning: no model found for '{}'".format(name))
|
|
|
|
else:
|
|
|
|
model_path = util.ensure_path(overrides['path'])
|
|
|
|
data_path = model_path.parent
|
|
|
|
meta = util.parse_package_meta(data_path, model_name, require=False)
|
2017-03-17 02:30:02 +03:00
|
|
|
lang = meta['lang'] if meta and 'lang' in meta else name
|
2017-04-16 21:35:00 +03:00
|
|
|
cls = util.get_lang_class(lang)
|
2017-03-16 19:13:08 +03:00
|
|
|
overrides['meta'] = meta
|
2017-04-16 21:35:00 +03:00
|
|
|
overrides['path'] = model_path
|
2016-12-19 00:15:29 +03:00
|
|
|
return cls(**overrides)
|