spaCy/spacy/__init__.py

80 lines
2.3 KiB
Python
Raw Normal View History

# coding: utf8
from __future__ import unicode_literals
from . import util
from .deprecated import resolve_model_name
2017-03-28 12:10:20 +00:00
from .cli.info import info
<<<<<<< HEAD
2017-03-28 12:10:20 +00:00
from . import en, de, zh, es, it, hu, fr, pt, nl, sv, fi, bn, he, nb
2017-03-18 18:30:03 +00:00
_languages = (en.English, de.German, es.Spanish, pt.Portuguese, fr.French,
it.Italian, hu.Hungarian, zh.Chinese, nl.Dutch, sv.Swedish,
2017-03-28 12:10:20 +00:00
fi.Finnish, bn.Bengali, he.Hebrew, nb.Norwegian)
for _lang in _languages:
util.set_lang_class(_lang.lang, _lang)
2017-01-31 22:27:29 +00:00
2017-03-28 12:10:20 +00:00
from . import en
from . import de
from . import zh
from . import es
from . import it
from . import hu
from . import fr
from . import pt
from . import nl
from . import sv
from . import fi
from . import bn
from . import he
2017-03-28 12:10:20 +00:00
from . import nb
from .about import *
set_lang_class(en.English.lang, en.English)
set_lang_class(de.German.lang, de.German)
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)
set_lang_class(nl.Dutch.lang, nl.Dutch)
set_lang_class(sv.Swedish.lang, sv.Swedish)
set_lang_class(fi.Finnish.lang, fi.Finnish)
set_lang_class(bn.Bengali.lang, bn.Bengali)
set_lang_class(he.Hebrew.lang, he.Hebrew)
set_lang_class(nb.Norwegian.lang, nb.Norwegian)
2017-03-28 12:10:20 +00:00
2016-03-25 17:54:45 +00:00
2016-10-18 17:23:31 +00:00
def load(name, **overrides):
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():
lang_name = util.get_lang_class(name).lang
model_path = None
util.print_msg(
"Only loading the '{}' tokenizer.".format(lang_name),
title="Warning: no model found for '{}'".format(name))
else:
model_path = util.ensure_path(overrides['path'])
data_path = model_path.parent
model_name = ''
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
cls = util.get_lang_class(lang)
overrides['meta'] = meta
overrides['path'] = model_path
2016-12-18 21:15:29 +00:00
return cls(**overrides)
2017-03-28 12:10:20 +00:00
def info(name, markdown):
info(name, markdown)