Coverage for src/wiktextract/extractor/es/example.py: 78%
27 statements
« prev ^ index » next coverage.py v7.9.0, created at 2025-06-13 07:43 +0000
« prev ^ index » next coverage.py v7.9.0, created at 2025-06-13 07:43 +0000
1from wikitextprocessor.parser import (
2 NodeKind,
3 TemplateNode,
4 WikiNode,
5)
7from ...page import clean_node
8from ...wxr_context import WiktextractContext
9from ..share import calculate_bold_offsets
10from .models import Example, Sense
13def process_ejemplo_template(
14 wxr: WiktextractContext,
15 sense_data: Sense,
16 template_node: TemplateNode,
17):
18 # https://es.wiktionary.org/wiki/Plantilla:ejemplo
19 # https://es.wiktionary.org/wiki/Módulo:ejemplo
20 example_data = Example(text="")
21 expanded_template = wxr.wtp.parse(
22 wxr.wtp.node_to_wikitext(template_node), expand_all=True
23 )
24 for span_tag in expanded_template.find_html_recursively("span"):
25 span_class = span_tag.attrs.get("class")
26 if "cita" == span_class:
27 if ( 27 ↛ 32line 27 didn't jump to line 32 because the condition on line 27 was never true
28 len(span_tag.children) > 1
29 and isinstance(span_tag.children[-1], WikiNode)
30 and span_tag.children[-1].kind == NodeKind.URL
31 ):
32 example_data.text = clean_node(
33 wxr, None, span_tag.children[:-1]
34 )
35 calculate_bold_offsets(
36 wxr,
37 wxr.wtp.parse(
38 wxr.wtp.node_to_wikitext(span_tag.children[:-1])
39 ),
40 example_data.text,
41 example_data,
42 "bold_text_offsets",
43 extra_node_kind=NodeKind.ITALIC,
44 )
45 example_data.ref = clean_node(wxr, None, span_tag.children[-1])
46 else:
47 example_data.text = clean_node(wxr, None, span_tag)
48 calculate_bold_offsets(
49 wxr,
50 span_tag,
51 example_data.text,
52 example_data,
53 "bold_text_offsets",
54 extra_node_kind=NodeKind.ITALIC,
55 )
56 elif "trad" == span_class:
57 example_data.translation = (
58 clean_node(wxr, None, span_tag).removeprefix("→").strip()
59 )
60 elif "ref" == span_class:
61 example_data.ref = clean_node(wxr, None, span_tag)
63 if len(example_data.text) == 0: 63 ↛ 64line 63 didn't jump to line 64 because the condition on line 63 was never true
64 first_arg = template_node.template_parameters.get(1, "")
65 example_data.text = clean_node(wxr, None, first_arg)
66 calculate_bold_offsets(
67 wxr,
68 wxr.wtp.parse(wxr.wtp.node_to_wikitext(first_arg)),
69 example_data.text,
70 example_data,
71 "bold_text_offsets",
72 extra_node_kind=NodeKind.ITALIC,
73 )
75 if len(example_data.text) > 0: 75 ↛ exitline 75 didn't return from function 'process_ejemplo_template' because the condition on line 75 was always true
76 sense_data.examples.append(example_data)