Coverage for src/wiktextract/extractor/it/etymology.py: 92%

39 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-07 00:55 +0000

1from wikitextprocessor.parser import LEVEL_KIND_FLAGS, LevelNode, NodeKind 

2 

3from ...page import clean_node 

4from ...wxr_context import WiktextractContext 

5from ..share import calculate_bold_offsets 

6from .models import Example, WordEntry 

7 

8 

9def extract_etymology_section( 

10 wxr: WiktextractContext, page_data: list[WordEntry], level_node: LevelNode 

11) -> None: 

12 # https://it.wiktionary.org/wiki/Aiuto:Etimologia 

13 etymology_texts = [] 

14 etymology_links = [] 

15 for list_node in level_node.find_child(NodeKind.LIST): 

16 for list_item in list_node.find_child(NodeKind.LIST_ITEM): 

17 links: list[tuple[str, str]] = [] 

18 e_str = clean_node( 

19 wxr, None, list_item.children, link_collector=links 

20 ) 

21 if e_str != "": 21 ↛ 16line 21 didn't jump to line 16 because the condition on line 21 was always true

22 etymology_texts.append(e_str) 

23 etymology_links.extend(links) 

24 

25 if len(etymology_texts) == 0: 

26 links = [] 

27 e_str = clean_node( 

28 wxr, 

29 None, 

30 list( 

31 level_node.invert_find_child( 

32 LEVEL_KIND_FLAGS, include_empty_str=True 

33 ) 

34 ), 

35 link_collector=links, 

36 ) 

37 if e_str != "": 37 ↛ 41line 37 didn't jump to line 41 because the condition on line 37 was always true

38 etymology_texts.append(e_str) 

39 etymology_links.extend(links) 

40 

41 for data in page_data: 

42 if data.lang_code == page_data[-1].lang_code: 

43 data.etymology_texts.extend(etymology_texts) 

44 data.etymology_links.extend(etymology_links) 

45 

46 

47def extract_citation_section( 

48 wxr: WiktextractContext, page_data: list[WordEntry], level_node: LevelNode 

49): 

50 examples = [] 

51 for t_node in level_node.find_child(NodeKind.TEMPLATE): 

52 if t_node.template_name.lower() == "quote": 52 ↛ 51line 52 didn't jump to line 51 because the condition on line 52 was always true

53 example = Example() 

54 first_arg = wxr.wtp.parse( 

55 wxr.wtp.node_to_wikitext(t_node.template_parameters.get(1, "")) 

56 ) 

57 example.text = clean_node(wxr, None, first_arg) 

58 example.ref = clean_node( 

59 wxr, None, t_node.template_parameters.get(2, "") 

60 ) 

61 calculate_bold_offsets( 

62 wxr, first_arg, example.text, example, "bold_text_offsets" 

63 ) 

64 if example.text != "": 64 ↛ 51line 64 didn't jump to line 51 because the condition on line 64 was always true

65 examples.append(example) 

66 for data in page_data: 

67 if data.lang_code == page_data[-1].lang_code: 67 ↛ 66line 67 didn't jump to line 66 because the condition on line 67 was always true

68 data.etymology_examples.extend(examples)