File size: 1,208 Bytes
b238f43 8196617 b238f43 c417fef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import spacy
from spacy.language import Language
from pathlib import Path
from spacy.util import get_model_meta
model_path = Path(__file__).parent
meta = get_model_meta(model_path)
data_dir = f"{meta['lang']}_{meta['name']}-{meta['version']}"
components_path = model_path / data_dir / "training"
@Language.component("vocabulary")
def vocabulary(doc):
nlp_vocabulary = spacy.load(components_path/"vocabulary")
return nlp_vocabulary(doc)
@Language.component("articles")
def articles(doc):
nlp_articles = spacy.load(components_path/"articles")
return nlp_articles(doc)
@Language.component("punctuation")
def punctuation(doc):
nlp_punctuation = spacy.load(components_path/"punctuation")
return nlp_punctuation(doc)
@Language.component("spelling")
def spelling(doc):
nlp_spelling = spacy.load(components_path/"spelling")
return nlp_spelling(doc)
@Language.component("grammar_major")
def grammar_major(doc):
nlp_grammar_major = spacy.load(components_path/"grammar_major")
return nlp_grammar_major(doc)
@Language.component("grammar_minor")
def grammar_minor(doc):
nlp_grammar_minor = spacy.load(components_path/"grammar_minor")
return nlp_grammar_minor(doc)
|