Coverage for src/wiktextract/extractor/zh/tags.py: 98%
34 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 11:10 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 11:10 +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 "臺灣華語": "Taiwanese-Mandarin",
356}
358# classifier tags
359# https://zh.wiktionary.org/wiki/Template:zh-mw
360# https://zh.wiktionary.org/wiki/Module:Zh/templates
361ZH_TAGS = {
362 "官話": "Mandarin",
363 "贛語": "Gan",
364 "客家話": "Hakka",
365 "晉語": "Jin",
366 "閩北語": "Min-Bei",
367 "閩東語": "Min-Dong",
368 "閩南語": "Min-Nan",
369 "潮州話": "Teochew",
370 "湘語": "Xiang",
371}
373# https://zh.wiktionary.org/wiki/Template:Zh-pron
374# https://zh.wiktionary.org/wiki/Module:Zh-pron
375ZH_PRON_TAGS = {
376 "拼音": "Pinyin",
377 "注音": "Bopomofo",
378 "潮州話拼音": "Peng'im",
379 "上海": "Shanghai",
380 "吳語學堂拼音": "Wugniu",
381 "通用拼音": "Tongyong-Pinyin",
382 "威妥瑪拼音": "Wade–Giles",
383 "耶魯官話拼音": "Yale",
384 "國語羅馬字": "Gwoyeu-Romatsyh",
385 "西里爾字母轉寫": "Cyrillic",
386 "西里爾字母": "Cyrillic",
387 "漢語國際音標": "Sinological-IPA",
388 "耶魯粵拼": ["Yale", "Jyutping"],
389 "廣州話拼音": ["Cantonese", "Pinyin"],
390 "廣東拼音": "Guangdong-Romanization",
391 "國際音標": "IPA",
392 "模仿白話字": "POJ",
393 "標準粵語": "Standard-Cantonese",
394 "廣州–香港話": ["Guangzhou", "Hong Kong"],
395 "福州話": "Fuzhou",
396 "平話字": "Foochow-Romanized",
397 "客家語": "Hakka",
398 "白話字": "Phak-fa-su",
399 "泉漳話": "Hokkien",
400 "泉州": "Quanzhou",
401 "廈門": "Xiamen",
402 "輕尾聲異讀": "toneless-final-syllable-variant",
403 "維基詞典": "Wiktionary-specific",
404 "維基詞典拼音": ["Wiktionary-specific", "Pinyin"],
405 "維基詞典轉寫": "Wiktionary-specific",
406 "成都話": "Chengdu",
407 "四川話拼音": ["Sichuanese", "Pinyin"],
408 "東干語": "Dongan",
409 "台山話": "Taishanese",
410 "四縣": "Sixian",
411 "長沙話": "Changsha",
412 "四川話拉丁化新文字": "Latinxua-Sin-Wenz",
413 "台城": "Taicheng",
414 "南昌話": "Nanchang",
415 "四縣話": "Sixian",
416 "苗栗": "Miaoli",
417 "美濃": "Neipu",
418 "客家語拼音": "Hakka-Romanization-System",
419 "客家話拼音方案": "Hagfa-Pinyim",
420 "太原話": "Taiyuan",
421 "老派": "dated",
422 "新加坡": "Singapore",
423 "臺羅": "Tâi-lô",
424 "普實台文": "Phofsit-Daibuun",
425 "太湖片": "Northern",
426 "吳音小字典": "MiniDict",
427 "維基詞典羅馬化": ["Wiktionary-specific", "romanization"],
428 "上海話": "Shanghai",
429 "中古漢語": "Middle-Chinese",
430 "莆仙語": "Puxian-Min",
431 "莆仙話拼音": "Pouseng-Ping'ing",
432 "莆田": "Putian",
433 "仙遊": "Xianyou",
434 "漳州": "Zhangzhou",
435 "臺北": "Taibei",
436 "高雄": "Kaohsiung",
437 "實際讀音": "phonetic",
438 "臺灣話": "Taiwanese",
439 "常用": "general",
440 "檳城": "Penang",
441 "兒化": "Erhua",
442 "文讀": "literary",
443 "中國大陸標準讀法": ["Mainland-China", "standard"],
444 "臺灣異讀法": ["Taiwan", "variant"],
445 "中國大陸與臺灣標準讀法": ["Mainland-China", "Taiwan", "standard"],
446}
448ZH_DIAL_TAGS = {
449 "白話文": "Written-vernacular-Chinese",
450 "北京": "Beijing",
451 "燕京官話": "Northeastern-Mandarin",
452 "冀魯官話": "Jilu-Mandarin",
453 "膠遼官話": "Jiaoliao-Mandarin",
454 "中原官話": "Central-Plains-Mandarin",
455 "蘭銀官話": "Lanyin-Mandarin",
456 "西南官話": "Southwestern-Mandarin",
457 "江淮官話": "Jianghuai-Mandarin",
458 "徽語": "Huizhou",
459 "南部平話": "Southern-Pinghua",
460 "濟南": "Jinan",
461 "臺灣": "Taiwan",
462}
465ALL_TAGS = {
466 **GRAMMATICAL_TAGS,
467 **LABEL_TAGS,
468 **ZH_X_TAGS,
469 **ZH_TAGS,
470 **ZH_PRON_TAGS,
471 **ZH_DIAL_TAGS,
472}
475def translate_raw_tags(data: WordEntry) -> WordEntry:
476 raw_tags = []
477 for raw_tag in data.raw_tags:
478 if raw_tag in ALL_TAGS:
479 tr_tag = ALL_TAGS[raw_tag]
480 if isinstance(tr_tag, str) and tr_tag not in data.tags:
481 data.tags.append(tr_tag)
482 elif isinstance(tr_tag, list):
483 data.tags.extend(tr_tag)
484 elif raw_tag in LABEL_TOPICS and hasattr(data, "topics"):
485 data.topics.append(LABEL_TOPICS[raw_tag])
486 elif raw_tag not in raw_tags: 486 ↛ 477line 486 didn't jump to line 477 because the condition on line 486 was always true
487 raw_tags.append(raw_tag)
488 data.raw_tags = raw_tags
489 return data
492# https://zh.wiktionary.org/wiki/Template:T
493# https://zh.wiktionary.org/wiki/Template:Head
494# https://zh.wiktionary.org/wiki/Module:Gender_and_number
495TEMPLATE_TAG_ARGS = {
496 "f": "feminine",
497 "m": "masculine",
498 "n": "neuter",
499 "c": "common",
500 # Animacy
501 "an": "animate",
502 "in": "inanimate",
503 # Animal (for Ukrainian, Belarusian, Polish)
504 "anml": "animal",
505 # Personal (for Ukrainian, Belarusian, Polish)
506 "pr": "personal",
507 # Nonpersonal not currently used
508 "np": "nonpersonal",
509 # Virility (for Polish)
510 "vr": "virile",
511 "nv": "nonvirile",
512 # Numbers
513 "s": "singular number",
514 "d": "dual number",
515 "p": "plural number",
516 # Verb qualifiers
517 "impf": "imperfective",
518 "pf": "perfective",
519 "mf": ["masculine", "feminine"],
520}