14
14
unigram ,
15
15
)
16
16
17
+ TEST_TOKENS = ["ผม" , "รัก" , "คุณ" ]
18
+
17
19
18
20
class TagTestCase (unittest .TestCase ):
19
- # ### pythainlp.tag.pos_tag
21
+ """Test pythainlp.tag.pos_tag"""
20
22
21
23
def test_pos_tag (self ):
22
- tokens = ["ผม" , "รัก" , "คุณ" ]
23
-
24
24
self .assertEqual (pos_tag (None ), [])
25
25
self .assertEqual (pos_tag ([]), [])
26
26
self .assertEqual (
@@ -40,25 +40,31 @@ def test_pos_tag(self):
40
40
self .assertEqual (unigram .tag (None , corpus = "tud" ), [])
41
41
self .assertEqual (unigram .tag ([], corpus = "tud" ), [])
42
42
self .assertIsNotNone (
43
- pos_tag (tokens , engine = "unigram" , corpus = "orchid" )
43
+ pos_tag (TEST_TOKENS , engine = "unigram" , corpus = "orchid" )
44
44
)
45
45
self .assertIsNotNone (
46
- pos_tag (tokens , engine = "unigram" , corpus = "orchid_ud" )
46
+ pos_tag (TEST_TOKENS , engine = "unigram" , corpus = "orchid_ud" )
47
+ )
48
+ self .assertIsNotNone (
49
+ pos_tag (TEST_TOKENS , engine = "unigram" , corpus = "pud" )
47
50
)
48
- self .assertIsNotNone (pos_tag (tokens , engine = "unigram" , corpus = "pud" ))
49
51
self .assertIsNotNone (pos_tag (["" ], engine = "unigram" , corpus = "pud" ))
50
52
self .assertIsNotNone (
51
- pos_tag (tokens , engine = "unigram" , corpus = "blackboard" )
53
+ pos_tag (TEST_TOKENS , engine = "unigram" , corpus = "blackboard" )
52
54
)
53
55
self .assertIsNotNone (
54
56
pos_tag (["" ], engine = "unigram" , corpus = "blackboard" )
55
57
)
56
58
self .assertIsNotNone (
57
59
pos_tag (["" ], engine = "unigram" , corpus = "blackboard_ud" )
58
60
)
59
- self .assertIsNotNone (pos_tag (tokens , engine = "unigram" , corpus = "tdtb" ))
61
+ self .assertIsNotNone (
62
+ pos_tag (TEST_TOKENS , engine = "unigram" , corpus = "tdtb" )
63
+ )
60
64
self .assertIsNotNone (pos_tag (["" ], engine = "unigram" , corpus = "tdtb" ))
61
- self .assertIsNotNone (pos_tag (tokens , engine = "unigram" , corpus = "tud" ))
65
+ self .assertIsNotNone (
66
+ pos_tag (TEST_TOKENS , engine = "unigram" , corpus = "tud" )
67
+ )
62
68
self .assertIsNotNone (pos_tag (["" ], engine = "unigram" , corpus = "tud" ))
63
69
self .assertEqual (
64
70
pos_tag (["คุณ" , "กำลัง" , "ประชุม" ], engine = "unigram" ),
@@ -72,6 +78,25 @@ def test_pos_tag(self):
72
78
pos_tag (["ความ" , "พอเพียง" ], corpus = "orchid_ud" )[0 ][1 ], "NOUN"
73
79
)
74
80
81
+ self .assertEqual (pos_tag_sents (None ), [])
82
+ self .assertEqual (pos_tag_sents ([]), [])
83
+ self .assertEqual (
84
+ pos_tag_sents ([["ผม" , "กิน" , "ข้าว" ], ["แมว" , "วิ่ง" ]]),
85
+ [
86
+ [("ผม" , "PPRS" ), ("กิน" , "VACT" ), ("ข้าว" , "NCMN" )],
87
+ [("แมว" , "NCMN" ), ("วิ่ง" , "VACT" )],
88
+ ],
89
+ )
90
+
91
+
92
+ class PerceptronTaggerTestCase (unittest .TestCase ):
93
+ """Test pythainlp.tag.PerceptronTagger
94
+
95
+ :param unittest: _description_
96
+ :type unittest: _type_
97
+ """
98
+
99
+ def test_perceptron_tagger (self ):
75
100
self .assertEqual (perceptron .tag (None , corpus = "orchid" ), [])
76
101
self .assertEqual (perceptron .tag ([], corpus = "orchid" ), [])
77
102
self .assertEqual (perceptron .tag (None , corpus = "orchid_ud" ), [])
@@ -82,44 +107,34 @@ def test_pos_tag(self):
82
107
self .assertEqual (perceptron .tag ([], corpus = "blackboard" ), [])
83
108
self .assertEqual (perceptron .tag (None , corpus = "tud" ), [])
84
109
self .assertEqual (perceptron .tag ([], corpus = "tud" ), [])
110
+
85
111
self .assertIsNotNone (
86
- pos_tag (tokens , engine = "perceptron" , corpus = "orchid" )
112
+ pos_tag (TEST_TOKENS , engine = "perceptron" , corpus = "orchid" )
87
113
)
88
114
self .assertIsNotNone (
89
- pos_tag (tokens , engine = "perceptron" , corpus = "orchid_ud" )
115
+ pos_tag (TEST_TOKENS , engine = "perceptron" , corpus = "orchid_ud" )
90
116
)
91
117
self .assertIsNotNone (
92
- pos_tag (tokens , engine = "perceptron" , corpus = "pud" )
118
+ pos_tag (TEST_TOKENS , engine = "perceptron" , corpus = "pud" )
93
119
)
94
120
self .assertIsNotNone (
95
- pos_tag (tokens , engine = "perceptron" , corpus = "blackboard" )
121
+ pos_tag (TEST_TOKENS , engine = "perceptron" , corpus = "blackboard" )
96
122
)
97
123
self .assertIsNotNone (
98
- pos_tag (tokens , engine = "perceptron" , corpus = "blackboard_ud" )
124
+ pos_tag (TEST_TOKENS , engine = "perceptron" , corpus = "blackboard_ud" )
99
125
)
100
126
self .assertIsNotNone (
101
- pos_tag (tokens , engine = "perceptron" , corpus = "tdtb" )
127
+ pos_tag (TEST_TOKENS , engine = "perceptron" , corpus = "tdtb" )
102
128
)
103
129
self .assertIsNotNone (
104
- pos_tag (tokens , engine = "perceptron" , corpus = "tdtb" )
130
+ pos_tag (TEST_TOKENS , engine = "perceptron" , corpus = "tdtb" )
105
131
)
106
132
self .assertIsNotNone (
107
- pos_tag (tokens , engine = "perceptron" , corpus = "tud" )
108
- )
109
-
110
- self .assertEqual (pos_tag_sents (None ), [])
111
- self .assertEqual (pos_tag_sents ([]), [])
112
- self .assertEqual (
113
- pos_tag_sents ([["ผม" , "กิน" , "ข้าว" ], ["แมว" , "วิ่ง" ]]),
114
- [
115
- [("ผม" , "PPRS" ), ("กิน" , "VACT" ), ("ข้าว" , "NCMN" )],
116
- [("แมว" , "NCMN" ), ("วิ่ง" , "VACT" )],
117
- ],
133
+ pos_tag (TEST_TOKENS , engine = "perceptron" , corpus = "tud" )
118
134
)
119
135
120
- # ### pythainlp.tag.PerceptronTagger
121
-
122
- def test_perceptron_tagger (self ):
136
+ def test_perceptron_tagger_custom (self ):
137
+ """Test pythainlp.tag.PerceptronTagger"""
123
138
tagger = PerceptronTagger ()
124
139
# train data, with "กิน" > 20 instances to trigger conditions
125
140
# in _make_tagdict()
@@ -182,7 +197,9 @@ def test_perceptron_tagger(self):
182
197
with self .assertRaises (IOError ):
183
198
tagger .load ("ptagger_notexistX4AcOcX.pkl" ) # file does not exist
184
199
185
- # ### pythainlp.tag.locations
200
+
201
+ class TagLocationsTestCase (unittest .TestCase ):
202
+ """Test pythainlp.tag.locations"""
186
203
187
204
def test_ner_locations (self ):
188
205
self .assertEqual (
0 commit comments