Coverage for src/wiktextract/extractor/fr/note.py: 81%

29 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-25 10:11 +0000

1from wikitextprocessor.parser import NodeKind, TemplateNode, WikiNode 

2 

3from ...page import clean_node 

4from ...wxr_context import WiktextractContext 

5from .models import WordEntry 

6 

7 

8def extract_note( 

9 wxr: WiktextractContext, 

10 page_data: list[WordEntry], 

11 level_node: WikiNode, 

12) -> None: 

13 # Save paragraph and list item texts to a list of string. 

14 note_paragraph_nodes = [] 

15 for child in level_node.children: 

16 if isinstance(child, TemplateNode) and child.template_name.startswith( 

17 "note-" 

18 ): 

19 process_note_template(wxr, page_data, child) 

20 continue 

21 if isinstance(child, WikiNode) and child.kind == NodeKind.LIST: 

22 for list_item_node in child.find_child(NodeKind.LIST_ITEM): 

23 note_text = clean_node( 

24 wxr, page_data[-1], list_item_node.children 

25 ) 

26 if len(note_text) > 0: 26 ↛ 22line 26 didn't jump to line 22 because the condition on line 26 was always true

27 page_data[-1].notes.append(note_text) 

28 continue 

29 

30 note_paragraph_nodes.append(child) 

31 if isinstance(child, str) and child.endswith("\n"): 31 ↛ 15line 31 didn't jump to line 15 because the condition on line 31 was always true

32 note_text = clean_node(wxr, page_data[-1], note_paragraph_nodes) 

33 if len(note_text) > 0: 

34 page_data[-1].notes.append(note_text) 

35 note_paragraph_nodes.clear() 

36 

37 

38def process_note_template( 

39 wxr: WiktextractContext, 

40 page_data: list[WordEntry], 

41 template_node: TemplateNode, 

42) -> None: 

43 expaned_template = wxr.wtp.parse( 

44 wxr.wtp.node_to_wikitext(template_node), expand_all=True 

45 ) 

46 extract_note(wxr, page_data, expaned_template) 

47 

48 

49def extract_recognition_rate_section( 

50 wxr: WiktextractContext, 

51 word_entry: WordEntry, 

52 level_node: WikiNode, 

53) -> None: 

54 for node in level_node.find_child(NodeKind.TEMPLATE): 

55 if node.template_name == "nl-taux": 

56 # https://fr.wiktionary.org/wiki/Modèle:nl-taux 

57 # save Dutch vocabulary recognition rate category links 

58 clean_node(wxr, word_entry, node)