Coverage for src/wiktextract/extractor/zh/etymology.py: 85%
32 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 LEVEL_KIND_FLAGS,
3 NodeKind,
4 TemplateNode,
5 WikiNode,
6)
8from ...page import clean_node
9from ...wxr_context import WiktextractContext
10from .models import Example, WordEntry
13def extract_etymology(
14 wxr: WiktextractContext,
15 page_data: list[WordEntry],
16 base_data: WordEntry,
17 level_node: WikiNode,
18) -> None:
19 from .example import extract_template_zh_x
21 etymology_nodes = []
22 level_node_index = len(level_node.children)
23 for next_level_index, next_level_node in level_node.find_child( 23 ↛ 26line 23 didn't jump to line 26 because the loop on line 23 never started
24 LEVEL_KIND_FLAGS, True
25 ):
26 level_node_index = next_level_index
27 break
28 for etymology_node in level_node.children[:level_node_index]:
29 if isinstance(
30 etymology_node, TemplateNode
31 ) and etymology_node.template_name in ["zh-x", "zh-q"]:
32 for example_data in extract_template_zh_x(
33 wxr, etymology_node, Example()
34 ):
35 base_data.etymology_examples.append(example_data)
36 clean_node(wxr, base_data, etymology_node)
37 elif ( 37 ↛ 41line 37 didn't jump to line 41 because the condition on line 37 was never true
38 isinstance(etymology_node, TemplateNode)
39 and etymology_node.template_name.lower() == "rfe"
40 ):
41 pass # missing etymology
42 elif (
43 isinstance(etymology_node, WikiNode)
44 and etymology_node.kind == NodeKind.LIST
45 ):
46 has_zh_x = False
47 for template_node in etymology_node.find_child_recursively(
48 NodeKind.TEMPLATE
49 ):
50 if template_node.template_name in ["zh-x", "zh-q"]:
51 has_zh_x = True
52 for example_data in extract_template_zh_x(
53 wxr, template_node, Example()
54 ):
55 base_data.etymology_examples.append(example_data)
56 clean_node(wxr, base_data, template_node)
57 if not has_zh_x: 57 ↛ 58line 57 didn't jump to line 58 because the condition on line 57 was never true
58 etymology_nodes.append(etymology_node)
59 else:
60 etymology_nodes.append(etymology_node)
62 etymology_text = clean_node(wxr, base_data, etymology_nodes)
63 if len(etymology_text) > 0: 63 ↛ exitline 63 didn't return from function 'extract_etymology' because the condition on line 63 was always true
64 base_data.etymology_text = etymology_text