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