Coverage for src / wiktextract / extractor / zh / tags.py: 98%
35 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-21 08:01 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-21 08:01 +0000
1from .models import WordEntry
2from .topics import LABEL_TOPICS
4GENDER_TAGS: dict[str, str] = {
5 "陰性": "feminine",
6 "阴性": "feminine",
7 "陰性形式": "feminine",
8 "陰性等價詞": "feminine",
9 "陽性": "masculine",
10 "陽性形式": "masculine",
11 "中性": "neuter",
12 "中性形式": "neuter",
13}
15NUMBER_TAGS: dict[str, str | list[str]] = {
16 "單數": "singular",
17 "单数": "singular",
18 "複數": "plural",
19 "复数": "plural",
20 "定單數": ["definite", "singular"],
21 "定单数": ["definite", "singular"],
22 "不定單數": ["indefinite", "singular"],
23 "不定单数": ["indefinite", "singular"],
24 "不定複數": ["indefinite", "plural"],
25 "不定复数": ["indefinite", "plural"],
26 "定複數": ["definite", "plural"],
27 "斜格複數": ["oblique", "plural"],
28 "主格單數": ["nominative", "singular"],
29 "主格複數": ["nominative", "plural"],
30 "屬格單數": ["genitive", "singular"],
31 "屬格複數": ["genitive", "plural"],
32 "陰性單數": ["feminine", "singular"],
33 "陽性單數": ["masculine", "singular"],
34 "陰性複數": ["feminine", "plural"],
35 "陽性複數": ["masculine", "plural"],
36 "中性複數": ["neuter", "plural"],
37 "中性單數": ["neuter", "singular"],
38 "賓格單數": ["accusative", "singular"],
39 "賓格複數": ["accusative", "plural"],
40 "無複數": "no-plural",
41}
43# https://en.wikipedia.org/wiki/Count_noun
44COUNT_TAGS: dict[str, str] = {
45 "可數": "countable",
46 "不可數": "uncountable",
47}
49OTHER_TAGS: dict[str, str] = {
50 "指小詞": "diminutive",
51 "指小": "diminutive",
52 "變格類型": "declension-pattern-of",
53 "屬格": "genitive",
54 "部分格": "partitive",
55 "個人": "person",
56 "無屈折": "indeclinable",
57 "諺文": "hangeul",
58 "漢字": "hanja",
59 # Template:cs-proper noun
60 "相關形容詞": ["relational", "adjective"],
61 "關係形容詞": ["relational", "adjective"],
62 "居民稱謂詞": "demonym",
63 "女性居民稱謂詞": ["feminine", "demonym"],
64 "定賓格": ["definite", "accusative"],
65 "定宾格": ["definite", "accusative"],
66 "拉丁字母拼寫": "romanization",
67 "定指賓格": ["definite", "accusative"],
68 "前元音和諧變體": "front-vowel-harmony",
69 # Template:zh-forms
70 "正體": "Standard-Chinese",
71 "繁體": "Traditional-Chinese",
72 "簡體": "Simplified-Chinese",
73 "異體": "alternative",
74 "仿譯詞": "calque",
75 "貶稱詞": "pejorative",
76}
78VERB_TAGS: dict[str, str] = {
79 "及物": "transitive",
80 "不及物": "intransitive",
81 "动宾结构": "verb-object",
82 "非完": "imperfective",
83 "完": "perfective",
84 "強變化": "strong",
85 "動名詞": "supine",
86 "命令式": "imperative",
87 # Template:ar-verb
88 "第I類": "form-i",
89 "第II類": "form-ii",
90 "第III類": "form-iii",
91 "第IV類": "form-iv",
92 "第V類": "form-v",
93 "第VI類": "form-vi",
94 "第VII類": "form-vii",
95 "第IX類": "form-ix",
96 "第X類": "form-x",
97 "第XII類": "form-xii",
98 "第XIII類": "form-xiii",
99 "第XIV類": "form-xiv",
100 "第XV類": "form-xv",
101 "第Iq類": "form-iq",
102 "第IIq類": "form-iiq",
103 "第IIIq類": "form-iiiq",
104 "第IVq類": "form-ivq",
105 # Module:Jpan-headword
106 "他動詞": "transitive",
107 "自動詞": "intransitive",
108 "自、他動詞": ["transitive", "intransitive"],
109 "五段": "godan",
110 "一段": "ichidan",
111 "サ行": "suru",
112 "カ行": "kuru",
113 "イ形": "-i",
114 "ナ形": "-na",
115 "四段": "yodan",
116 "二段": "nidan",
117 "ラ行": "-ri",
118 "ナリ": "-nari",
119 "タリ": "-tari",
120 # Template:ja-conj-bungo
121 "語幹形態": "stem",
122 "對比連接詞": ["contrastive", "conjunction"],
123 "因果連接詞": ["causative", "conjunction"],
124 "條件連接詞": ["conditional", "conjunction"],
125 "過去式 (第一手消息)": "past",
126 "過去式 (第二手消息)": "past",
127 "完成式 (自覺動作)": "perfect",
128 "完成式 (自然事件)": ["perfect", "natural"],
129 "完成進行式": ["perfect", "continuative"],
130 "意志形": "volitional",
131 "副詞": "adverbial",
132 "無助動詞": "no-auxiliary",
133 "有助動詞": "auxiliary",
134}
136# https://en.wikipedia.org/wiki/Japanese_grammar#Stem_forms
137JA_STEM_FORMS: dict[str, str] = {
138 "未然形": "imperfective",
139 "連用形": "continuative",
140 "終止形": "terminal",
141 "連體形": "attributive",
142 "連体形": "attributive",
143 "假定形": "hypothetical",
144 "仮定形": "hypothetical",
145 "命令形": "imperative",
146 "已然形": "realis",
147}
149# https://en.wikipedia.org/wiki/Voice_(grammar)
150VOICE_TAGS: dict[str, str | list[str]] = {
151 "被動形": "passive",
152 "使役形": "causative",
153 "可能形": "potential",
154 "意志形": "volitional",
155 "否定形": "negative",
156 "否定連用形": ["negative", "continuative"],
157 "尊敬形": "formal",
158 "完成形": "perfective",
159 "接續形": "conjunctive",
160 "條件形": ["hypothetical", "conditional"],
161}
163COMPARISON_TAGS: dict[str, str] = {
164 # https://en.wikipedia.org/wiki/Comparison_(grammar)
165 "原级": "positive",
166 "比較級": "comparative",
167 "最高級": "superlative",
168}
170TENSE_TAGS = {
171 "過去時": "preterite",
172 "過去式": "past",
173 "過去分詞": ["past", "participle"],
174 "現在時": "present",
175 "第三人稱單數現在時": ["third-person", "singular", "present"],
176 "助動詞": "auxiliary",
177 # Template:de-verb
178 "弱變化": "weak",
179 "弱变化": "weak",
180 "第三人稱單數簡單現在時": ["third-person", "singular", "present"],
181 "現在分詞": ["present", "participle"],
182 "一般過去時及過去分詞": ["past", "participle"],
183 # Template:it-verb
184 "第一人稱單數 現在時": ["first-person", "singular", "present"],
185 "第一人稱單數 先過去時": ["first-person", "singular", "past", "historic"],
186 # Template:de-adj
187 "強變化主格陽性單數": ["strong", "nominative", "masculine", "singular"],
188 # Template:la-verb
189 "现在时不定式": ["present", "infinitive"],
190 "完成时主动式": ["perfect", "active"],
191 "目的动名词": "supine",
192 # Template:ar-verb
193 "非過去時": "non-past",
194 "動詞性名詞": "noun-from-verb",
195 "主動分詞": ["active", "participle"],
196 "被動分詞": ["passive", "participle"],
197 # Template:it-verb
198 # https://zh.wiktionary.org/wiki/Module:It-headword
199 "第一人稱單數現在時": ["first-person", "singular", "present"],
200 "第一人稱單數先過去時": ["first-person", "singular", "past", "historic"],
201 "第三人稱單數先過去時": ["third-person", "singular", "past", "historic"],
202 "第一人稱單數過去分詞": ["first-person", "singular", "past", "participle"],
203 "第三人稱單數過去分詞": ["third-person", "singular", "past", "participle"],
204 "第一人稱單數未完成時": ["first-person", "singular", "imperfect"],
205 "第三人稱單數未完成時": ["third-person", "singular", "imperfect"],
206 "第一人稱單數未來時": ["first-person", "singular", "future"],
207 "第三人稱單數未來時": ["third-person", "singular", "future"],
208 "第一人稱單數現在時虛擬式": ["first-person", "singular", "subjunctive"],
209 "第三人稱單數現在時虛擬式": ["third-person", "singular", "subjunctive"],
210 "第一人稱單數未完成時虛擬式": [
211 "first-person",
212 "singular",
213 "imperfect",
214 "subjunctive",
215 ],
216 "第三人稱單數未完成時虛擬式": [
217 "third-person",
218 "singular",
219 "imperfect",
220 "subjunctive",
221 ],
222 # Template:es-verb
223 "第一人稱單數過去時": ["first-person", "singular", "past"],
224 # Template:ast-verb-ar
225 "第一人稱單數直陳現在時": [
226 "first-person",
227 "singular",
228 "indicative",
229 "present",
230 ],
231}
233GRAMMATICAL_TAGS: dict[str, str] = {
234 **GENDER_TAGS,
235 **NUMBER_TAGS,
236 **COUNT_TAGS,
237 **OTHER_TAGS,
238 **VERB_TAGS,
239 **JA_STEM_FORMS,
240 **VOICE_TAGS,
241 **COMPARISON_TAGS,
242 **TENSE_TAGS,
243}
245# https://zh.wiktionary.org/wiki/Template:Label
246# https://zh.wiktionary.org/wiki/Module:Labels/data
247# https://zh.wiktionary.org/wiki/Template:Qualifier
248# https://zh.wiktionary.org/wiki/Template:古
249# https://zh.wiktionary.org/wiki/Template:注释
250LABEL_TAGS = {
251 "棄用": "obsolete",
252 "弃用": "obsolete",
253 "比喻": "figuratively",
254 "古": "archaic",
255 "陽": "masculine",
256 "陰": "feminine",
257 "喻": "figuratively",
258 "書": "literary",
259 "口": "colloquial",
260 "俚": "slang",
261 "俗": "slang",
262 "方": "dialectal",
263 "废": "obsolete",
264 "貶": "derogatory",
265 "罕": "rare",
266 "引": "broadly",
267 "現已罕用": "archaic",
268 # Module:Labels/data
269 "back slang": "slang",
270 "synecdochically": "synecdoche",
271 "不再自由造詞": "idiomatic",
272 "不及物": "intransitive",
273 "不可數": "uncountable",
274 "不定": "indefinite",
275 "不常見": "uncommon",
276 "不推薦使用": "proscribed",
277 "中性": "neuter",
278 "中間被動語態": "mediopassive",
279 "中間語態": "middle",
280 "主動語態": "active",
281 "主要用於否定": ["usually", "with-negation"],
282 "交互": "reciprocal",
283 "以單數形式": "singular",
284 "以複數形式": "in-plural",
285 "作定語": "attributive",
286 "作格": "ergative",
287 "作表語": "predicative",
288 "使役": "causative",
289 "俗語": "idiomatic",
290 "俚語": "slang",
291 "俚语": "slang",
292 "兒童用語": "childish",
293 "公文": "bureaucratese",
294 "冒犯": "offensive",
295 "分詞": "participle",
296 "前古典": "pre-Classical",
297 "助動詞": "auxiliary",
298 "助記符": "mnemonic",
299 "及物": "transitive",
300 "反問句": "rhetoric",
301 "反身": "reflexive",
302 "口語": "colloquial",
303 "口语": "colloquial",
304 "古舊": "archaic",
305 "可數": "countable",
306 "同性戀俚語": ["slang", "LGBT"],
307 "名詞化": "noun-from-verb",
308 "唯單": "singular-only",
309 "唯複": "plural-only",
310 "國際音標": "IPA",
311 "基數詞": "cardinal",
312 "大寫": "capitalized",
313 "委婉": "euphemistic",
314 "字面義": "literally",
315 "完整": "perfect",
316 "完整體": "perfective",
317 "定語": "attributive",
318 "實詞": "substantive",
319 "尊敬": "honorific",
320 "敬語": "honorific",
321 "敬语": "honorific",
322 "常用複數": "plural-normally",
323 "幽默": "humorous",
324 "序數詞": "ordinal",
325 "廣義來說": "broadly",
326 "引申": "broadly",
327 "弱祈使式": "jussive",
328 "強調": "emphatic",
329 "後古典": "obsolete",
330 "性別中立": "gender-neutral",
331 "情態": "modal",
332 "愛稱": "endearing",
333 "所有格代詞": ["possessive", "pronoun", "without-noun"],
334 "押韻俚語": "slang",
335 "抽象名詞": "abstract-noun",
336 "擬態詞": "ideophonic",
337 "擬聲詞": "onomatopoeic",
338 "新詞": "neologism",
339 "方言": "dialectal",
340 "書面": "literary",
341 "书面": "literary",
342 "有比較級": "comparable",
343 "有生": "animate",
344 "正式": "formal",
345 "歷史": "historical",
346 "比喻義": "figuratively",
347 "無人稱": "impersonal",
348 "無比較級": "not-comparable",
349 "無生": "inanimate",
350 "焦點": "focus",
351 "狹義": "narrowly",
352 "監獄俚語": "slang",
353 "直陳語氣": "indicative",
354 "短信": "Internet",
355 "祈使語氣": "imperative",
356 "禮貌": "polite",
357 "種族歧視語": "slur",
358 "粉絲用語": ["slang", "lifestyle"],
359 "粗俗": "vulgar",
360 "系動詞": "copulative",
361 "網路用語": "Internet",
362 "縮寫": "abbreviation",
363 "罕用": "rare",
364 "臨時語": "nonce-word",
365 "虛擬語氣": "subjunctive",
366 "表語": "predicative",
367 "被動語態": "passive",
368 "視覺方言": "pronunciation-spelling",
369 "親切": "familiar",
370 "詈語": "expletive",
371 "詩歌": "poetic",
372 "誇飾": "excessive",
373 "語中音省略": "syncope",
374 "諷刺": "sarcastic",
375 "謙遜": "humble",
376 "貶義": "derogatory",
377 "轉喻義": "metonymically",
378 "返璞詞": "retronym",
379 "過時": "dated",
380 "陰性": "feminine",
381 "陽性": "masculine",
382 "雙及物動詞": "ditransitive",
383 "靜態動詞": "stative",
384 "非完整": "imperfect",
385 "非完整體": "imperfective",
386 "非常罕用": "rare",
387 "非標準": "nonstandard",
388 "非标准": "nonstandard",
389 "非標準形式": "nonstandard",
390 "非正式": "informal",
391 "首字母縮略詞": "initialism",
392 "駭客語": ["Leet", "Internet"],
393 "高語域": "honorific",
394 "中醫": "Traditional-Chinese-Medicine",
395 "修辭學": "rhetoric",
396 "印度教": "Hinduism",
397 "摩門教": "Mormonism",
398 "物理": "particle",
399 "猶太教": "Judaism",
400 "納粹主義": "Nazism",
401 "網際網路": "Internet",
402 "耆那教": "Jainism",
403 "聖經": "Biblical",
404 "解剖學": "anatomy",
405 "貴格會": "Quakerism",
406 "錫克教": "Sikhism",
407 "馬克思主義": "Marxism",
408 # also from Module:Labels/data, but translated manually
409 "喃字": "Chu-Nom",
410 "反身代詞": "reflexive",
411 "字面意義": "literally",
412 "成語": "Chengyu",
413 "及物、不及物": ["transitive", "intransitive"],
414 "集合名詞": "collective",
415 "控制動詞": "control-verb",
416 "省略": "ellipsis",
417 "分數": "fractional",
418 "以雙數形式": "dual",
419 "主要用於否定複數": ["negative", "plural"],
420 "數詞縮寫": ["numeral", "abbreviation"],
421 "主要用於肯定": "positive",
422 "古典": "Classical",
423 "中國大陸": "Mainland-China",
424 "書面語": "literary",
425}
427# example sentence template
428# https://zh.wiktionary.org/wiki/Template:Zh-x
429# https://zh.wiktionary.org/wiki/Module:Zh-usex/data
430ZH_X_TAGS = {
431 "繁體": "Traditional-Chinese",
432 "繁體和": "Traditional-Chinese",
433 "簡體": "Simplified-Chinese",
434 "繁體和簡體": ["Traditional-Chinese", "Simplified-Chinese"],
435 "漢語拼音": "Pinyin",
436 "粵拼": "Jyutping",
437 "現代標準漢語": "Standard-Chinese",
438 "文言文": "Classical-Chinese",
439 "官話白話文": "Written-vernacular-Chinese",
440 "粵語": "Cantonese",
441 "吳語": "Wu",
442 "廣州話": "Cantonese",
443 "臺灣華語": "Taiwanese-Mandarin",
444}
446# classifier tags
447# https://zh.wiktionary.org/wiki/Template:zh-mw
448# https://zh.wiktionary.org/wiki/Module:Zh/templates
449ZH_TAGS = {
450 "官話": "Mandarin",
451 "贛語": "Gan",
452 "客家話": "Hakka",
453 "晉語": "Jin",
454 "閩北語": "Min-Bei",
455 "閩東語": "Min-Dong",
456 "閩南語": "Min-Nan",
457 "潮州話": "Teochew",
458 "湘語": "Xiang",
459}
461# https://zh.wiktionary.org/wiki/Template:Zh-pron
462# https://zh.wiktionary.org/wiki/Module:Zh-pron
463ZH_PRON_TAGS = {
464 "拼音": "Pinyin",
465 "注音": "Bopomofo",
466 "潮州話拼音": "Peng'im",
467 "上海": "Shanghai",
468 "吳語學堂拼音": "Wugniu",
469 "通用拼音": "Tongyong-Pinyin",
470 "威妥瑪拼音": "Wade–Giles",
471 "耶魯官話拼音": "Yale",
472 "國語羅馬字": "Gwoyeu-Romatsyh",
473 "西里爾字母轉寫": "Cyrillic",
474 "西里爾字母": "Cyrillic",
475 "漢語國際音標": "Sinological-IPA",
476 "耶魯粵拼": ["Yale", "Jyutping"],
477 "廣州話拼音": ["Cantonese", "Pinyin"],
478 "廣東拼音": "Guangdong-Romanization",
479 "國際音標": "IPA",
480 "模仿白話字": "POJ",
481 "標準粵語": "Standard-Cantonese",
482 "廣州–香港話": ["Guangzhou", "Hong Kong"],
483 "福州話": "Fuzhou",
484 "平話字": "Foochow-Romanized",
485 "客家語": "Hakka",
486 "白話字": "Phak-fa-su",
487 "泉漳話": "Hokkien",
488 "泉州": "Quanzhou",
489 "廈門": "Xiamen",
490 "輕尾聲異讀": "toneless-final-syllable-variant",
491 "維基詞典": "Wiktionary-specific",
492 "維基詞典拼音": ["Wiktionary-specific", "Pinyin"],
493 "維基詞典轉寫": "Wiktionary-specific",
494 "成都話": "Chengdu",
495 "四川話拼音": ["Sichuanese", "Pinyin"],
496 "東干語": "Dongan",
497 "台山話": "Taishanese",
498 "四縣": "Sixian",
499 "長沙話": "Changsha",
500 "四川話拉丁化新文字": "Latinxua-Sin-Wenz",
501 "台城": "Taicheng",
502 "南昌話": "Nanchang",
503 "四縣話": "Sixian",
504 "苗栗": "Miaoli",
505 "美濃": "Neipu",
506 "客家語拼音": "Hakka-Romanization-System",
507 "客家話拼音方案": "Hagfa-Pinyim",
508 "太原話": "Taiyuan",
509 "老派": "dated",
510 "新加坡": "Singapore",
511 "臺羅": "Tâi-lô",
512 "普實台文": "Phofsit-Daibuun",
513 "太湖片": "Northern",
514 "吳音小字典": "MiniDict",
515 "維基詞典羅馬化": ["Wiktionary-specific", "romanization"],
516 "上海話": "Shanghai",
517 "中古漢語": "Middle-Chinese",
518 "莆仙語": "Puxian-Min",
519 "莆仙話拼音": "Pouseng-Ping'ing",
520 "莆田": "Putian",
521 "仙遊": "Xianyou",
522 "漳州": "Zhangzhou",
523 "臺北": "Taibei",
524 "高雄": "Kaohsiung",
525 "實際讀音": "phonetic",
526 "臺灣話": "Taiwanese",
527 "常用": "general",
528 "檳城": "Penang",
529 "兒化": "Erhua",
530 "文讀": "literary",
531 "中國大陸標準讀法": ["Mainland-China", "standard"],
532 "臺灣異讀法": ["Taiwan", "variant"],
533 "中國大陸與臺灣標準讀法": ["Mainland-China", "Taiwan", "standard"],
534}
536ZH_DIAL_TAGS = {
537 "白話文": "Written-vernacular-Chinese",
538 "北京": "Beijing",
539 "燕京官話": "Northeastern-Mandarin",
540 "冀魯官話": "Jilu-Mandarin",
541 "膠遼官話": "Jiaoliao-Mandarin",
542 "中原官話": "Central-Plains-Mandarin",
543 "蘭銀官話": "Lanyin-Mandarin",
544 "西南官話": "Southwestern-Mandarin",
545 "江淮官話": "Jianghuai-Mandarin",
546 "徽語": "Huizhou",
547 "南部平話": "Southern-Pinghua",
548 "濟南": "Jinan",
549 "臺灣": "Taiwan",
550}
552TH_PRON_TAGS = {
553 "寫法": "orthographic",
554 "音素": "phoneme",
555 "泰語羅馬化": "romanization",
556 "派汶拼音": "Paiboon",
557 "皇家轉寫": "Royal-Institute",
558 "非正字法": "unorthographical",
559 "短音": "short",
560}
563ALL_TAGS = {
564 **GRAMMATICAL_TAGS,
565 **LABEL_TAGS,
566 **ZH_X_TAGS,
567 **ZH_TAGS,
568 **ZH_PRON_TAGS,
569 **ZH_DIAL_TAGS,
570 **TH_PRON_TAGS,
571}
574def translate_raw_tags(data: WordEntry) -> WordEntry:
575 raw_tags = []
576 for raw_tag in data.raw_tags:
577 if raw_tag in ALL_TAGS:
578 tr_tag = ALL_TAGS[raw_tag]
579 if isinstance(tr_tag, str) and tr_tag not in data.tags:
580 data.tags.append(tr_tag)
581 elif isinstance(tr_tag, list):
582 data.tags.extend(tr_tag)
583 elif raw_tag in LABEL_TOPICS and hasattr(data, "topics"):
584 data.topics.append(LABEL_TOPICS[raw_tag])
585 elif raw_tag not in raw_tags: 585 ↛ 576line 585 didn't jump to line 576 because the condition on line 585 was always true
586 raw_tags.append(raw_tag)
587 data.raw_tags = raw_tags
588 return data
591# https://zh.wiktionary.org/wiki/Template:T
592# https://zh.wiktionary.org/wiki/Template:Head
593# https://zh.wiktionary.org/wiki/Module:Gender_and_number
594TEMPLATE_TAG_ARGS = {
595 "f": "feminine",
596 "m": "masculine",
597 "n": "neuter",
598 "c": "common",
599 # Animacy
600 "an": "animate",
601 "in": "inanimate",
602 # Animal (for Ukrainian, Belarusian, Polish)
603 "anml": "animal",
604 # Personal (for Ukrainian, Belarusian, Polish)
605 "pr": "personal",
606 # Nonpersonal not currently used
607 "np": "nonpersonal",
608 # Virility (for Polish)
609 "vr": "virile",
610 "nv": "nonvirile",
611 # Numbers
612 "s": "singular number",
613 "d": "dual number",
614 "p": "plural number",
615 # Verb qualifiers
616 "impf": "imperfective",
617 "pf": "perfective",
618 "mf": ["masculine", "feminine"],
619}