Coverage for src / wiktextract / extractor / th / tags.py: 75%
26 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-02 00:27 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-02 00:27 +0000
1from .models import WordEntry
3EXAMPLE_TAGS = {
4 # แม่แบบ:zh-x, มอดูล:zh-usex/data
5 "MSC": "Modern-Standard-Chinese",
6 "Pinyin": "Pinyin",
7 "trad.": "Traditional-Chinese",
8 "simp.": "Simplified-Chinese",
9}
11TRANSLATION_TAGS = {
12 # แม่แบบ:t
13 # https://th.wiktionary.org/wiki/มอดูล:gender_and_number/data
14 "ญ.": "feminine",
15 "ช.": "masculine",
16 "ก.": "neuter",
17 "ร.": "common",
18 "ชีว.": "animate",
19 "อชีว.": "inanimate",
20 "สัต.": "animal-not-person",
21 "บุค.": "personal",
22 "อบุค.": "impersonal",
23 "เอก.": "singular",
24 "ทวิ.": "dual",
25 "พหู.": "plural",
26 "ไม่สมบูรณ์": "imperfective",
27 "สมบูรณ์": "perfective",
28}
30SOUND_TAGS = {
31 # Template:th-pron
32 "การแผลงเป็น": "romanization",
33 "อักษรโรมัน": "romanization",
34 "ไพบูลย์พับบลิชชิง": "Paiboon",
35 "ราชบัณฑิตยสภา": "Royal-Institute",
36 "การแบ่งพยางค์": "phoneme",
37 "US": "US",
38 "UK": "UK",
39 "เสียงสมาส": "compound",
40 "ไม่ตามอักขรวิธี": "unorthographical",
41 "เสียงสระสั้น": "short",
42 # Template:zh-pron
43 "จีนกลาง": "Mandarin",
44 "มาตรฐาน": "Standard",
45 "พินอิน": "Pinyin",
46 "จู้อิน": "Bopomofo",
47 "Xi'an": "Xi'an",
48 "Guanzhong Pinyin": ["Guanzhong", "Pinyin"],
49 "ดุงกาน": "Dungan",
50 "Cyrillic": "Cyrillic",
51 "Wiktionary": "Wiktionary-specific",
52 "กวางตุ้ง": "Cantonese",
53 "Jyutping": "Jyutping",
54 "PFS": "Phak-fa-su",
55 "หมิ่นเหนือ": "Min-Bei",
56 "KCR": "Kienning-Colloquial-Romanized",
57 "หมิ่นตะวันออก": "Min-Dong",
58 "BUC": "Foochow-Romanized",
59 "หมิ่นใต้": "Min-Nan",
60 "ฮกเกี้ยน": "Hokkien",
61 "POJ": "POJ",
62 "แต้จิ๋ว": "Teochew",
63 "Peng'im": "Peng'im",
64 "จีนมาตรฐาน": "Standard-Chinese",
65 "ทงย่งพินอิน": "Tongyong-Pinyin",
66 "เวด-ไจลส์": "Wade–Giles",
67 "เยล": "Yale",
68 "กั๋วยฺหวี่หลัวหม่าจื้อ": "Gwoyeu-Romatsyh",
69 "พัลลาดีอุส": "Palladius",
70 "สัทอักษรสากลจีนวิทยา": "Sinological-IPA",
71 "กวางตุ้งมาตรฐาน": "Standard-Cantonese",
72 "กว่างโจว–ฮ่องกง": ["Guangzhou", "Hong Kong"],
73 "ยฺหวืดเพ็ง": "Jyutping",
74 "เพ็งยั้ม": ["Cantonese", "Pinyin"],
75 "อักษรโรมันมณฑลกวางตุ้ง": "Guangdong-Romanization",
76 "Pha̍k-fa-sṳ": "Phak-fa-su",
77 "Kienning Colloquial Romanized": "Kienning-Colloquial-Romanized",
78 "Pe̍h-ōe-jī": "POJ",
79 "Tâi-lô": "Tai-lo",
80 "Phofsit Daibuun": "Phofsit-Daibuun",
81 "เสฉวน": "Sichuan",
82 "เฉิงตู": "Chengdu",
83 "Sichuanese Pinyin": ["Sichuanese", "Pinyin"],
84 "Scuanxua Ladinxua Xin Wenz": "Latinxua-Sin-Wenz",
85 "Pe̍h-ōe-jī-like": "POJ",
86 "อู๋": "Wu",
87 "เซียง": "Xiang",
88 "Wiktionary Romanisation": ["Wiktionary-specific", "romanization"],
89 # Template:vi-ipa
90 "ฮานอย": "Hà-Nội",
91 "เว้": "Huế",
92 "นครโฮจิมินห์": "Saigon",
93 # Template:hi-ipa
94 "เดลี": "Delhi",
95 # Template:sa-ipa
96 "พระเวท": "Vedic",
97 "สันสกฤตคลาสสิก": "Classical-Sanskrit",
98 # Template:ko-ipa
99 "มาตรฐานเกาหลีใต้": "SK-Standard",
100 "โซล": "Seoul",
101 "การแผลงเป็นอักษรโรมันฉบับปรับปรุง": ["revised", "romanization"],
102 "การแผลงเป็นอักษรโรมันฉบับปรับปรุง (การถอดอักษร)": [
103 "revised",
104 "romanization",
105 "transliteration",
106 ],
107 "ระบบแมกคูน-ไรซ์ชาวเออร์": "McCune-Reischauer",
108 "ระบบเยล": ["Yale", "romanization"],
109}
111LABEL_TAGS = {
112 # https://th.wiktionary.org/wiki/มอดูล:labels/data
113 "คำย่อ": "abbreviation",
114 "อาการนาม": "abstract-noun",
115 "อักษรอ่านย่อ": "acronym",
116 "กรรตุวาจก": "active",
117 "สกรรม, อกรรม": "ambitransitive",
118 "มีชีวิต": "animate",
119 "บอกเล่า": "indicative",
120 "สมมุติ": "subjunctive",
121 "สั่ง": "imperative",
122 "คำกริยานุเคราะห์": "auxiliary",
123 "จำนวนเชิงการนับ": "cardinal",
124 "สมุหนาม": "collective",
125 "เพศรวม": "common",
126 "เปรียบเทียบได้": "comparable",
127 "เชื่อม": "copulative",
128 "นับได้": "countable",
129 "ทวิกรรม": "ditransitive",
130 "เพศหญิง": "feminine",
131 "สำนวน": "idiomatic",
132 "ไม่สมบูรณ์": "imperfective",
133 "คำอบุรุษกริยา": "impersonal",
134 "ในรูปเอกพจน์": "singular",
135 "ในรูปทวิพจน์": "dual",
136 "ในรูปพหูพจน์": "plural",
137 "ไม่มีชีวิต": "inanimate",
138 "ไม่ชี้เฉพาะ": "indefinite",
139 "อักษรย่อ": "initialism",
140 "อกรรม": "intransitive",
141 "สัทอักษรสากล": "IPA",
142 "เพศชาย": "masculine",
143 "เพศกลาง": "neuter",
144 "เปรียบเทียบไม่ได้": "not-comparable",
145 "เลียนเสียงธรรมชาติ": "onomatopoeic",
146 "จำนวนเชิงอันดับที่": "ordinal",
147 "พาร์ทิซิเพิล": "partitive",
148 "กรรมวาจก": "passive",
149 "สมบูรณ์": "perfect",
150 "พหูพจน์เท่านั้น": "plural-only",
151 "แสดงความเป็นเจ้าของ": "possessive",
152 "วลีภาคแสดง": "predicative",
153 "สะท้อน": "reflexive",
154 "เอกพจน์เท่านั้น": "singular-only",
155 "สภาว": "stative",
156 "สกรรม": "transitive",
157 "นับไม่ได้": "uncountable",
158 "โบราณ": "archaic",
159 "ภาษาเด็ก": "childish",
160 "ภาษาปาก": "colloquial",
161 "ล้าสมัย": "dated",
162 "นัยล้าสมัย": "dated",
163 "ดูหมิ่น": "derogatory",
164 "ภาษาถิ่น": "dialect",
165 "ในเชิงเปรียบเทียบ": "metaphoric",
166 "ทางการ": "formal",
167 "ขำขัน": "humorous",
168 "อติพจน์": "excessive",
169 "ไม่ทางการ": "informal",
170 "สแลงอินเทอร์เน็ต": ["Internet", "slang"],
171 "ไออาร์ซี": "IRC",
172 "ภาษาข่าว": "journalistic",
173 "ภาษาหนังสือ": "literary",
174 "คำสร้างใหม่": "neologism",
175 "ภาษาไม่มาตรฐาน": "nonstandard",
176 "เลิกใช้": "obsolete",
177 "ล่วงเกิน": "offensive",
178 "ร้อยกรอง": "poetic",
179 "สุภาพ": "polite",
180 "ไม่ควรใช้": "proscribed",
181 "พบได้ยาก": "rare",
182 # "ราชาศัพท์": "",
183 "สแลง": "slang",
184 # "ศัพท์เฉพาะ": "",
185 "หยาบคาย": "vulgar",
186 "กรีซโบราณ": "Ancient Greek",
187 "โรมโบราณ": "Ancient Rome",
188 "สะกดผิด": "misspelling",
189 # Template:zh-mw
190 # Module:zh/templates
191 "กั้น": "Gan",
192 "แคะ": "Hakka",
193 "จิ้น": "Jin",
194 # Template:ru-noun+
195 "ช.": "masculine",
196 "อชีว.": "inanimate",
197 "สัมพันธการก": "genitive",
198 "กรรตุการกพหูพจน์": ["nominative", "plural"],
199 "สัมพันธการกพหูพจน์": ["genitive", "plural"],
200 # Template:zh-forms
201 "ตัวเต็ม": "Traditional-Chinese",
202 "ตัวย่อ": "Simplified-Chinese",
203 "ตัวย่อรอบสอง": "Second-Round-Simplified-Chinese",
204 "รูปแบบอื่น": "alternative",
205 "obsolete": "obsolete",
206 # Template:zh-dial
207 "คลาสสิก": "Classical-Chinese",
208 "Written Vernacular Chinese": "Written-vernacular-Chinese",
209 "Written Standard Chinese": "Written-Standard-Chinese",
210 "จีนกลางตะวันออกเฉียงเหนือ": "Northeastern-Mandarin",
211 "จีนกลางแบบจี้หลู่": "Jilu-Mandarin",
212 "จีนกลางแบบเจียวเหลียว": "Jiaoliao-Mandarin",
213 "จีนกลาง": "Central-Plains-Mandarin",
214 "จีนกลางแบบหลันอิ๋น": "Lanyin-Mandarin",
215 "จีนกลางตะวันตกเฉียงใต้": "Southwestern-Mandarin",
216 "จีนกลางแบบเจียงหวย": "Jianghuai-Mandarin",
217 "ฮุ่ยโจว": "Huizhou",
218 "หมิ่นแบบผูเซียน": "Puxian-Min",
219 "หมิ่นตอนกลาง": "Central-Min",
220 "หมิ่นแบบจงซัน": "Zhongshan-Min",
221 "ผิงใต้": "Southern-Pinghua",
222 "ผิงเหนือ": "Northern-Pinghua",
223 # Template:en-noun
224 "พหูพจน์": "plural",
225 # Template:en-verb
226 "บุรุษที่สามเอกพจน์ปัจจุบันกาล": ["present", "singular", "third-person"],
227 "รูปกริยาขยายปัจจุบันกาล": ["participle", "present"],
228 "อดีตกาล": "past",
229 "รูปกริยาขยายอดีตกาล": ["participle", "past"],
230 "อดีตกาลและรูปกริยาขยายอดีตกาล": ["participle", "past"],
231 # Template:en-adj
232 "ขั้นกว่า": "comparative",
233 "ขั้นสุด": "superlative",
234 # Template:en-pron
235 "ตัวกำหนดเจ้าของ": ["determiner", "possessive"],
236 "สรรพนามเจ้าของ": ["possessive", "pronoun"],
237 "สะท้อนเอกพจน์": ["reflexive", "singular"],
238 "สะท้อนพหูพจน์": ["reflexive", "plural"],
239 # Template:eo-head
240 "กรรมการกเอกพจน์": ["accusative", "singular"],
241 "กรรมการกพหูพจน์": ["accusative", "plural"],
242 # Template:nl-noun
243 "ตัวบอกความเล็ก": "diminutive",
244 # Template:fr-noun
245 "เพศชายพหูพจน์": ["masculine", "plural"],
246 "เพศหญิงพหูพจน์": ["feminine", "plural"],
247 # Template:es-adj
248 "เพศชายและเพศหญิงพหูพจน์": ["masculine", "feminine", "plural"],
249 # มอดูล:Jpan-headword
250 "สกรรมหรืออกรรม": ["transitive", "intransitive"],
251 "ต้นเค้าศัพท์": "stem",
252 "โกดัง": "godan",
253 "อิจิดัง": "ichidan",
254 "ซูรุ": "suru",
255 "คูรุ": "kuru",
256 "-อิ": "-i",
257 "-นะ": "-na",
258 "โยดัง": "yodan",
259 "นิดัง": "nidan",
260 "-ริ": "-ri",
261 "-เซะ": "-se",
262 "-โกะ": "-ko",
263 "-ง": "-n",
264 "-นาริ": "-nari",
265 "-ตาริ": "-tari",
266 "-กุ": "-ku",
267 "-ชิกุ": "-shiku",
268 "-กะ": "-ka",
269 "adnominal": "adnominal",
270 "adverbial": "adverbial",
271 # Template:ko-noun
272 "ฮันกึล": "hangeul",
273 "ฮันจา": "hanja",
274 # Template:ja-kanjitab
275 "คีวจิไต": "kyūjitai",
276 # Template:hi-noun
277 "การสะกดภาษาอูรดู": "Urdu",
278 "เป็นทางการ": "formal",
279}
282TAGS = {**EXAMPLE_TAGS, **TRANSLATION_TAGS, **SOUND_TAGS, **LABEL_TAGS}
284TOPICS = {
285 # https://th.wiktionary.org/wiki/มอดูล:labels/data/topical
286 "การบัญชี": "accounting",
287 "สวนศาสตร์": "acoustics",
288 "อากาศยานศาสตร์": "aeronautics",
289 "เกษตรกรรม": "agriculture",
290 "อากาศยาน": "aircraft",
291 "การเล่นแร่แปรธาตุ": "alchemy",
292 "เครื่องดื่มแอลกอฮอล์": "alcohol",
293 "โรคพิษสุรา": "alcoholism",
294 "พีชคณิต": "algebra",
295 "เรขาคณิตเชิงพีชคณิต": "geometry",
296 "ทอพอโลยีเชิงพีชคณิต": "topology",
297 "แพทยศาสตร์ทางเลือก": "alternative-medicine",
298 "วิทยุสมัครเล่น": "radio",
299 "อเมริกันฟุตบอล": "football",
300 "เคมีวิเคราะห์": "chemistry",
301 "อนาธิปไตย": "anarchism",
302 "กายวิภาคศาสตร์": "anatomy",
303 "แอนิเมชัน": "anime",
304 "มานุษยวิทยา": "anthropology",
305 "วิทยาแมงมุม": "arachnology",
306 "โบราณคดี": "archaeology",
307 "การยิงธนู": "archery",
308 "สถาปัตยกรรม": "architecture",
309 "เลขคณิต": "arithmetic",
310 "ศิลปะ": "arts",
311 "ปัญญาประดิษฐ์": "AI",
312 "โหราศาสตร์": "astrology",
313 "อวกาศยานศาสตร์": "astronautics",
314 "ดาราศาสตร์": "astronomy",
315 "ฟิสิกส์ดาราศาสตร์": "astrophysics",
316 "กรีฑา": "athletics",
317 "ยานยนต์": "automotive",
318 "การบิน": "aviation",
319 "วิทยาแบคทีเรีย": "bacteria",
320 "แบดมินตัน": "badminton",
321 "กีฬาใช้บอล": "ball-games",
322 "การธนาคาร": "banking",
323 "เบสบอล": ["baseball", "ball-games"],
324 "บาสเกตบอล": ["basketball", "ball-games"],
325 "บีดีเอสเอ็ม": "BDSM",
326 "เบียร์": ["beer", "beverages"],
327 "ไบเบิล": ["biblical", "religion"],
328 "บิงโก": ["bingo", "games"],
329 "ชีวเคมี": "biochemistry",
330 "ชีววิทยา": "biology",
331 "เกมกระดาน": "board-games",
332 "พฤกษศาสตร์": "botany",
333 "มวย": ["boxing", "martial-arts"],
334 "ไบรโอโลยี": ["bryology", "botany"],
335 "ศาสนาพุทธ": ["Buddhism", "religion"],
336 "ธุรกิจ": "business",
337 "แคลคูลัส": ["calculus", "mathematics"],
338 "เกมไพ่": "card-games",
339 "หทัยวิทยา": ["cardiology", "medicine"],
340 "การทำแผนที่": ["cartography", "geography"],
341 # "ธาตุเคมี": "",
342 "เคมี": "chemistry",
343 "หมากรุกสากล": ["chess", "board-games"],
344 "ศาสนาคริสต์": "Christianity",
345 "การถ่ายภาพยนตร์": ["cinematography", "film"],
346 "ภาษาศาสตร์คอมพิวเตอร์": ["computing", "linguistics"],
347 "ภาษาคอมพิวเตอร์": "computing",
348 "วิทยาการคอมพิวเตอร์": "computing",
349 "การคอมพิวเตอร์": "computing",
350 "ศาสนาขงจื๊อ": "Confucianism",
351 "ตัจวิทยา": ["dermatology", "medicine"],
352 "เศรษฐศาสตร์": "economics",
353 "การศึกษา": "education",
354 "ไฟฟ้า": "electricity",
355 "แม่เหล็กไฟฟ้า": "electromagnetism",
356 "อิเล็กทรอนิกส์": ["electronics", "electricity"],
357 "จริยศาสตร์": ["ethics", "philosophy"],
358 "การออกกำลังกาย": ["exercise", "sports"],
359 "ภูมิศาสตร์": "geography",
360 "ธรณีวิทยา": "geology",
361 "เรขาคณิต": "geometry",
362 "กอล์ฟ": ["golf", "sports"],
363 "ไวยากรณ์": ["grammar", "linguistics"],
364 "ศาสนาฮินดู": ["Hinduism", "religion"],
365 "เทคโนโลยีสารสนเทศ": "computing",
366 "อินเทอร์เน็ต": "Internet",
367 "ศาสนาอิสลาม": "Islam",
368 "กฎหมาย": "law",
369 "ศัพทานุกรมศาสตร์": ["lexicography", "linguistics"],
370 "แอลจีบีที": "LGBT",
371 "ภาษาศาสตร์": "linguistics",
372 "วรรณกรรม": "literature",
373 "ตรรกศาสตร์": "logic",
374 "คณิตศาสตร์": "mathematics",
375 "แพทยศาสตร์": "medicine",
376 "อุตุนิยมวิทยา": "meteorology",
377 "การทหาร": "military",
378 "วิทยาแร่": "mineralogy",
379 "ราชาธิปไตย": "monarchy",
380 "ดนตรี": "music",
381 "นาโนเทคโนโลยี": ["nanotechnology", "engineering"],
382 "การเดินเรือ": "nautical",
383 "กษาปณวิทยา": ["numismatics", "hobbies"],
384 "โภชนาการ": "nutrition",
385 "ทัศนศาสตร์": "optics",
386 "พยาธิวิทยา": "pathology",
387 "เภสัชวิทยา": "pharmacology",
388 "ปรัชญา": "philosophy",
389 "สัทศาสตร์": "phonetics",
390 "สัทวิทยา": "phonology",
391 "คมีเชิงฟิสิกส์": "chemistry",
392 "ฟิสิกส์": "physics",
393 "สรีรวิทยา": "physiology",
394 "การเมือง": "politics",
395 "สื่อลามก": "pornography",
396 "การเขียนโปรแกรม": "programming",
397 "สัทสัมพันธ์": ["prosody", "phonology"],
398 "ศาสนา": "religion",
399 "วิทยาการหุ่นยนต์": ["robotics", "mechanical-engineering computing"],
400 "นิยายวิทยาศาสตร์": "science-fiction",
401 "วิทยาศาสตร์": "sciences",
402 "เพศวิถี": "sexuality",
403 # "การเดินเรือ": "",
404 "ซอกเกอร์": ["soccer", "ball-games"],
405 "สังคมศาสตร์": "social-science",
406 "ภาษาศาสตร์สังคม": ["sociolinguistics", "linguistics sociology"],
407 "สังคมวิทยา": "sociology",
408 "กีฬา": "sports",
409 "สถิติศาสตร์": "statistics",
410 "ศาสนาเต๋า": "Taoism",
411 "อนุกรมวิธาน": "taxonomy",
412 "เทคโนโลยี": "technology",
413 "ยูนิโคด": "Unicode",
414 "ผัก": ["vegetable", "food"],
415 "ไวน์": ["wine", "oenology"],
416 "สงครามโลกครั้งที่หนึ่ง": "World War I",
417 "สงครามโลกครั้งที่สอง": "World War II",
418 "พิษ": "poison",
419}
422def translate_raw_tags(data: WordEntry) -> None:
423 raw_tags = []
424 for raw_tag in data.raw_tags:
425 if raw_tag in TAGS and hasattr(data, "tags"):
426 tr_tag = TAGS[raw_tag]
427 if isinstance(tr_tag, str) and tr_tag not in data.tags:
428 data.tags.append(tr_tag)
429 elif isinstance(tr_tag, list):
430 for tag in tr_tag:
431 if tag not in data.tags: 431 ↛ 430line 431 didn't jump to line 430 because the condition on line 431 was always true
432 data.tags.append(tag)
433 elif raw_tag in TOPICS and hasattr(data, "topics"): 433 ↛ 434line 433 didn't jump to line 434 because the condition on line 433 was never true
434 topic = TOPICS[raw_tag]
435 if isinstance(topic, str):
436 data.topics.append(topic)
437 elif isinstance(topic, list):
438 data.topics.extend(topic)
439 else:
440 raw_tags.append(raw_tag)
441 data.raw_tags = raw_tags