Coverage for src/wiktextract/extractor/pt/head_line.py: 96%
18 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
1from wikitextprocessor import NodeKind, TemplateNode, WikiNode
3from ...page import clean_node
4from ...wxr_context import WiktextractContext
5from .models import WordEntry
6from .tags import translate_raw_tags
9def extract_head_line_nodes(
10 wxr: WiktextractContext,
11 word_entry: WordEntry,
12 nodes: list[WikiNode | str],
13) -> None:
14 for node in nodes:
15 if isinstance(node, TemplateNode):
16 match node.template_name:
17 case "g" | "gramática":
18 extract_gramática_template(wxr, word_entry, node)
21def extract_gramática_template(
22 wxr: WiktextractContext,
23 word_entry: WordEntry,
24 t_node: TemplateNode,
25) -> None:
26 # https://pt.wiktionary.org/wiki/Predefinição:gramática
27 expanded_node = wxr.wtp.parse(
28 wxr.wtp.node_to_wikitext(t_node), expand_all=True
29 )
30 for italic_node in expanded_node.find_child(NodeKind.ITALIC):
31 raw_tag = clean_node(wxr, None, italic_node)
32 if raw_tag != "": 32 ↛ 30line 32 didn't jump to line 30 because the condition on line 32 was always true
33 word_entry.raw_tags.append(raw_tag)
34 translate_raw_tags(word_entry)