File manager - Edit - /usr/local/lib/python3.9/dist-packages/pythainlp/parse/spacy_thai_engine.py
Back
# -*- coding: utf-8 -*- """ spacy_thai: Tokenizer, POS tagger, and dependency parser for the Thai language using Universal Dependencies. GitHub: https://github.com/KoichiYasuoka/spacy-thai """ from typing import List, Union import spacy_thai class Parse: def __init__(self, model: str = "th") -> None: self.nlp = spacy_thai.load() def __call__( self, text: str, tag: str = "str" ) -> Union[List[List[str]], str]: doc = self.nlp(text) _text = [] if tag == "list": _tag_data = [] for t in doc: _tag_data.append( [ str(t.i + 1), t.orth_, t.lemma_, t.pos_, t.tag_, "_", str(0 if t.head == t else t.head.i + 1), t.dep_, "_", "_" if t.whitespace_ else "SpaceAfter=No", ] ) return _tag_data for t in doc: _text.append( "\t".join( [ str(t.i + 1), t.orth_, t.lemma_, t.pos_, t.tag_, "_", str(0 if t.head == t else t.head.i + 1), t.dep_, "_", "_" if t.whitespace_ else "SpaceAfter=No", ] ) ) return "\n".join(_text)
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.72 |
proxy
|
phpinfo
|
Settings