From cc9df10e69ba6c8efbf89c28899064ea3bbd0388 Mon Sep 17 00:00:00 2001 From: ines Date: Wed, 3 Jan 2018 20:13:25 +0100 Subject: [PATCH] Document util.set_lang_class (see #1737) --- website/api/_top-level/_util.jade | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/website/api/_top-level/_util.jade b/website/api/_top-level/_util.jade index ef12846ad..c5ca14db6 100644 --- a/website/api/_top-level/_util.jade +++ b/website/api/_top-level/_util.jade @@ -51,7 +51,9 @@ p p | Import and load a #[code Language] class. Allows lazy-loading | #[+a("/usage/adding-languages") language data] and importing - | languages using the two-letter language code. + | languages using the two-letter language code. To add a language code + | for a custom language class, you can use the + | #[+api("top-level#util.set_lang_class") #[code set_lang_class]] helper. +aside-code("Example"). for lang_id in ['en', 'de']: @@ -70,6 +72,33 @@ p +cell #[code Language] +cell Language class. ++h(3, "util.set_lang_class") util.set_lang_class + +tag function + +p + | Set a custom #[code Language] class name that can be loaded via + | #[+api("top-level#util.get_lang_class") #[code get_lang_class]]. If + | your model uses a custom language, this is required so that spaCy can + | load the correct class from the two-letter language code. + ++aside-code("Example"). + from spacy.lang.xy import CustomLanguage + + util.set_lang_class('xy', CustomLanguage) + lang_class = util.get_lang_class('xy') + nlp = lang_class() + ++table(["Name", "Type", "Description"]) + +row + +cell #[code name] + +cell unicode + +cell Two-letter language code, e.g. #[code 'en']. + + +row + +cell #[code cls] + +cell #[code Language] + +cell The language class, e.g. #[code English]. + +h(3, "util.load_model") util.load_model +tag function +tag-new(2)