Coverage for src / wiktextract / extractor / es / inflection.py: 93%
44 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-21 08:01 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-21 08:01 +0000
1from wikitextprocessor.parser import NodeKind, TemplateNode
3from ...page import clean_node
4from ...wxr_context import WiktextractContext
5from .models import Form, WordEntry
6from .tags import translate_raw_tags
9def process_inflect_template(
10 wxr: WiktextractContext, word_entry: WordEntry, t_node: TemplateNode
11) -> None:
12 # https://es.wiktionary.org/wiki/Plantilla:inflect.es.sust.reg
13 # POS headword table template
14 expanded_node = wxr.wtp.parse(
15 wxr.wtp.node_to_wikitext(t_node), expand_all=True
16 )
17 table_nodes = list(expanded_node.find_child(NodeKind.TABLE))
18 if len(table_nodes) == 0:
19 return
20 table_node = table_nodes[0]
21 col_headers = []
22 row_header = ""
23 forms_with_row_span = []
24 for row in table_node.find_child(NodeKind.TABLE_ROW):
25 col_index = 0
26 is_col_header_row = not row.contain_node(NodeKind.TABLE_CELL)
27 for cell in row.find_child(
28 NodeKind.TABLE_HEADER_CELL | NodeKind.TABLE_CELL
29 ):
30 cell_text = clean_node(wxr, None, cell)
31 if cell_text == "":
32 continue
33 elif cell.kind == NodeKind.TABLE_HEADER_CELL:
34 if is_col_header_row:
35 col_headers.append(cell_text)
36 else:
37 row_header = cell_text
38 for form in forms_with_row_span[:]:
39 form.raw_tags.append(row_header)
40 translate_raw_tags(form)
41 if form.row_span == 1: 41 ↛ 44line 41 didn't jump to line 44 because the condition on line 41 was always true
42 forms_with_row_span.remove(form)
43 else:
44 form.row_span -= 1
45 elif cell.kind == NodeKind.TABLE_CELL: 45 ↛ 27line 45 didn't jump to line 27 because the condition on line 45 was always true
46 form = Form(form=cell_text)
47 row_span = int(cell.attrs.get("rowspan", "1"))
48 if row_span > 1:
49 forms_with_row_span.append(form)
50 if len(row_header) > 0:
51 form.raw_tags.append(row_header)
52 if col_index < len(col_headers): 52 ↛ 54line 52 didn't jump to line 54 because the condition on line 52 was always true
53 form.raw_tags.append(col_headers[col_index])
54 if len(form.form) > 0: 54 ↛ 57line 54 didn't jump to line 57 because the condition on line 54 was always true
55 translate_raw_tags(form)
56 word_entry.forms.append(form)
57 col_index += 1