Coverage for src/wiktextract/extractor/vi/tags.py: 74%
24 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
3# https://vi.wiktionary.org/wiki/Mô_đun:labels/data
4LABEL_TAGS = {
5 "không còn dùng": "obsolete",
6 "cũ": "obsolete",
7}
8# https://vi.wiktionary.org/wiki/Mô_đun:gender_and_number/data
9GENDER_NUMBER_TAGS = {
10 "giống đực": "masculine",
11 "giống cái": "feminine",
12 "giống trung": "neuter",
13 "giống chung": "common-gender",
14 "gender-neutral": "neuter",
15 "động vật": "animate",
16 "bất động vật": "inanimate",
17 "chỉ loài vật": "animal-not-person",
18 "từ chỉ cá nhân": "person",
19 "nonpersonal": "impersonal",
20 "virile (= masculine personal)": "virile",
21 "nonvirile (= other than masculine personal)": "nonvirile",
22 "số ít": "singular",
23 "số kép": "dual",
24 "số nhiều": "plural",
25 "thể chưa hoàn thành": "imperfective",
26 "thể hoàn thành": "perfective",
27}
29LOCATIONS = {
30 "hà nội": "Hà-Nội",
31 "huế": "Huế",
32 "sài gòn": "Saigon",
33 "vinh": "Vinh",
34 "thanh chương": "Thanh-Chương",
35 "hà tĩnh": "Hà-Tĩnh",
36}
38SOUND_TAGS = {
39 "phát âm giọng anh chuẩn": "Received-Pronunciation",
40 "anh mỹ thông dụng": "General-American",
41}
43TAGS = {**LABEL_TAGS, **GENDER_NUMBER_TAGS, **LOCATIONS, **SOUND_TAGS}
45# https://vi.wiktionary.org/wiki/Mô_đun:labels/data/topical
46TOPICS = {
47 "địa chấn học": "seismology",
48 "thực vật học": "botany",
49 "hóa học": "chemistry",
50}
53def translate_raw_tags(data: WordEntry) -> None:
54 raw_tags = []
55 for raw_tag in data.raw_tags:
56 if raw_tag.lower() in TAGS and hasattr(data, "tags"):
57 tr_tag = TAGS[raw_tag.lower()]
58 if isinstance(tr_tag, str): 58 ↛ 60line 58 didn't jump to line 60 because the condition on line 58 was always true
59 data.tags.append(tr_tag)
60 elif isinstance(tr_tag, list):
61 data.tags.extend(tr_tag)
62 elif raw_tag.lower() in TOPICS and hasattr(data, "topics"):
63 topic = TOPICS[raw_tag.lower()]
64 if isinstance(topic, str): 64 ↛ 66line 64 didn't jump to line 66 because the condition on line 64 was always true
65 data.topics.append(topic)
66 elif isinstance(topic, list):
67 data.topics.extend(topic)
68 else:
69 raw_tags.append(raw_tag)
70 data.raw_tags = raw_tags