Coverage for src/wiktextract/extractor/ku/sound.py: 88%

50 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-04 10:58 +0000

1from wikitextprocessor import LevelNode, NodeKind, TemplateNode, WikiNode 

2 

3from ...page import clean_node 

4from ...wxr_context import WiktextractContext 

5from ..share import set_sound_file_url_fields 

6from .models import Sound, WordEntry 

7from .tags import translate_raw_tags 

8 

9 

10def extract_sound_section( 

11 wxr: WiktextractContext, word_entry: WordEntry, level_node: LevelNode 

12) -> None: 

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

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

15 extract_sound_list_item(wxr, word_entry, list_item) 

16 

17 

18def extract_sound_list_item( 

19 wxr: WiktextractContext, word_entry: WordEntry, list_item: WikiNode 

20) -> None: 

21 for node in list_item.children: 

22 if isinstance(node, TemplateNode): 

23 if node.template_name in ["ku-IPA", "IPA-ku"]: 

24 extract_ku_ipa_template(wxr, word_entry, node) 

25 elif node.template_name in ["deng", "sound"]: 

26 extract_deng_template(wxr, word_entry, node) 

27 elif node.template_name == "ku-kîte": 27 ↛ 21line 27 didn't jump to line 21 because the condition on line 27 was always true

28 extract_ku_kîte(wxr, word_entry, node) 

29 elif isinstance(node, WikiNode) and node.kind == NodeKind.LIST: 29 ↛ 30line 29 didn't jump to line 30 because the condition on line 29 was never true

30 for child_list_item in node.find_child(NodeKind.LIST_ITEM): 

31 extract_sound_list_item(wxr, word_entry, child_list_item) 

32 

33 

34def extract_ku_ipa_template( 

35 wxr: WiktextractContext, word_entry: WordEntry, t_node: TemplateNode 

36) -> None: 

37 expanded_node = wxr.wtp.parse( 

38 wxr.wtp.node_to_wikitext(t_node), expand_all=True 

39 ) 

40 for span_tag in expanded_node.find_html( 

41 "span", attr_name="class", attr_value="IPA" 

42 ): 

43 sound = Sound(ipa=clean_node(wxr, None, span_tag)) 

44 if sound.ipa != "": 44 ↛ 40line 44 didn't jump to line 40 because the condition on line 44 was always true

45 word_entry.sounds.append(sound) 

46 clean_node(wxr, word_entry, expanded_node) 

47 

48 

49def extract_deng_template( 

50 wxr: WiktextractContext, word_entry: WordEntry, t_node: TemplateNode 

51) -> None: 

52 sound = Sound( 

53 ipa=clean_node(wxr, None, t_node.template_parameters.get("ipa", "")) 

54 ) 

55 raw_tag = clean_node( 

56 wxr, 

57 None, 

58 t_node.template_parameters.get( 

59 4, t_node.template_parameters.get("dever", "") 

60 ), 

61 ) 

62 for r_tag in raw_tag.split(","): 

63 r_tag = r_tag.strip() 

64 if r_tag != "": 

65 sound.raw_tags.append(r_tag) 

66 filename = clean_node(wxr, None, t_node.template_parameters.get(2, "")) 

67 if filename != "": 67 ↛ 71line 67 didn't jump to line 71 because the condition on line 67 was always true

68 set_sound_file_url_fields(wxr, filename, sound) 

69 translate_raw_tags(sound) 

70 word_entry.sounds.append(sound) 

71 clean_node(wxr, word_entry, t_node) 

72 

73 

74def extract_ku_kîte( 

75 wxr: WiktextractContext, word_entry: WordEntry, t_node: TemplateNode 

76) -> None: 

77 expanded_node = wxr.wtp.parse( 

78 wxr.wtp.node_to_wikitext(t_node), expand_all=True 

79 ) 

80 for index, node in enumerate(expanded_node.children): 80 ↛ exitline 80 didn't return from function 'extract_ku_kîte' because the loop on line 80 didn't complete

81 if isinstance(node, str) and ":" in node: 

82 hyphenation = clean_node( 

83 wxr, 

84 None, 

85 [node[node.index(":") + 1 :]] 

86 + expanded_node.children[index + 1 :], 

87 ).strip() 

88 if hyphenation != "": 88 ↛ 90line 88 didn't jump to line 90 because the condition on line 88 was always true

89 word_entry.hyphenation = hyphenation 

90 break