Coverage for src/wiktextract/extractor/zh/tags.py: 98%
35 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 10:31 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 10:31 +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}
89# https://en.wikipedia.org/wiki/Japanese_grammar#Stem_forms
90JA_STEM_FORMS: dict[str, str] = {
91 "未然形": "imperfective",
92 "連用形": "continuative",
93 "終止形": "terminal",
94 "連體形": "attributive",
95 "連体形": "attributive",
96 "假定形": "hypothetical",
97 "仮定形": "hypothetical",
98 "命令形": "imperative",
99}
101# https://en.wikipedia.org/wiki/Voice_(grammar)
102VOICE_TAGS: dict[str, str | list[str]] = {
103 "被動形": "passive",
104 "使役形": "causative",
105 "可能形": "potential",
106 "意志形": "volitional",
107 "否定形": "negative",
108 "否定連用形": ["negative", "continuative"],
109 "尊敬形": "formal",
110 "完成形": "perfective",
111 "接續形": "conjunctive",
112 "條件形": ["hypothetical", "conditional"],
113}
115COMPARISON_TAGS: dict[str, str] = {
116 # https://en.wikipedia.org/wiki/Comparison_(grammar)
117 "原级": "positive",
118 "比較級": "comparative",
119 "最高級": "superlative",
120}
122TENSE_TAGS = {
123 "過去時": "preterite",
124 "過去式": "past",
125 "過去分詞": ["past", "participle"],
126 "現在時": "present",
127 "第三人稱單數現在時": ["third-person", "singular", "present"],
128 "助動詞": "auxiliary",
129 # Template:de-verb
130 "弱變化": "weak",
131 "弱变化": "weak",
132 "第三人稱單數簡單現在時": ["third-person", "singular", "present"],
133 "現在分詞": ["present", "participle"],
134 "一般過去時及過去分詞": ["past", "participle"],
135 # Template:it-verb
136 "第一人稱單數 現在時": ["first-person", "singular", "present"],
137 "第一人稱單數 先過去時": ["first-person", "singular", "past", "historic"],
138 # Template:de-adj
139 "強變化主格陽性單數": ["strong", "nominative", "masculine", "singular"],
140 # Template:la-verb
141 "现在时不定式": ["present", "infinitive"],
142 "完成时主动式": ["perfect", "active"],
143 "目的动名词": "supine",
144}
146GRAMMATICAL_TAGS: dict[str, str] = {
147 **GENDER_TAGS,
148 **NUMBER_TAGS,
149 **COUNT_TAGS,
150 **OTHER_TAGS,
151 **VERB_TAGS,
152 **JA_STEM_FORMS,
153 **VOICE_TAGS,
154 **COMPARISON_TAGS,
155 **TENSE_TAGS,
156}
158# https://zh.wiktionary.org/wiki/Template:Label
159# https://zh.wiktionary.org/wiki/Module:Labels/data
160# https://zh.wiktionary.org/wiki/Template:Qualifier
161# https://zh.wiktionary.org/wiki/Template:古
162# https://zh.wiktionary.org/wiki/Template:注释
163LABEL_TAGS = {
164 "棄用": "obsolete",
165 "弃用": "obsolete",
166 "比喻": "figuratively",
167 "古": "archaic",
168 "陽": "masculine",
169 "陰": "feminine",
170 "喻": "figuratively",
171 "書": "literary",
172 "口": "colloquial",
173 "俚": "slang",
174 "俗": "slang",
175 "方": "dialectal",
176 "废": "obsolete",
177 "貶": "derogatory",
178 "罕": "rare",
179 "引": "broadly",
180 "現已罕用": "archaic",
181 # Module:Labels/data
182 "back slang": "slang",
183 "synecdochically": "synecdoche",
184 "不再自由造詞": "idiomatic",
185 "不及物": "intransitive",
186 "不可數": "uncountable",
187 "不定": "indefinite",
188 "不常見": "uncommon",
189 "不推薦使用": "proscribed",
190 "中性": "neuter",
191 "中間被動語態": "mediopassive",
192 "中間語態": "middle",
193 "主動語態": "active",
194 "主要用於否定": ["usually", "with-negation"],
195 "交互": "reciprocal",
196 "以單數形式": "singular",
197 "以複數形式": "in-plural",
198 "作定語": "attributive",
199 "作格": "ergative",
200 "作表語": "predicative",
201 "使役": "causative",
202 "俗語": "idiomatic",
203 "俚語": "slang",
204 "俚语": "slang",
205 "兒童用語": "childish",
206 "公文": "bureaucratese",
207 "冒犯": "offensive",
208 "分詞": "participle",
209 "前古典": "pre-Classical",
210 "助動詞": "auxiliary",
211 "助記符": "mnemonic",
212 "及物": "transitive",
213 "反問句": "rhetoric",
214 "反身": "reflexive",
215 "口語": "colloquial",
216 "口语": "colloquial",
217 "古舊": "archaic",
218 "可數": "countable",
219 "同性戀俚語": ["slang", "LGBT"],
220 "名詞化": "noun-from-verb",
221 "唯單": "singular-only",
222 "唯複": "plural-only",
223 "國際音標": "IPA",
224 "基數詞": "cardinal",
225 "大寫": "capitalized",
226 "委婉": "euphemistic",
227 "字面義": "literally",
228 "完整": "perfect",
229 "完整體": "perfective",
230 "定語": "attributive",
231 "實詞": "substantive",
232 "尊敬": "honorific",
233 "敬語": "honorific",
234 "敬语": "honorific",
235 "常用複數": "plural-normally",
236 "幽默": "humorous",
237 "序數詞": "ordinal",
238 "廣義來說": "broadly",
239 "引申": "broadly",
240 "弱祈使式": "jussive",
241 "強調": "emphatic",
242 "後古典": "obsolete",
243 "性別中立": "gender-neutral",
244 "情態": "modal",
245 "愛稱": "endearing",
246 "所有格代詞": ["possessive", "pronoun", "without-noun"],
247 "押韻俚語": "slang",
248 "抽象名詞": "abstract-noun",
249 "擬態詞": "ideophonic",
250 "擬聲詞": "onomatopoeic",
251 "新詞": "neologism",
252 "方言": "dialectal",
253 "書面": "literary",
254 "书面": "literary",
255 "有比較級": "comparable",
256 "有生": "animate",
257 "正式": "formal",
258 "歷史": "historical",
259 "比喻義": "figuratively",
260 "無人稱": "impersonal",
261 "無比較級": "not-comparable",
262 "無生": "inanimate",
263 "焦點": "focus",
264 "狹義": "narrowly",
265 "監獄俚語": "slang",
266 "直陳語氣": "indicative",
267 "短信": "Internet",
268 "祈使語氣": "imperative",
269 "禮貌": "polite",
270 "種族歧視語": "slur",
271 "粉絲用語": ["slang", "lifestyle"],
272 "粗俗": "vulgar",
273 "系動詞": "copulative",
274 "網路用語": "Internet",
275 "縮寫": "abbreviation",
276 "罕用": "rare",
277 "臨時語": "nonce-word",
278 "虛擬語氣": "subjunctive",
279 "表語": "predicative",
280 "被動語態": "passive",
281 "視覺方言": "pronunciation-spelling",
282 "親切": "familiar",
283 "詈語": "expletive",
284 "詩歌": "poetic",
285 "誇飾": "excessive",
286 "語中音省略": "syncope",
287 "諷刺": "sarcastic",
288 "謙遜": "humble",
289 "貶義": "derogatory",
290 "轉喻義": "metonymically",
291 "返璞詞": "retronym",
292 "過時": "dated",
293 "陰性": "feminine",
294 "陽性": "masculine",
295 "雙及物動詞": "ditransitive",
296 "靜態動詞": "stative",
297 "非完整": "imperfect",
298 "非完整體": "imperfective",
299 "非常罕用": "rare",
300 "非標準": "nonstandard",
301 "非标准": "nonstandard",
302 "非標準形式": "nonstandard",
303 "非正式": "informal",
304 "首字母縮略詞": "initialism",
305 "駭客語": ["Leet", "Internet"],
306 "高語域": "honorific",
307 "中醫": "Traditional-Chinese-Medicine",
308 "修辭學": "rhetoric",
309 "印度教": "Hinduism",
310 "摩門教": "Mormonism",
311 "物理": "particle",
312 "猶太教": "Judaism",
313 "納粹主義": "Nazism",
314 "網際網路": "Internet",
315 "耆那教": "Jainism",
316 "聖經": "Biblical",
317 "解剖學": "anatomy",
318 "貴格會": "Quakerism",
319 "錫克教": "Sikhism",
320 "馬克思主義": "Marxism",
321 # also from Module:Labels/data, but translated manually
322 "喃字": "Chu-Nom",
323 "反身代詞": "reflexive",
324 "字面意義": "literally",
325 "成語": "Chengyu",
326 "及物、不及物": ["transitive", "intransitive"],
327 "集合名詞": "collective",
328 "控制動詞": "control-verb",
329 "省略": "ellipsis",
330 "分數": "fractional",
331 "以雙數形式": "dual",
332 "主要用於否定複數": ["negative", "plural"],
333 "數詞縮寫": ["numeral", "abbreviation"],
334 "主要用於肯定": "positive",
335 "古典": "Classical",
336 "中國大陸": "Mainland-China",
337 "書面語": "literary",
338}
340# example sentence template
341# https://zh.wiktionary.org/wiki/Template:Zh-x
342# https://zh.wiktionary.org/wiki/Module:Zh-usex/data
343ZH_X_TAGS = {
344 "繁體": "Traditional-Chinese",
345 "繁體和": "Traditional-Chinese",
346 "簡體": "Simplified-Chinese",
347 "繁體和簡體": ["Traditional-Chinese", "Simplified-Chinese"],
348 "漢語拼音": "Pinyin",
349 "粵拼": "Jyutping",
350 "現代標準漢語": "Standard-Chinese",
351 "文言文": "Classical-Chinese",
352 "官話白話文": "Written-vernacular-Chinese",
353 "粵語": "Cantonese",
354 "吳語": "Wu",
355 "廣州話": "Cantonese",
356 "臺灣華語": "Taiwanese-Mandarin",
357}
359# classifier tags
360# https://zh.wiktionary.org/wiki/Template:zh-mw
361# https://zh.wiktionary.org/wiki/Module:Zh/templates
362ZH_TAGS = {
363 "官話": "Mandarin",
364 "贛語": "Gan",
365 "客家話": "Hakka",
366 "晉語": "Jin",
367 "閩北語": "Min-Bei",
368 "閩東語": "Min-Dong",
369 "閩南語": "Min-Nan",
370 "潮州話": "Teochew",
371 "湘語": "Xiang",
372}
374# https://zh.wiktionary.org/wiki/Template:Zh-pron
375# https://zh.wiktionary.org/wiki/Module:Zh-pron
376ZH_PRON_TAGS = {
377 "拼音": "Pinyin",
378 "注音": "Bopomofo",
379 "潮州話拼音": "Peng'im",
380 "上海": "Shanghai",
381 "吳語學堂拼音": "Wugniu",
382 "通用拼音": "Tongyong-Pinyin",
383 "威妥瑪拼音": "Wade–Giles",
384 "耶魯官話拼音": "Yale",
385 "國語羅馬字": "Gwoyeu-Romatsyh",
386 "西里爾字母轉寫": "Cyrillic",
387 "西里爾字母": "Cyrillic",
388 "漢語國際音標": "Sinological-IPA",
389 "耶魯粵拼": ["Yale", "Jyutping"],
390 "廣州話拼音": ["Cantonese", "Pinyin"],
391 "廣東拼音": "Guangdong-Romanization",
392 "國際音標": "IPA",
393 "模仿白話字": "POJ",
394 "標準粵語": "Standard-Cantonese",
395 "廣州–香港話": ["Guangzhou", "Hong Kong"],
396 "福州話": "Fuzhou",
397 "平話字": "Foochow-Romanized",
398 "客家語": "Hakka",
399 "白話字": "Phak-fa-su",
400 "泉漳話": "Hokkien",
401 "泉州": "Quanzhou",
402 "廈門": "Xiamen",
403 "輕尾聲異讀": "toneless-final-syllable-variant",
404 "維基詞典": "Wiktionary-specific",
405 "維基詞典拼音": ["Wiktionary-specific", "Pinyin"],
406 "維基詞典轉寫": "Wiktionary-specific",
407 "成都話": "Chengdu",
408 "四川話拼音": ["Sichuanese", "Pinyin"],
409 "東干語": "Dongan",
410 "台山話": "Taishanese",
411 "四縣": "Sixian",
412 "長沙話": "Changsha",
413 "四川話拉丁化新文字": "Latinxua-Sin-Wenz",
414 "台城": "Taicheng",
415 "南昌話": "Nanchang",
416 "四縣話": "Sixian",
417 "苗栗": "Miaoli",
418 "美濃": "Neipu",
419 "客家語拼音": "Hakka-Romanization-System",
420 "客家話拼音方案": "Hagfa-Pinyim",
421 "太原話": "Taiyuan",
422 "老派": "dated",
423 "新加坡": "Singapore",
424 "臺羅": "Tâi-lô",
425 "普實台文": "Phofsit-Daibuun",
426 "太湖片": "Northern",
427 "吳音小字典": "MiniDict",
428 "維基詞典羅馬化": ["Wiktionary-specific", "romanization"],
429 "上海話": "Shanghai",
430 "中古漢語": "Middle-Chinese",
431 "莆仙語": "Puxian-Min",
432 "莆仙話拼音": "Pouseng-Ping'ing",
433 "莆田": "Putian",
434 "仙遊": "Xianyou",
435 "漳州": "Zhangzhou",
436 "臺北": "Taibei",
437 "高雄": "Kaohsiung",
438 "實際讀音": "phonetic",
439 "臺灣話": "Taiwanese",
440 "常用": "general",
441 "檳城": "Penang",
442 "兒化": "Erhua",
443 "文讀": "literary",
444 "中國大陸標準讀法": ["Mainland-China", "standard"],
445 "臺灣異讀法": ["Taiwan", "variant"],
446 "中國大陸與臺灣標準讀法": ["Mainland-China", "Taiwan", "standard"],
447}
449ZH_DIAL_TAGS = {
450 "白話文": "Written-vernacular-Chinese",
451 "北京": "Beijing",
452 "燕京官話": "Northeastern-Mandarin",
453 "冀魯官話": "Jilu-Mandarin",
454 "膠遼官話": "Jiaoliao-Mandarin",
455 "中原官話": "Central-Plains-Mandarin",
456 "蘭銀官話": "Lanyin-Mandarin",
457 "西南官話": "Southwestern-Mandarin",
458 "江淮官話": "Jianghuai-Mandarin",
459 "徽語": "Huizhou",
460 "南部平話": "Southern-Pinghua",
461 "濟南": "Jinan",
462 "臺灣": "Taiwan",
463}
465TH_PRON_TAGS = {
466 "寫法": "orthographic",
467 "音素": "phoneme",
468 "泰語羅馬化": "romanization",
469 "派汶拼音": "Paiboon",
470 "皇家轉寫": "Royal-Institute",
471 "非正字法": "unorthographical",
472 "短音": "short",
473}
476ALL_TAGS = {
477 **GRAMMATICAL_TAGS,
478 **LABEL_TAGS,
479 **ZH_X_TAGS,
480 **ZH_TAGS,
481 **ZH_PRON_TAGS,
482 **ZH_DIAL_TAGS,
483 **TH_PRON_TAGS,
484}
487def translate_raw_tags(data: WordEntry) -> WordEntry:
488 raw_tags = []
489 for raw_tag in data.raw_tags:
490 if raw_tag in ALL_TAGS:
491 tr_tag = ALL_TAGS[raw_tag]
492 if isinstance(tr_tag, str) and tr_tag not in data.tags:
493 data.tags.append(tr_tag)
494 elif isinstance(tr_tag, list):
495 data.tags.extend(tr_tag)
496 elif raw_tag in LABEL_TOPICS and hasattr(data, "topics"):
497 data.topics.append(LABEL_TOPICS[raw_tag])
498 elif raw_tag not in raw_tags: 498 ↛ 489line 498 didn't jump to line 489 because the condition on line 498 was always true
499 raw_tags.append(raw_tag)
500 data.raw_tags = raw_tags
501 return data
504# https://zh.wiktionary.org/wiki/Template:T
505# https://zh.wiktionary.org/wiki/Template:Head
506# https://zh.wiktionary.org/wiki/Module:Gender_and_number
507TEMPLATE_TAG_ARGS = {
508 "f": "feminine",
509 "m": "masculine",
510 "n": "neuter",
511 "c": "common",
512 # Animacy
513 "an": "animate",
514 "in": "inanimate",
515 # Animal (for Ukrainian, Belarusian, Polish)
516 "anml": "animal",
517 # Personal (for Ukrainian, Belarusian, Polish)
518 "pr": "personal",
519 # Nonpersonal not currently used
520 "np": "nonpersonal",
521 # Virility (for Polish)
522 "vr": "virile",
523 "nv": "nonvirile",
524 # Numbers
525 "s": "singular number",
526 "d": "dual number",
527 "p": "plural number",
528 # Verb qualifiers
529 "impf": "imperfective",
530 "pf": "perfective",
531 "mf": ["masculine", "feminine"],
532}