Coverage for src/wiktextract/extractor/nl/example.py: 91%
52 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 import NodeKind, TemplateNode, WikiNode
3from ...page import clean_node
4from ...wxr_context import WiktextractContext
5from ..share import calculate_bold_offsets
6from .models import Example, Sense
8EXAMPLE_TEMPLATES = frozenset({"bijv-1", "bijv-2", "bijv-e", "citeer"})
11def extract_example_list_item(
12 wxr: WiktextractContext, sense: Sense, list_item: WikiNode
13) -> None:
14 has_template = False
15 for t_node in list_item.find_child(NodeKind.TEMPLATE):
16 extract_example_template(wxr, sense, t_node)
17 has_template = True
18 if not has_template:
19 example_text = clean_node(wxr, None, list_item.children)
20 if example_text != "": 20 ↛ exitline 20 didn't return from function 'extract_example_list_item' because the condition on line 20 was always true
21 sense.examples.append(Example(text=example_text))
24def extract_example_template(
25 wxr: WiktextractContext, sense: Sense, node: TemplateNode
26) -> None:
27 if node.template_name == "bijv-1":
28 # https://nl.wiktionary.org/wiki/Sjabloon:bijv-1
29 first_arg = node.template_parameters.get(1, "")
30 e_text = clean_node(wxr, None, first_arg)
31 if len(e_text) > 0: 31 ↛ exitline 31 didn't return from function 'extract_example_template' because the condition on line 31 was always true
32 e_data = Example(text=e_text)
33 calculate_bold_offsets(
34 wxr,
35 wxr.wtp.parse(wxr.wtp.node_to_wikitext(first_arg)),
36 e_text,
37 e_data,
38 "bold_text_offsets",
39 )
40 sense.examples.append(e_data)
41 elif node.template_name in ["bijv-2", "bijv-e"]:
42 first_arg = node.template_parameters.get(1, "")
43 e_text = clean_node(wxr, None, first_arg)
44 if len(e_text) > 0: 44 ↛ exitline 44 didn't return from function 'extract_example_template' because the condition on line 44 was always true
45 e_data = Example(text=e_text)
46 calculate_bold_offsets(
47 wxr,
48 wxr.wtp.parse(wxr.wtp.node_to_wikitext(first_arg)),
49 e_text,
50 e_data,
51 "bold_text_offsets",
52 )
53 second_arg = node.template_parameters.get(2, "")
54 e_data.translation = clean_node(wxr, None, second_arg)
55 calculate_bold_offsets(
56 wxr,
57 wxr.wtp.parse(wxr.wtp.node_to_wikitext(second_arg)),
58 e_data.translation,
59 e_data,
60 "bold_translation_offsets",
61 )
62 sense.examples.append(e_data)
63 elif node.template_name == "citeer": 63 ↛ exitline 63 didn't return from function 'extract_example_template' because the condition on line 63 was always true
64 extract_citeer_template(wxr, sense, node)
67def extract_citeer_template(
68 wxr: WiktextractContext, sense: Sense, node: TemplateNode
69) -> None:
70 # https://nl.wiktionary.org/wiki/Sjabloon:citeer
71 e_data = Example()
72 for text_arg_name in ["citaat", "passage"]: 72 ↛ 84line 72 didn't jump to line 84 because the loop on line 72 didn't complete
73 text_arg = node.template_parameters.get(text_arg_name, "")
74 e_data.text = clean_node(wxr, None, text_arg)
75 if e_data.text != "":
76 calculate_bold_offsets(
77 wxr,
78 wxr.wtp.parse(wxr.wtp.node_to_wikitext(text_arg)),
79 e_data.text,
80 e_data,
81 "bold_text_offsets",
82 )
83 break
84 tr_arg = node.template_parameters.get("vertaling", "")
85 e_data.translation = clean_node(wxr, None, tr_arg)
86 calculate_bold_offsets(
87 wxr,
88 wxr.wtp.parse(wxr.wtp.node_to_wikitext(tr_arg)),
89 e_data.translation,
90 e_data,
91 "bold_translation_offsets",
92 )
93 expanded_node = wxr.wtp.parse(
94 wxr.wtp.node_to_wikitext(node), expand_all=True
95 )
96 for ref_tag in expanded_node.find_html_recursively("ref"): 96 ↛ 99line 96 didn't jump to line 99 because the loop on line 96 didn't complete
97 e_data.ref = clean_node(wxr, sense, ref_tag.children)
98 break
99 if e_data.text != "": 99 ↛ exitline 99 didn't return from function 'extract_citeer_template' because the condition on line 99 was always true
100 sense.examples.append(e_data)