Coverage for src/wiktextract/extractor/es/inflection.py: 93%

44 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-04 08:12 +0000

1from wikitextprocessor.parser import NodeKind, TemplateNode 

2 

3from ...page import clean_node 

4from ...wxr_context import WiktextractContext 

5from .models import Form, WordEntry 

6from .tags import translate_raw_tags 

7 

8 

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 expanded_node = wxr.wtp.parse( 

14 wxr.wtp.node_to_wikitext(t_node), expand_all=True 

15 ) 

16 table_nodes = list(expanded_node.find_child(NodeKind.TABLE)) 

17 if len(table_nodes) == 0: 

18 return 

19 table_node = table_nodes[0] 

20 col_headers = [] 

21 row_header = "" 

22 forms_with_row_span = [] 

23 for row in table_node.find_child(NodeKind.TABLE_ROW): 

24 col_index = 0 

25 is_col_header_row = not row.contain_node(NodeKind.TABLE_CELL) 

26 for cell in row.find_child( 

27 NodeKind.TABLE_HEADER_CELL | NodeKind.TABLE_CELL 

28 ): 

29 cell_text = clean_node(wxr, None, cell) 

30 if cell_text == "": 

31 continue 

32 elif cell.kind == NodeKind.TABLE_HEADER_CELL: 

33 if is_col_header_row: 

34 col_headers.append(cell_text) 

35 else: 

36 row_header = cell_text 

37 for form in forms_with_row_span[:]: 

38 form.raw_tags.append(row_header) 

39 translate_raw_tags(form) 

40 if form.row_span == 1: 40 ↛ 43line 40 didn't jump to line 43 because the condition on line 40 was always true

41 forms_with_row_span.remove(form) 

42 else: 

43 form.row_span -= 1 

44 elif cell.kind == NodeKind.TABLE_CELL: 44 ↛ 26line 44 didn't jump to line 26 because the condition on line 44 was always true

45 form = Form(form=cell_text) 

46 row_span = int(cell.attrs.get("rowspan", "1")) 

47 if row_span > 1: 

48 forms_with_row_span.append(form) 

49 if len(row_header) > 0: 

50 form.raw_tags.append(row_header) 

51 if col_index < len(col_headers): 51 ↛ 53line 51 didn't jump to line 53 because the condition on line 51 was always true

52 form.raw_tags.append(col_headers[col_index]) 

53 if len(form.form) > 0: 53 ↛ 56line 53 didn't jump to line 56 because the condition on line 53 was always true

54 translate_raw_tags(form) 

55 word_entry.forms.append(form) 

56 col_index += 1