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