Coverage for src/wiktextract/extractor/it/etymology.py: 89%
33 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-13 10:14 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-13 10:14 +0000
1from wikitextprocessor.parser import LEVEL_KIND_FLAGS, LevelNode, NodeKind
3from ...page import clean_node
4from ...wxr_context import WiktextractContext
5from ..share import calculate_bold_offsets
6from .models import Example, WordEntry
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 for list_node in level_node.find_child(NodeKind.LIST):
15 for list_item in list_node.find_child(NodeKind.LIST_ITEM):
16 e_str = clean_node(wxr, None, list_item.children)
17 if e_str != "": 17 ↛ 15line 17 didn't jump to line 15 because the condition on line 17 was always true
18 etymology_texts.append(e_str)
20 if len(etymology_texts) == 0:
21 e_str = clean_node(
22 wxr,
23 None,
24 list(
25 level_node.invert_find_child(
26 LEVEL_KIND_FLAGS, include_empty_str=True
27 )
28 ),
29 )
30 if e_str != "": 30 ↛ 33line 30 didn't jump to line 33 because the condition on line 30 was always true
31 etymology_texts.append(e_str)
33 for data in page_data:
34 if data.lang_code == page_data[-1].lang_code: 34 ↛ 33line 34 didn't jump to line 33 because the condition on line 34 was always true
35 data.etymology_texts.extend(etymology_texts)
38def extract_citation_section(
39 wxr: WiktextractContext, page_data: list[WordEntry], level_node: LevelNode
40):
41 examples = []
42 for t_node in level_node.find_child(NodeKind.TEMPLATE):
43 if t_node.template_name.lower() == "quote": 43 ↛ 42line 43 didn't jump to line 42 because the condition on line 43 was always true
44 example = Example()
45 first_arg = wxr.wtp.parse(
46 wxr.wtp.node_to_wikitext(t_node.template_parameters.get(1, ""))
47 )
48 example.text = clean_node(wxr, None, first_arg)
49 example.ref = clean_node(
50 wxr, None, t_node.template_parameters.get(2, "")
51 )
52 calculate_bold_offsets(
53 wxr, first_arg, example.text, example, "bold_text_offsets"
54 )
55 if example.text != "": 55 ↛ 42line 55 didn't jump to line 42 because the condition on line 55 was always true
56 examples.append(example)
57 for data in page_data:
58 if data.lang_code == page_data[-1].lang_code: 58 ↛ 57line 58 didn't jump to line 57 because the condition on line 58 was always true
59 data.etymology_examples.extend(examples)