Coverage for src/wiktextract/extractor/ja/conjugation.py: 96%
38 statements
« prev ^ index » next coverage.py v7.9.0, created at 2025-06-13 07:43 +0000
« prev ^ index » next coverage.py v7.9.0, created at 2025-06-13 07:43 +0000
1from wikitextprocessor import LevelNode, NodeKind, TemplateNode
3from ...page import clean_node
4from ...wxr_context import WiktextractContext
5from .models import Form, WordEntry
6from .tags import translate_raw_tags
9def extract_conjugation_section(
10 wxr: WiktextractContext, word_entry: WordEntry, level_node: LevelNode
11) -> None:
12 for t_node in level_node.find_child(NodeKind.TEMPLATE):
13 if t_node.template_name in {
14 "日本語形容動詞活用",
15 "日本語五段活用",
16 "日本語五段活用/表示",
17 "日本語上一段活用",
18 "日本語下一段活用",
19 "日本語形容詞活用/表示",
20 "日本語タルト活用",
21 "日本語ダ活用",
22 "日本語サ変活用",
23 "日本語一段活用",
24 "日本語カ変活用",
25 "日本語ザ変活用",
26 }:
27 extract_ja_conjugation_table_template(wxr, word_entry, t_node)
30def extract_ja_conjugation_table_template(
31 wxr: WiktextractContext, word_entry: WordEntry, t_node: TemplateNode
32) -> None:
33 # extract templates use this Lua module
34 # https://ja.wiktionary.org/wiki/モジュール:日本語活用表
35 expanded_node = wxr.wtp.parse(
36 wxr.wtp.node_to_wikitext(t_node), expand_all=True
37 )
38 for link_node in expanded_node.find_child(NodeKind.LINK):
39 clean_node(wxr, word_entry, link_node)
40 for table_index, table_node in enumerate(
41 expanded_node.find_child_recursively(NodeKind.TABLE)
42 ):
43 table_name = ""
44 column_headers = []
45 row_header = ""
46 for row_or_caption in table_node.find_child(
47 NodeKind.TABLE_CAPTION | NodeKind.TABLE_ROW
48 ):
49 if row_or_caption.kind == NodeKind.TABLE_CAPTION:
50 table_name = clean_node(wxr, None, row_or_caption.children)
51 elif row_or_caption.kind == NodeKind.TABLE_ROW: 51 ↛ 46line 51 didn't jump to line 46 because the condition on line 51 was always true
52 for cell_index, cell_node in enumerate(
53 row_or_caption.find_child(
54 NodeKind.TABLE_HEADER_CELL | NodeKind.TABLE_CELL
55 )
56 ):
57 if cell_node.kind == NodeKind.TABLE_HEADER_CELL:
58 if (
59 len(list(row_or_caption.filter_empty_str_child()))
60 == 1
61 ):
62 table_name = clean_node(wxr, None, cell_node)
63 else:
64 column_headers.append(
65 clean_node(wxr, None, cell_node)
66 )
67 elif cell_node.kind == NodeKind.TABLE_CELL: 67 ↛ 52line 67 didn't jump to line 52 because the condition on line 67 was always true
68 if table_index == 1 and cell_index == 0:
69 row_header = clean_node(wxr, None, cell_node)
70 else:
71 for line in clean_node(
72 wxr, None, cell_node
73 ).splitlines():
74 form = Form(form=line)
75 form.raw_tags.append(table_name)
76 if cell_index < len(column_headers): 76 ↛ 80line 76 didn't jump to line 80 because the condition on line 76 was always true
77 form.raw_tags.append(
78 column_headers[cell_index]
79 )
80 if len(row_header) > 0:
81 form.raw_tags.append(row_header)
82 translate_raw_tags(form)
83 word_entry.forms.append(form)