Coverage for src/wiktextract/extractor/nl/example.py: 79%
39 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 import NodeKind, TemplateNode, WikiNode
3from ...page import clean_node
4from ...wxr_context import WiktextractContext
5from .models import Example, Sense
7EXAMPLE_TEMPLATES = frozenset({"bijv-1", "bijv-2", "bijv-e", "citeer"})
10def extract_example_list_item(
11 wxr: WiktextractContext, sense: Sense, list_item: WikiNode
12) -> None:
13 has_template = False
14 for t_node in list_item.find_child(NodeKind.TEMPLATE):
15 extract_example_template(wxr, sense, t_node)
16 has_template = True
17 if not has_template:
18 example_text = clean_node(wxr, None, list_item.children)
19 if example_text != "": 19 ↛ exitline 19 didn't return from function 'extract_example_list_item' because the condition on line 19 was always true
20 sense.examples.append(Example(text=example_text))
23def extract_example_template(
24 wxr: WiktextractContext, sense: Sense, node: TemplateNode
25) -> None:
26 if node.template_name == "bijv-1": 26 ↛ 28line 26 didn't jump to line 28 because the condition on line 26 was never true
27 # https://nl.wiktionary.org/wiki/Sjabloon:bijv-1
28 e_text = clean_node(wxr, None, node.template_parameters.get(1, ""))
29 if len(e_text) > 0:
30 sense.examples.append(Example(text=e_text))
31 elif node.template_name in ["bijv-2", "bijv-e"]:
32 e_text = clean_node(wxr, None, node.template_parameters.get(1, ""))
33 if len(e_text) > 0: 33 ↛ exitline 33 didn't return from function 'extract_example_template' because the condition on line 33 was always true
34 e_trans = clean_node(wxr, None, node.template_parameters.get(2, ""))
35 sense.examples.append(Example(text=e_text, translation=e_trans))
36 elif node.template_name == "citeer": 36 ↛ exitline 36 didn't return from function 'extract_example_template' because the condition on line 36 was always true
37 extract_citeer_template(wxr, sense, node)
40def extract_citeer_template(
41 wxr: WiktextractContext, sense: Sense, node: TemplateNode
42) -> None:
43 # https://nl.wiktionary.org/wiki/Sjabloon:citeer
44 e_text = clean_node(wxr, None, node.template_parameters.get("citaat", ""))
45 if len(e_text) == 0: 45 ↛ 49line 45 didn't jump to line 49 because the condition on line 45 was always true
46 e_text = clean_node(
47 wxr, None, node.template_parameters.get("passage", "")
48 )
49 if len(e_text) == 0: 49 ↛ 50line 49 didn't jump to line 50 because the condition on line 49 was never true
50 return
51 e_trans = clean_node(
52 wxr, None, node.template_parameters.get("vertaling", "")
53 )
54 example = Example(text=e_text, translation=e_trans)
55 expanded_node = wxr.wtp.parse(
56 wxr.wtp.node_to_wikitext(node), expand_all=True
57 )
58 for ref_tag in expanded_node.find_html_recursively("ref"): 58 ↛ 61line 58 didn't jump to line 61 because the loop on line 58 didn't complete
59 example.ref = clean_node(wxr, sense, ref_tag.children)
60 break
61 sense.examples.append(example)