spaCy/spacy/__init__.py

54 lines
1.5 KiB
Python
Raw Normal View History

# 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 .deprecated import resolve_model_name
from . import en
from . import de
from . import zh
2016-11-02 22:05:14 +03:00
from . import es
from . import it
2016-12-21 22:45:36 +03:00
from . import hu
2016-11-02 22:48:29 +03:00
from . import fr
2016-11-02 22:05:14 +03:00
from . import pt
2016-11-24 18:39:49 +03:00
from . import nl
2016-12-20 13:05:06 +03:00
from . import sv
2017-02-01 01:27:29 +03:00
from . import fi
2017-02-28 04:48:37 +03:00
from . import bn
set_lang_class(en.English.lang, en.English)
set_lang_class(de.German.lang, de.German)
2016-11-02 22:05:14 +03:00
set_lang_class(es.Spanish.lang, es.Spanish)
set_lang_class(pt.Portuguese.lang, pt.Portuguese)
set_lang_class(fr.French.lang, fr.French)
set_lang_class(it.Italian.lang, it.Italian)
set_lang_class(hu.Hungarian.lang, hu.Hungarian)
set_lang_class(zh.Chinese.lang, zh.Chinese)
2016-11-29 18:42:05 +03:00
set_lang_class(nl.Dutch.lang, nl.Dutch)
2016-12-20 13:05:06 +03:00
set_lang_class(sv.Swedish.lang, sv.Swedish)
2017-02-01 01:27:29 +03:00
set_lang_class(fi.Finnish.lang, fi.Finnish)
2017-02-28 04:48:37 +03:00
set_lang_class(bn.Bengali.lang, bn.Bengali)
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):
data_path = overrides.get('path', util.get_data_path())
model_name = resolve_model_name(name)
2017-03-17 21:51:45 +03:00
meta = 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
cls = get_lang_class(lang)
overrides['meta'] = meta
2017-03-17 21:51:45 +03:00
model_path = Path(data_path / model_name)
2017-03-17 02:30:02 +03:00
if model_path.exists():
overrides['path'] = model_path
2017-03-17 21:51:45 +03:00
2016-12-19 00:15:29 +03:00
return cls(**overrides)
def info(name):
2017-03-17 02:30:02 +03:00
meta = parse_package_meta(util.get_data_path(), name, require=True)
print(json.dumps(meta, indent=2))