Coverage for src/wiktextract/extractor/tr/example.py: 88%

89 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-15 05:18 +0000

1from wikitextprocessor import NodeKind, TemplateNode, WikiNode 

2 

3from ...page import clean_node 

4from ...wxr_context import WiktextractContext 

5from ..share import calculate_bold_offsets 

6from .linkage import ( 

7 GLOSS_LIST_LINKAGE_TEMPLATES, 

8 extract_gloss_list_linkage_template, 

9) 

10from .models import Example, WordEntry 

11 

12 

13def extract_example_list_item( 

14 wxr: WiktextractContext, 

15 word_entry: WordEntry, 

16 list_item: WikiNode, 

17 example: Example, 

18) -> None: 

19 for node in list_item.children: 

20 if isinstance(node, TemplateNode): 

21 if node.template_name in ["ux", "uxi"]: 

22 extract_ux_template(wxr, word_entry.lang_code, node, example) 

23 elif node.template_name == "örnek": 

24 extract_örnek_template(wxr, word_entry.lang_code, node, example) 

25 elif node.template_name in GLOSS_LIST_LINKAGE_TEMPLATES: 

26 extract_gloss_list_linkage_template(wxr, word_entry, node) 

27 elif node.template_name.startswith("AT:"): 27 ↛ 19line 27 didn't jump to line 19 because the condition on line 27 was always true

28 extract_at_template(wxr, example, node) 

29 elif isinstance(node, WikiNode): 

30 match node.kind: 

31 case NodeKind.LIST: 

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

33 extract_example_list_item( 

34 wxr, word_entry, child_list_item, example 

35 ) 

36 case NodeKind.ITALIC: 36 ↛ 19line 36 didn't jump to line 19 because the pattern on line 36 always matched

37 italic_str = clean_node(wxr, None, node) 

38 if italic_str != "": 38 ↛ 19line 38 didn't jump to line 19 because the condition on line 38 was always true

39 if example.text == "": 

40 example.text = italic_str 

41 calculate_bold_offsets( 

42 wxr, 

43 node, 

44 italic_str, 

45 example, 

46 "bold_text_offsets", 

47 ) 

48 else: 

49 example.translation = italic_str 

50 calculate_bold_offsets( 

51 wxr, 

52 node, 

53 italic_str, 

54 example, 

55 "bold_translation_offsets", 

56 ) 

57 

58 

59def extract_ux_template( 

60 wxr: WiktextractContext, 

61 lang_code: str, 

62 t_node: TemplateNode, 

63 example: Example, 

64) -> None: 

65 # https://tr.wiktionary.org/wiki/Şablon:ux 

66 e_lang_code = clean_node(wxr, None, t_node.template_parameters.get(1, "")) 

67 second_arg = t_node.template_parameters.get(2, "") 

68 second_arg_text = clean_node(wxr, None, second_arg) 

69 if e_lang_code == lang_code: 69 ↛ 78line 69 didn't jump to line 78 because the condition on line 69 was always true

70 example.text = second_arg_text 

71 calculate_bold_offsets( 

72 wxr, 

73 wxr.wtp.parse(wxr.wtp.node_to_wikitext(second_arg)), 

74 second_arg_text, 

75 example, 

76 "bold_text_offsets", 

77 ) 

78 elif e_lang_code == "tr": 

79 example.translation = second_arg_text 

80 calculate_bold_offsets( 

81 wxr, 

82 wxr.wtp.parse(wxr.wtp.node_to_wikitext(second_arg)), 

83 second_arg_text, 

84 example, 

85 "bold_translation_offsets", 

86 ) 

87 for index in [4, 5]: 

88 ref = clean_node(wxr, None, t_node.template_parameters.get(index, "")) 

89 if ref != "": 89 ↛ 90line 89 didn't jump to line 90 because the condition on line 89 was never true

90 example.ref = ref 

91 third_arg = t_node.template_parameters.get(3, "") 

92 tr_value = clean_node(wxr, None, third_arg) 

93 if tr_value != "": 93 ↛ exitline 93 didn't return from function 'extract_ux_template' because the condition on line 93 was always true

94 example.translation = tr_value 

95 calculate_bold_offsets( 

96 wxr, 

97 wxr.wtp.parse(wxr.wtp.node_to_wikitext(third_arg)), 

98 tr_value, 

99 example, 

100 "bold_translation_offsets", 

101 ) 

102 

103 

104def extract_örnek_template( 

105 wxr: WiktextractContext, 

106 lang_code: str, 

107 t_node: TemplateNode, 

108 example: Example, 

109) -> None: 

110 # https://tr.wiktionary.org/wiki/Şablon:örnek 

111 e_lang_code = clean_node( 

112 wxr, None, t_node.template_parameters.get("dil", "") 

113 ) 

114 first_arg = t_node.template_parameters.get(1, "") 

115 first_arg_text = clean_node(wxr, None, first_arg) 

116 if e_lang_code == lang_code: 

117 example.text = first_arg_text 

118 calculate_bold_offsets( 

119 wxr, 

120 wxr.wtp.parse(wxr.wtp.node_to_wikitext(first_arg)), 

121 first_arg_text, 

122 example, 

123 "bold_text_offsets", 

124 ) 

125 elif e_lang_code == "tr": 125 ↛ 134line 125 didn't jump to line 134 because the condition on line 125 was always true

126 example.translation = first_arg_text 

127 calculate_bold_offsets( 

128 wxr, 

129 wxr.wtp.parse(wxr.wtp.node_to_wikitext(first_arg)), 

130 first_arg_text, 

131 example, 

132 "bold_translation_offsets", 

133 ) 

134 for index in [2, 3]: 

135 ref = clean_node(wxr, None, t_node.template_parameters.get(index, "")) 

136 if ref != "": 136 ↛ 137line 136 didn't jump to line 137 because the condition on line 136 was never true

137 example.ref = ref 

138 t_arg = t_node.template_parameters.get("t", "") 

139 t_value = clean_node(wxr, None, t_arg) 

140 if t_value != "": 

141 example.translation = t_value 

142 calculate_bold_offsets( 

143 wxr, 

144 wxr.wtp.parse(wxr.wtp.node_to_wikitext(t_arg)), 

145 t_value, 

146 example, 

147 "bold_translation_offsets", 

148 ) 

149 

150 

151def extract_at_template( 

152 wxr: WiktextractContext, example: Example, t_node: TemplateNode 

153) -> None: 

154 # Şablon:AT:Kur'an 

155 if any( 

156 arg in t_node.template_parameters for arg in ["pasaj", "text", "metin"] 

157 ): 

158 for arg in ["pasaj", "text", "metin"]: 158 ↛ 170line 158 didn't jump to line 170 because the loop on line 158 didn't complete

159 if arg in t_node.template_parameters: 159 ↛ 158line 159 didn't jump to line 158 because the condition on line 159 was always true

160 arg_value = t_node.template_parameters[arg] 

161 example.text = clean_node(wxr, None, arg_value) 

162 calculate_bold_offsets( 

163 wxr, 

164 wxr.wtp.parse(wxr.wtp.node_to_wikitext(arg_value)), 

165 example.text, 

166 example, 

167 "bold_text_offsets", 

168 ) 

169 break 

170 for arg in ["anlam", "mana", "mânâ", "t", "tercüme"]: 170 ↛ 196line 170 didn't jump to line 196 because the loop on line 170 didn't complete

171 if arg in t_node.template_parameters: 

172 arg_value = t_node.template_parameters[arg] 

173 example.translation = clean_node(wxr, None, arg_value) 

174 calculate_bold_offsets( 

175 wxr, 

176 wxr.wtp.parse(wxr.wtp.node_to_wikitext(arg_value)), 

177 example.translation, 

178 example, 

179 "bold_translation_offsets", 

180 ) 

181 break 

182 else: 

183 for arg in ["anlam", "mana", "mânâ", "t", "tercüme"]: 

184 if arg in t_node.template_parameters: 

185 arg_value = t_node.template_parameters[arg] 

186 example.text = clean_node(wxr, None, arg_value) 

187 calculate_bold_offsets( 

188 wxr, 

189 wxr.wtp.parse(wxr.wtp.node_to_wikitext(arg_value)), 

190 example.text, 

191 example, 

192 "bold_text_offsets", 

193 ) 

194 break 

195 

196 example.ref = clean_node(wxr, None, t_node).splitlines()[0]