Coverage for src/wiktextract/extractor/it/etymology.py: 89%
30 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.parser import LEVEL_KIND_FLAGS, LevelNode, NodeKind
3from ...page import clean_node
4from ...wxr_context import WiktextractContext
5from .models import Example, WordEntry
8def extract_etymology_section(
9 wxr: WiktextractContext, page_data: list[WordEntry], level_node: LevelNode
10) -> None:
11 # https://it.wiktionary.org/wiki/Aiuto:Etimologia
12 etymology_texts = []
13 for list_node in level_node.find_child(NodeKind.LIST):
14 for list_item in list_node.find_child(NodeKind.LIST_ITEM):
15 e_str = clean_node(wxr, None, list_item.children)
16 if e_str != "": 16 ↛ 14line 16 didn't jump to line 14 because the condition on line 16 was always true
17 etymology_texts.append(e_str)
19 if len(etymology_texts) == 0:
20 e_str = clean_node(
21 wxr, None, list(level_node.invert_find_child(LEVEL_KIND_FLAGS))
22 )
23 if e_str != "": 23 ↛ 26line 23 didn't jump to line 26 because the condition on line 23 was always true
24 etymology_texts.append(e_str)
26 for data in page_data:
27 if data.lang_code == page_data[-1].lang_code: 27 ↛ 26line 27 didn't jump to line 26 because the condition on line 27 was always true
28 data.etymology_texts.extend(etymology_texts)
31def extract_citation_section(
32 wxr: WiktextractContext, page_data: list[WordEntry], level_node: LevelNode
33) -> None:
34 examples = []
35 for t_node in level_node.find_child(NodeKind.TEMPLATE):
36 if t_node.template_name.lower() == "quote": 36 ↛ 35line 36 didn't jump to line 35 because the condition on line 36 was always true
37 example = Example()
38 example.text = clean_node(
39 wxr, None, t_node.template_parameters.get(1, "")
40 )
41 example.ref = clean_node(
42 wxr, None, t_node.template_parameters.get(2, "")
43 )
44 if example.text != "": 44 ↛ 35line 44 didn't jump to line 35 because the condition on line 44 was always true
45 examples.append(example)
46 for data in page_data:
47 if data.lang_code == page_data[-1].lang_code: 47 ↛ 46line 47 didn't jump to line 46 because the condition on line 47 was always true
48 data.etymology_examples.extend(examples)