Update model loading to support links

Remove match_best_version check, fetch model language from meta instead
of directory name, and don't make too many assumptions – if model is
downloaded via downloader, version should match anyway. (Otherwise,
users should be free to add and load whichever models they want.)
This commit is contained in:
ines 2017-03-16 17:13:08 +01:00
parent 5f3f04bd0a
commit eea3b35e3f
1 changed files with 11 additions and 12 deletions

View File

@ -1,4 +1,9 @@
from .util import set_lang_class, get_lang_class
# coding: utf8
from __future__ import unicode_literals, print_function
import json
from pathlib import Path
from .util import set_lang_class, get_lang_class, parse_package_meta
from . import en
from . import de
@ -14,12 +19,6 @@ from . import fi
from . import bn
try:
basestring
except NameError:
basestring = str
set_lang_class(en.English.lang, en.English)
set_lang_class(de.German.lang, de.German)
set_lang_class(es.Spanish.lang, es.Spanish)
@ -34,11 +33,11 @@ set_lang_class(fi.Finnish.lang, fi.Finnish)
set_lang_class(bn.Bengali.lang, bn.Bengali)
def load(name, **overrides):
target_name, target_version = util.split_data_name(name)
data_path = overrides.get('path', util.get_data_path())
path = util.match_best_version(target_name, target_version, data_path)
cls = get_lang_class(target_name)
overrides['path'] = path
meta = parse_package_meta(data_path, name)
lang = meta['lang'] if meta and 'lang' in meta else 'en'
cls = get_lang_class(lang)
overrides['meta'] = meta
overrides['path'] = Path(data_path / name)
return cls(**overrides)