2017-03-16 16:13:08 +00:00
|
|
|
# coding: utf8
|
2017-04-15 10:05:47 +00:00
|
|
|
from __future__ import unicode_literals
|
2017-03-16 16:13:08 +00:00
|
|
|
|
2017-04-16 18:35:00 +00:00
|
|
|
from . import util
|
2017-03-17 17:47:05 +00:00
|
|
|
from .deprecated import resolve_model_name
|
2017-05-03 09:01:42 +00:00
|
|
|
import importlib
|
2017-03-28 12:10:20 +00:00
|
|
|
from .cli.info import info
|
2016-01-15 17:01:02 +00:00
|
|
|
|
2017-03-18 18:30:03 +00:00
|
|
|
|
2017-05-03 09:01:42 +00:00
|
|
|
_languages_name = set(["en", "de", "es", "pt", "fr",
|
|
|
|
"it", "hu", "zh", "nl", "sv",
|
|
|
|
"fi", "bn", "he", "nb"])
|
2017-01-31 22:27:29 +00:00
|
|
|
|
2016-03-25 17:54:45 +00:00
|
|
|
|
2016-10-18 17:23:31 +00:00
|
|
|
def load(name, **overrides):
|
2017-04-16 18:35:00 +00: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():
|
2017-04-16 20:16:47 +00:00
|
|
|
lang_name = util.get_lang_class(name).lang
|
2017-04-16 18:35:00 +00:00
|
|
|
model_path = None
|
|
|
|
util.print_msg(
|
2017-04-16 20:16:47 +00:00
|
|
|
"Only loading the '{}' tokenizer.".format(lang_name),
|
2017-04-16 18:35:00 +00:00
|
|
|
title="Warning: no model found for '{}'".format(name))
|
|
|
|
else:
|
|
|
|
model_path = util.ensure_path(overrides['path'])
|
|
|
|
data_path = model_path.parent
|
2017-04-16 20:15:51 +00:00
|
|
|
model_name = ''
|
2017-04-16 18:35:00 +00:00
|
|
|
meta = util.parse_package_meta(data_path, model_name, require=False)
|
2017-03-16 23:30:02 +00:00
|
|
|
lang = meta['lang'] if meta and 'lang' in meta else name
|
2017-05-03 09:01:42 +00:00
|
|
|
cls = importlib.import_module("."+lang, "spacy")
|
2017-03-16 16:13:08 +00:00
|
|
|
overrides['meta'] = meta
|
2017-04-16 18:35:00 +00:00
|
|
|
overrides['path'] = model_path
|
2017-05-03 09:01:42 +00:00
|
|
|
return cls.EXPORT(**overrides)
|