55import warnings
66from typing import List , Tuple , Union
77
8+ from pythainlp .util .messages import deprecation_message
9+
810
911class NER :
1012 """
@@ -30,43 +32,53 @@ class NER:
3032
3133 **Note**: for tltk engine, It's support ner model from tltk only.
3234 """
35+
3336 def __init__ (self , engine : str , corpus : str = "thainer" ) -> None :
37+ if any ([arg .startswith ("lst20" ) for arg in (engine , corpus )]):
38+ dep_msg = deprecation_message (
39+ [("engine" , "lst20_onnx" ), ("corpus" , "lst20" )],
40+ "`named_entity.NER`" ,
41+ "4.0.0" ,
42+ )
43+ warnings .warn (dep_msg , DeprecationWarning , stacklevel = 2 )
3444 self .load_engine (engine = engine , corpus = corpus )
3545
3646 def load_engine (self , engine : str , corpus : str ) -> None :
3747 self .name_engine = engine
3848 self .engine = None
3949 if engine == "thainer" and corpus == "thainer" :
4050 from pythainlp .tag .thainer import ThaiNameTagger
51+
4152 self .engine = ThaiNameTagger ()
4253 elif engine == "lst20_onnx" :
4354 from pythainlp .tag .lst20_ner_onnx import LST20_NER_ONNX
55+
4456 self .engine = LST20_NER_ONNX ()
4557 elif engine == "wangchanberta" :
4658 from pythainlp .wangchanberta import ThaiNameTagger
47- if corpus == "lst20" :
48- warnings .warn ("""
59+
60+ if corpus == "lst20" :
61+ warnings .warn (
62+ """
4963 LST20 corpus are free for research and open source only.\n
5064 If you want to use in Commercial use, please contract NECTEC.\n
5165 https://www.facebook.com/dancearmy/posts/10157641945708284
52- """ )
66+ """
67+ )
5368 self .engine = ThaiNameTagger (dataset_name = corpus )
5469 elif engine == "tltk" :
5570 from pythainlp .tag import tltk
71+
5672 self .engine = tltk
5773 else :
5874 raise ValueError (
5975 "NER class not support {0} engine or {1} corpus." .format (
60- engine ,
61- corpus
76+ engine , corpus
6277 )
6378 )
6479
6580 def tag (
66- self ,
67- text ,
68- pos = True ,
69- tag = False
81+ self , text , pos = True , tag = False
7082 ) -> Union [List [Tuple [str , str ]], List [Tuple [str , str , str ]], str ]:
7183 """
7284 This function tags named-entitiy from text in IOB format.
@@ -103,7 +115,10 @@ def tag(
103115 """wangchanberta is not support part-of-speech tag.
104116 It have not part-of-speech tag in output."""
105117 )
106- if self .name_engine == "wangchanberta" or self .name_engine == "lst20_onnx" :
118+ if (
119+ self .name_engine == "wangchanberta"
120+ or self .name_engine == "lst20_onnx"
121+ ):
107122 return self .engine .get_ner (text , tag = tag )
108123 else :
109124 return self .engine .get_ner (text , tag = tag , pos = pos )
@@ -119,11 +134,13 @@ class NNER:
119134 **Options for engine**
120135 * *thai_nner* - Thai NER engine
121136 """
137+
122138 def __init__ (self , engine : str = "thai_nner" ) -> None :
123139 self .load_engine (engine )
124140
125141 def load_engine (self , engine : str = "thai_nner" ) -> None :
126142 from pythainlp .tag .thai_nner import Thai_NNER
143+
127144 self .engine = Thai_NNER ()
128145
129146 def tag (self , text ) -> Tuple [List [str ], List [dict ]]:
0 commit comments