Coverage for src/wiktextract/extractor/cs/linkage.py: 97%

44 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-13 10:14 +0000

1from wikitextprocessor import LevelNode, NodeKind, TemplateNode, WikiNode 

2 

3from ...page import clean_node 

4from ...wxr_context import WiktextractContext 

5from .models import Form, Linkage, WordEntry 

6from .tags import translate_raw_tags 

7 

8 

9def extract_alt_form_section( 

10 wxr: WiktextractContext, base_data: WordEntry, level_node: LevelNode 

11): 

12 for list_node in level_node.find_child(NodeKind.LIST): 

13 for list_item in list_node.find_child(NodeKind.LIST_ITEM): 

14 raw_tags = [] 

15 for node in list_item.children: 

16 if isinstance(node, WikiNode) and node.kind == NodeKind.LINK: 

17 word = clean_node(wxr, None, node) 

18 if word != "": 18 ↛ 15line 18 didn't jump to line 15 because the condition on line 18 was always true

19 form = Form( 

20 form=word, tags=["alternative"], raw_tags=raw_tags 

21 ) 

22 translate_raw_tags(form) 

23 base_data.forms.append(form) 

24 raw_tags.clear() 

25 elif ( 

26 isinstance(node, TemplateNode) 

27 and node.template_name == "Příznak2" 

28 ): 

29 from .sound import extract_příznak2_template 

30 

31 raw_tags.extend(extract_příznak2_template(wxr, node)) 

32 

33 

34def extract_linkage_section( 

35 wxr: WiktextractContext, 

36 word_entry: WordEntry, 

37 level_node: LevelNode, 

38 linkage_type: str, 

39): 

40 l_list = [] 

41 sense_index = 0 

42 for list_node in level_node.find_child(NodeKind.LIST): 

43 for list_item in list_node.find_child(NodeKind.LIST_ITEM): 

44 if list_item.sarg == "#": 

45 sense_index += 1 

46 l_list.extend( 

47 extract_linkage_list_item(wxr, list_item, sense_index) 

48 ) 

49 getattr(word_entry, linkage_type).extend(l_list) 

50 

51 

52def extract_linkage_list_item( 

53 wxr: WiktextractContext, list_item: WikiNode, sense_index: int 

54) -> list[Linkage]: 

55 l_list = [] 

56 raw_tags = [] 

57 for node in list_item.children: 

58 if isinstance(node, TemplateNode) and node.template_name == "Příznak2": 

59 from .sound import extract_příznak2_template 

60 

61 raw_tags.extend(extract_příznak2_template(wxr, node)) 

62 elif isinstance(node, WikiNode) and node.kind == NodeKind.LINK: 

63 word = clean_node(wxr, None, node) 

64 if word != "": 64 ↛ 57line 64 didn't jump to line 57 because the condition on line 64 was always true

65 l_data = Linkage( 

66 word=word, raw_tags=raw_tags, sense_index=sense_index 

67 ) 

68 translate_raw_tags(l_data) 

69 l_list.append(l_data) 

70 raw_tags.clear() 

71 

72 return l_list