-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1008 from xxyzz/ku
[ku] extract other forms sections
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from wikitextprocessor import NodeKind, TemplateNode, WikiNode | ||
|
||
from ...page import clean_node | ||
from ...wxr_context import WiktextractContext | ||
from .models import Form, WordEntry | ||
|
||
|
||
def extract_other_form_section( | ||
wxr: WiktextractContext, | ||
word_entry: WordEntry, | ||
level_node: WikiNode, | ||
) -> None: | ||
for list_node in level_node.find_child(NodeKind.LIST): | ||
for list_item in list_node.find_child(NodeKind.LIST_ITEM): | ||
for t_node in list_item.find_child(NodeKind.TEMPLATE): | ||
if t_node.template_name.startswith("ku-"): | ||
extract_ku_form_template(wxr, word_entry, t_node) | ||
elif t_node.template_name == "g": | ||
extract_g_template(wxr, word_entry, t_node) | ||
|
||
|
||
def extract_ku_form_template( | ||
wxr: WiktextractContext, | ||
word_entry: WordEntry, | ||
t_node: TemplateNode, | ||
) -> None: | ||
expanded_node = wxr.wtp.parse( | ||
wxr.wtp.node_to_wikitext(t_node), expand_all=True | ||
) | ||
form = Form(form="") | ||
for index, span_tag in enumerate(expanded_node.find_html("span")): | ||
if index == 0: | ||
form.raw_tags.append(clean_node(wxr, None, span_tag)) | ||
elif index == 1: | ||
form.form = clean_node(wxr, None, span_tag) | ||
if form.form != "": | ||
word_entry.forms.append(form) | ||
|
||
|
||
def extract_g_template( | ||
wxr: WiktextractContext, | ||
word_entry: WordEntry, | ||
t_node: TemplateNode, | ||
) -> None: | ||
form = Form( | ||
form=clean_node( | ||
wxr, | ||
None, | ||
t_node.template_parameters.get( | ||
2, t_node.template_parameters.get("cuda", "") | ||
), | ||
), | ||
roman=clean_node(wxr, None, t_node.template_parameters.get("tr", "")), | ||
translation=clean_node( | ||
wxr, None, t_node.template_parameters.get("w", "") | ||
), | ||
) | ||
if form.form != "": | ||
word_entry.forms.append(form) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from unittest import TestCase | ||
|
||
from wikitextprocessor import Wtp | ||
|
||
from wiktextract.config import WiktionaryConfig | ||
from wiktextract.extractor.ku.page import parse_page | ||
from wiktextract.wxr_context import WiktextractContext | ||
|
||
|
||
class TestKuLinkage(TestCase): | ||
maxDiff = None | ||
|
||
def setUp(self) -> None: | ||
self.wxr = WiktextractContext( | ||
Wtp(lang_code="ku"), | ||
WiktionaryConfig( | ||
dump_file_lang_code="ku", capture_language_codes=None | ||
), | ||
) | ||
|
||
def tearDown(self): | ||
self.wxr.wtp.close_db_conn() | ||
|
||
def test_ku_ar(self): | ||
self.wxr.wtp.add_page("Şablon:ziman", 10, "Kurmancî") | ||
self.wxr.wtp.add_page( | ||
"Şablon:ku-ar", | ||
10, | ||
"""<span class="Latn" lang="ku">[[kurdî-erebî#Kurmancî|kurdî-erebî]]</span>: <span class="Arab" lang="ku">[[کووچک#Kurmancî|کووچک]]</span>‎""", | ||
) | ||
page_data = parse_page( | ||
self.wxr, | ||
"kûçik", | ||
"""== {{ziman|ku}} == | ||
=== Navdêr === | ||
# [[heywan|Heywanek]] | ||
==== Bi alfabeyên din ==== | ||
* {{ku-ar|کووچک}}""", | ||
) | ||
self.assertEqual( | ||
page_data[0]["forms"], | ||
[{"form": "کووچک", "raw_tags": ["kurdî-erebî"]}], | ||
) |