From eea3b35e3fedb87123e7f65ef22e8e7974e0c12e Mon Sep 17 00:00:00 2001 From: ines Date: Thu, 16 Mar 2017 17:13:08 +0100 Subject: [PATCH] Update model loading to support links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.) --- spacy/__init__.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/spacy/__init__.py b/spacy/__init__.py index dfdc4a198..52ebf0635 100644 --- a/spacy/__init__.py +++ b/spacy/__init__.py @@ -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)