@@ -16,12 +16,15 @@ class NER:
1616 :param str corpus: corpus
1717
1818 **Options for engine**
19- * *thainer-v2 * - Thai NER engine v2.0 for Thai NER 2.0 (default)
19+ * *phayathaibert * - PhayaThaiBERT-based Thai NER engine
2020 * *thainer* - Thai NER engine
21+ * *thainer-v2* - Thai NER engine v2.0 for Thai NER 2.0 (default)
2122 * *tltk* - wrapper for `TLTK <https://pypi.org/project/tltk/>`_.
23+ * *wangchanberta* - WangchanBERTa-based Thai NER engine
2224
2325 **Options for corpus**
2426 * *thainer* - Thai NER corpus (default)
27+ * *thainer-v2* - Thai NER v2 corpus
2528
2629 **Note**: The tltk engine supports NER models from tltk only.
2730 """
@@ -34,29 +37,33 @@ def __init__(
3437 def load_engine (self , engine : str , corpus : str ) -> None :
3538 self .name_engine = engine
3639 self .engine : Any = None
37- if engine == "thainer" and corpus == "thainer" :
38- from pythainlp .tag .thainer import ThaiNameTagger
40+ if corpus == "thainer" :
41+ if engine == "thainer" :
42+ from pythainlp .tag .thainer import ThaiNameTagger
3943
40- self .engine = ThaiNameTagger ()
41- elif engine == "thainer-v2" and corpus == "thainer" :
42- from pythainlp .wangchanberta import NamedEntityRecognition
44+ self .engine = ThaiNameTagger ()
45+ elif engine == "thainer-v2 " :
46+ from pythainlp .wangchanberta import NamedEntityRecognition
4347
44- self .engine = NamedEntityRecognition (
45- model = "pythainlp/thainer-corpus-v2-base-model"
46- )
47- elif engine == "tltk" :
48- from pythainlp .tag import tltk
48+ self .engine = NamedEntityRecognition (
49+ model = "pythainlp/thainer-corpus-v2-base-model"
50+ )
51+ elif engine == "wangchanberta" :
52+ from pythainlp .wangchanberta import ThaiNameTagger as WangchanbertaThaiNameTagger # type: ignore[assignment] # noqa: I001,E501
53+
54+ self .engine = WangchanbertaThaiNameTagger (dataset_name = corpus ) # type: ignore[call-arg]
55+ elif corpus == "thainer-v2" :
56+ if engine == "phayathaibert" :
57+ from pythainlp .phayathaibert .core import NamedEntityTagger
4958
50- self .engine = tltk
51- elif engine == "wangchanberta" and corpus == "thainer" :
52- from pythainlp .wangchanberta import ThaiNameTagger # type: ignore[assignment] # noqa: I001
59+ self .engine = NamedEntityTagger ()
60+ else : # No corpus matched
61+ if engine == "tltk" :
62+ from pythainlp .tag import tltk
5363
54- self .engine = ThaiNameTagger (dataset_name = corpus ) # type: ignore[call-arg]
55- elif engine == "phayathaibert" and corpus == "thainer-v2" :
56- from pythainlp .phayathaibert .core import NamedEntityTagger
64+ self .engine = tltk
5765
58- self .engine = NamedEntityTagger ()
59- else :
66+ if self .engine is None :
6067 raise ValueError (
6168 f"NER class not support { engine } engine or { corpus } corpus."
6269 )
0 commit comments