Coverage for src/wiktextract/extractor/es/linkage.py: 92%
53 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 (
2 LevelNode,
3 NodeKind,
4 TemplateNode,
5 WikiNode,
6 WikiNodeChildrenList,
7)
9from ...page import clean_node
10from ...wxr_context import WiktextractContext
11from .models import Linkage, WordEntry
12from .section_titles import LINKAGE_TITLES
15def extract_linkage_section(
16 wxr: WiktextractContext,
17 word_entry: WordEntry,
18 level_node: LevelNode,
19 linkage_type: str,
20):
21 for list_item_node in level_node.find_child_recursively(NodeKind.LIST_ITEM):
22 sense_nodes = []
23 after_colon = False
24 words = []
25 for node in list_item_node.children:
26 if after_colon:
27 sense_nodes.append(node)
28 elif isinstance(node, WikiNode) and node.kind == NodeKind.LINK:
29 words.append(clean_node(wxr, None, node))
30 elif isinstance(node, TemplateNode) and node.template_name == "l":
31 words.append(clean_node(wxr, None, node))
32 elif isinstance(node, str) and ":" in node:
33 after_colon = True
34 sense_nodes.append(node[node.index(":") + 1 :])
35 sense = clean_node(wxr, None, sense_nodes)
36 for word in filter(None, words):
37 getattr(word_entry, linkage_type).append(
38 Linkage(word=word, sense=sense)
39 )
42def process_linkage_template(
43 wxr: WiktextractContext,
44 word_entry: WordEntry,
45 template_node: WikiNode,
46):
47 # https://es.wiktionary.org/wiki/Plantilla:sinónimo
48 linkage_type = LINKAGE_TITLES.get(
49 template_node.template_name.removesuffix("s")
50 )
51 for index in range(1, 41): 51 ↛ exitline 51 didn't return from function 'process_linkage_template' because the loop on line 51 didn't complete
52 if index not in template_node.template_parameters:
53 break
54 linkage_data = Linkage(
55 word=clean_node(wxr, None, template_node.template_parameters[index])
56 )
57 if len(word_entry.senses) > 0: 57 ↛ 58line 57 didn't jump to line 58 because the condition on line 57 was never true
58 linkage_data.sense_index = word_entry.senses[-1].sense_index
59 getattr(word_entry, linkage_type).append(linkage_data)
60 process_linkage_template_parameter(
61 wxr, linkage_data, template_node, f"nota{index}"
62 )
63 process_linkage_template_parameter(
64 wxr, linkage_data, template_node, f"alt{index}"
65 )
66 if index == 1:
67 process_linkage_template_parameter(
68 wxr, linkage_data, template_node, "nota"
69 )
70 process_linkage_template_parameter(
71 wxr, linkage_data, template_node, "alt"
72 )
75def process_linkage_template_parameter(
76 wxr: WiktextractContext,
77 linkage_data: Linkage,
78 template_node: TemplateNode,
79 param: str,
80) -> None:
81 if param in template_node.template_parameters:
82 value = clean_node(wxr, None, template_node.template_parameters[param])
83 if param.startswith("nota"):
84 linkage_data.note = value
85 elif param.startswith("alt"): 85 ↛ exitline 85 didn't return from function 'process_linkage_template_parameter' because the condition on line 85 was always true
86 linkage_data.alternative_spelling = value
89def process_linkage_list_children(
90 wxr: WiktextractContext,
91 word_entry: WordEntry,
92 nodes: WikiNodeChildrenList,
93 linkage_type: str,
94):
95 # under gloss list
96 for node in nodes:
97 if isinstance(node, WikiNode) and node.kind == NodeKind.LINK:
98 word = clean_node(wxr, None, node)
99 if len(word) > 0: 99 ↛ 96line 99 didn't jump to line 96 because the condition on line 99 was always true
100 linkage_data = Linkage(word=word)
101 if len(word_entry.senses) > 0: 101 ↛ 102line 101 didn't jump to line 102 because the condition on line 101 was never true
102 linkage_data.sense_index = word_entry.senses[-1].sense_index
103 getattr(word_entry, linkage_type).append(linkage_data)