55from pythainlp .tag import perceptron , pos_tag , pos_tag_sents , unigram
66from pythainlp .tag .locations import tag_provinces
77from pythainlp .tag .named_entity import ThaiNameTagger
8- from pythainlp .tokenize import (
9- word_tokenize ,
10- )
118
129
1310class TestTagPackage (unittest .TestCase ):
14-
1511 def test_pos_tag (self ):
1612 tokens = ["ผม" , "รัก" , "คุณ" ]
1713
@@ -29,7 +25,7 @@ def test_pos_tag(self):
2925 self .assertIsNotNone (pos_tag (tokens , engine = "unigram" , corpus = "pud" ))
3026 self .assertIsNotNone (pos_tag (["" ], engine = "unigram" , corpus = "pud" ))
3127 self .assertEqual (
32- pos_tag (word_tokenize ( "คุณกำลังประชุม" ) , engine = "unigram" ),
28+ pos_tag ([ "คุณ" , "กำลัง" , "ประชุม" ] , engine = "unigram" ),
3329 [("คุณ" , "PPRS" ), ("กำลัง" , "XVBM" ), ("ประชุม" , "VACT" )],
3430 )
3531
@@ -43,6 +39,10 @@ def test_pos_tag(self):
4339 self .assertEqual (perceptron .tag ([], corpus = "pud" ), [])
4440 self .assertEqual (perceptron .tag (None , corpus = "orchid" ), [])
4541 self .assertEqual (perceptron .tag ([], corpus = "orchid" ), [])
42+ self .assertEqual (
43+ pos_tag (["นักเรียน" , "ถาม" , "ครู" ]),
44+ [("นักเรียน" , "NCMN" ), ("ถาม" , "VACT" ), ("ครู" , "NCMN" )],
45+ )
4646
4747 self .assertEqual (pos_tag_sents (None ), [])
4848 self .assertEqual (pos_tag_sents ([]), [])
@@ -81,108 +81,102 @@ def test_ner(self):
8181 """คณะวิทยาศาสตร์ประยุกต์และวิศวกรรมศาสตร์ มหาวิทยาลัยขอนแก่น
8282 วิทยาเขตหนองคาย 112 หมู่ 7 บ้านหนองเดิ่น ตำบลหนองกอมเกาะ อำเภอเมือง
8383 จังหวัดหนองคาย 43000""" ,
84- tag = True
84+ tag = True ,
8585 )
8686 )
8787
8888 # arguement `tag` is True
8989 self .assertEqual (
90- ner .get_ner (
91- "วันที่ 15 ก.ย. 61 ทดสอบระบบเวลา 14:49 น." ,
92- tag = True
93- ),
90+ ner .get_ner ("วันที่ 15 ก.ย. 61 ทดสอบระบบเวลา 14:49 น." , tag = True ),
9491 "วันที่ <DATE>15 ก.ย. 61</DATE> "
95- "ทดสอบระบบเวลา <TIME>14:49 น.</TIME>" )
92+ "ทดสอบระบบเวลา <TIME>14:49 น.</TIME>" ,
93+ )
9694
9795 self .assertEqual (
9896 ner .get_ner (
99- "url = https://thainlp.org/pythainlp/docs/2.0/" ,
100- tag = True
97+ "url = https://thainlp.org/pythainlp/docs/2.0/" , tag = True
10198 ),
102- "url = <URL>https://thainlp.org/pythainlp/docs/2.0/</URL>" )
99+ "url = <URL>https://thainlp.org/pythainlp/docs/2.0/</URL>" ,
100+ )
103101
104102 self .assertEqual (
105- ner .get_ner (
106- "example@gmail.com" ,
107- tag = True
108- ),
109- "<EMAIL>example@gmail.com</EMAIL>" )
103+ ner .get_ner ("example@gmail.com" , tag = True ),
104+ "<EMAIL>example@gmail.com</EMAIL>" ,
105+ )
110106
111107 self .assertEqual (
112- ner .get_ner (
113- "รหัสไปรษณีย์ 19130" ,
114- tag = True
115- ),
116- "รหัสไปรษณีย์ <ZIP>19130</ZIP>" )
108+ ner .get_ner ("รหัสไปรษณีย์ 19130" , tag = True ),
109+ "รหัสไปรษณีย์ <ZIP>19130</ZIP>" ,
110+ )
117111
118112 self .assertEqual (
119- ner .get_ner (
120- "เบอร์โทรศัพท์ 091-123-4567" ,
121- tag = True
122- ),
123- "เบอร์โทรศัพท์ <PHONE>091-123-4567</PHONE>" )
113+ ner .get_ner ("เบอร์โทรศัพท์ 091-123-4567" , tag = True ),
114+ "เบอร์โทรศัพท์ <PHONE>091-123-4567</PHONE>" ,
115+ )
124116
125117 self .assertEqual (
126- ner .get_ner (
127- "อาจารย์เอกพล ประจำคณะวิศวกรรมศาสตร์ " ,
128- tag = True
129- ),
118+ ner .get_ner ("อาจารย์เอกพล ประจำคณะวิศวกรรมศาสตร์ " , tag = True ),
130119 "<PERSON>อาจารย์เอกพล</PERSON> ประจำ<ORGANIZATION>"
131- "คณะวิศวกรรมศาสตร์</ORGANIZATION> " )
120+ "คณะวิศวกรรมศาสตร์</ORGANIZATION> " ,
121+ )
132122
133123 self .assertEqual (
134124 ner .get_ner (
135125 "มาตรา 80 ปพพ ให้ใช้อัตราภาษีร้อยละ 10.0"
136126 " ในการคำนวณภาษีมูลค่าเพิ่ม" ,
137- tag = True
127+ tag = True ,
138128 ),
139129 "<LAW>มาตรา 80 ปพพ</LAW> "
140130 "ให้ใช้อัตราภาษี<PERCENT>ร้อยละ 10.0</PERCENT>"
141- " ในการคำนวณภาษีมูลค่าเพิ่ม" )
131+ " ในการคำนวณภาษีมูลค่าเพิ่ม" ,
132+ )
142133
143134 self .assertEqual (
144- ner .get_ner (
145- "ยาว 20 เซนติเมตร" ,
146- tag = True
147- ),
148- "ยาว <LEN>20 เซนติเมตร</LEN>" )
135+ ner .get_ner ("ยาว 20 เซนติเมตร" , tag = True ),
136+ "ยาว <LEN>20 เซนติเมตร</LEN>" ,
137+ )
149138
150139 self .assertEqual (
151- ner .get_ner (
152- "1 บาท" ,
153- pos = True ,
154- tag = True ),
155- "<MONEY>1 บาท</MONEY>" )
140+ ner .get_ner ("1 บาท" , pos = True , tag = True ), "<MONEY>1 บาท</MONEY>"
141+ )
156142
157143 self .assertEqual (
158- ner .get_ner (
159- "ไทย" ,
160- pos = False ,
161- tag = True
162- ),
163- "<LOCATION>ไทย</LOCATION>" )
144+ ner .get_ner ("ไทย" , pos = False , tag = True ), "<LOCATION>ไทย</LOCATION>"
145+ )
164146
165147 # arguement `tag` is False and `pos` is True
166148 self .assertEqual (
167- ner .get_ner (
168- "ไทย" ,
169- pos = True ,
170- tag = False
171- ),
172- [('ไทย' , 'PROPN' , 'B-LOCATION' )])
149+ ner .get_ner ("ไทย" , pos = True , tag = False ),
150+ [("ไทย" , "PROPN" , "B-LOCATION" )],
151+ )
173152
174153 # arguement `tag` is False and `pos` is False
175154 self .assertEqual (
176155 ner .get_ner (
177156 "วันที่ 15 ก.ย. 61 ทดสอบระบบเวลา 14:49 น." ,
178157 pos = False ,
179- tag = False
158+ tag = False ,
180159 ),
181- [('วันที่' , 'O' ), (' ' , 'O' ), ('15' , 'B-DATE' ),
182- (' ' , 'I-DATE' ), ('ก.ย.' , 'I-DATE' ), (' ' , 'I-DATE' ),
183- ('61' , 'I-DATE' ), (' ' , 'O' ), ('ทดสอบ' , 'O' ), ('ระบบ' , 'O' ),
184- ('เวลา' , 'O' ), (' ' , 'O' ), ('14' , 'B-TIME' ), (':' , 'I-TIME' ),
185- ('49' , 'I-TIME' ), (' ' , 'I-TIME' ), ('น.' , 'I-TIME' )])
160+ [
161+ ("วันที่" , "O" ),
162+ (" " , "O" ),
163+ ("15" , "B-DATE" ),
164+ (" " , "I-DATE" ),
165+ ("ก.ย." , "I-DATE" ),
166+ (" " , "I-DATE" ),
167+ ("61" , "I-DATE" ),
168+ (" " , "O" ),
169+ ("ทดสอบ" , "O" ),
170+ ("ระบบ" , "O" ),
171+ ("เวลา" , "O" ),
172+ (" " , "O" ),
173+ ("14" , "B-TIME" ),
174+ (":" , "I-TIME" ),
175+ ("49" , "I-TIME" ),
176+ (" " , "I-TIME" ),
177+ ("น." , "I-TIME" ),
178+ ],
179+ )
186180
187181 # self.assertEqual(
188182 # ner.get_ner("แมวทำอะไรตอนห้าโมงเช้า"),
0 commit comments