Coverage for src/wiktextract/extractor/pl/note.py: 92%
33 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
1import re
2from typing import Optional
4from wikitextprocessor import NodeKind, WikiNode
6from ...page import clean_node
7from ...wxr_context import WiktextractContext
8from .models import Note, WordEntry
11def extract_note_section(
12 wxr: WiktextractContext,
13 page_data: list[WordEntry],
14 base_data: WordEntry,
15 level_node: WikiNode,
16) -> None:
17 from .page import match_sense_index
19 notes = []
20 for list_item in level_node.find_child_recursively(NodeKind.LIST_ITEM):
21 note = process_note_list_item(wxr, list_item)
22 if note is not None: 22 ↛ 20line 22 didn't jump to line 20 because the condition on line 22 was always true
23 notes.append(note)
24 for data in page_data:
25 if data.lang_code == base_data.lang_code: 25 ↛ 24line 25 didn't jump to line 24 because the condition on line 25 was always true
26 for note in notes:
27 if note.sense_index == "" or match_sense_index(
28 note.sense_index, data
29 ):
30 data.notes.append(note)
33def process_note_list_item(
34 wxr: WiktextractContext, list_item: WikiNode
35) -> Optional[Note]:
36 sense_index = ""
37 note_nodes = []
38 for node in list_item.children:
39 if isinstance(node, str):
40 m = re.search(r"\([\d\s,-.]+\)", node)
41 if m is not None:
42 sense_index = m.group(0).strip("()")
43 note_nodes.append(node[m.end() :])
44 else:
45 note_nodes.append(node)
46 else:
47 note_nodes.append(node)
48 note_text = clean_node(wxr, None, note_nodes)
49 if len(note_text) > 0: 49 ↛ 51line 49 didn't jump to line 51 because the condition on line 49 was always true
50 return Note(sense_index=sense_index, text=note_text)
51 return None