Skip to content

Commit

Permalink
Merge pull request #438 from xxyzz/fr
Browse files Browse the repository at this point in the history
Extract links in "Dérivés dans d’autres langues" section
  • Loading branch information
xxyzz authored Dec 27, 2023
2 parents ae805ae + 34712de commit 82fc4d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/wiktextract/extractor/fr/linkage.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ def process_derives_autres_list(
for list_item in level_node.find_child_recursively(NodeKind.LIST_ITEM):
lang_code = ""
lang_name = ""
for template_node in list_item.find_child(NodeKind.TEMPLATE):
if template_node.template_name == "L":
lang_code = template_node.template_parameters.get(1)
lang_name = clean_node(wxr, None, template_node)
elif template_node.template_name == "lien":
word = clean_node(wxr, None, template_node)
for node in list_item.find_child(NodeKind.TEMPLATE | NodeKind.LINK):
if isinstance(node, TemplateNode) and node.template_name == "L":
lang_code = node.template_parameters.get(1)
lang_name = clean_node(wxr, None, node)
elif node.kind == NodeKind.LINK or (
isinstance(node, TemplateNode) and node.template_name == "lien"
):
word = clean_node(wxr, None, node)
page_data[-1].derived.append(
Linkage(lang_code=lang_code, lang_name=lang_name, word=word)
)
Expand Down
18 changes: 16 additions & 2 deletions tests/test_fr_linkage.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,23 @@ def test_sense(self):

def test_derives_autres_langues_section(self):
# https://fr.wiktionary.org/wiki/eau#Dérivés_dans_d’autres_langues
# https://fr.wiktionary.org/wiki/caligineux#Dérivés_dans_d’autres_langues
self.wxr.wtp.add_page("Modèle:lien", 10, body="{{{1}}}")
self.wxr.wtp.add_page("Modèle:L", 10, body="Karipúna")
self.wxr.wtp.add_page(
"Modèle:L",
10,
body="""{{#switch: {{{1}}}
| kmv = Karipúna
| en = Anglais
}}""",
)
page_data = [
WordEntry(word="test", lang_code="fr", lang_name="Français")
]
self.wxr.wtp.start_page("eau")
root = self.wxr.wtp.parse(
"* {{L|kmv}} : {{lien|dlo|kmv}}, {{lien|djilo|kmv}}"
"""* {{L|kmv}} : {{lien|dlo|kmv}}, {{lien|djilo|kmv}}
* {{L|en}} : [[caliginous#en|caliginous]]"""
)
extract_linkage(self.wxr, page_data, root, "dérivés autres langues")
self.assertEqual(
Expand All @@ -169,6 +178,11 @@ def test_derives_autres_langues_section(self):
"lang_code": "kmv",
"lang_name": "Karipúna",
},
{
"word": "caliginous",
"lang_code": "en",
"lang_name": "Anglais",
},
],
)

Expand Down

0 comments on commit 82fc4d5

Please sign in to comment.