-
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 #882 from xxyzz/nl
[nl] extract "-nlnoun-" inflection table template
- Loading branch information
Showing
6 changed files
with
189 additions
and
4 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,48 @@ | ||
from wikitextprocessor import NodeKind, TemplateNode | ||
|
||
from ...page import clean_node | ||
from ...wxr_context import WiktextractContext | ||
from .models import Form, WordEntry | ||
from .tags import translate_raw_tags | ||
|
||
|
||
def extract_inflection_template( | ||
wxr: WiktextractContext, word_entry: WordEntry, t_node: TemplateNode | ||
) -> None: | ||
if t_node.template_name == "-nlnoun-": | ||
extract_nlnoun_template(wxr, word_entry, t_node) | ||
|
||
|
||
def extract_nlnoun_template( | ||
wxr: WiktextractContext, word_entry: WordEntry, t_node: TemplateNode | ||
) -> None: | ||
# https://nl.wiktionary.org/wiki/Sjabloon:-nlnoun- | ||
expanded_node = wxr.wtp.parse( | ||
wxr.wtp.node_to_wikitext(t_node), expand_all=True | ||
) | ||
column_headers = [] | ||
for table_node in expanded_node.find_child(NodeKind.TABLE): | ||
for row_node in table_node.find_child(NodeKind.TABLE_ROW): | ||
for header_node in row_node.find_child(NodeKind.TABLE_HEADER_CELL): | ||
header_text = clean_node(wxr, None, header_node) | ||
if header_text != "": | ||
column_headers.append(header_text) | ||
row_header = "" | ||
for col_index, data_node in enumerate( | ||
row_node.find_child(NodeKind.TABLE_CELL) | ||
): | ||
if col_index == 0: | ||
row_header = clean_node(wxr, None, data_node) | ||
else: | ||
form_str = clean_node(wxr, None, data_node) | ||
if form_str not in ["", wxr.wtp.title]: | ||
form = Form(form=form_str) | ||
if row_header not in ["", "naamwoord"]: | ||
form.raw_tags.append(row_header) | ||
if col_index - 1 < len(column_headers): | ||
form.raw_tags.append(column_headers[col_index - 1]) | ||
translate_raw_tags(form) | ||
word_entry.forms.append(form) | ||
|
||
for link_node in expanded_node.find_child(NodeKind.LINK): | ||
clean_node(wxr, word_entry, link_node) |
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
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,110 @@ | ||
from unittest import TestCase | ||
|
||
from wikitextprocessor import Wtp | ||
|
||
from wiktextract.config import WiktionaryConfig | ||
from wiktextract.extractor.nl.page import parse_page | ||
from wiktextract.wxr_context import WiktextractContext | ||
|
||
|
||
class TestNlInflection(TestCase): | ||
maxDiff = None | ||
|
||
def setUp(self) -> None: | ||
self.wxr = WiktextractContext( | ||
Wtp(lang_code="nl"), | ||
WiktionaryConfig( | ||
dump_file_lang_code="nl", | ||
capture_language_codes=None, | ||
), | ||
) | ||
|
||
def tearDown(self) -> None: | ||
self.wxr.wtp.close_db_conn() | ||
|
||
def test_nlnoun_different_pos(self): | ||
self.wxr.wtp.add_page( | ||
"Sjabloon:-nlnoun-", | ||
10, | ||
"""{| class="infobox" | ||
|- | ||
! | ||
! [[enkelvoud]] | ||
! [[meervoud]] | ||
|- | ||
| class="infoboxrijhoofding" | [[zelfstandig naamwoord|naamwoord]] | ||
| loop | ||
| [[lopen]] | ||
|- | ||
| class="infoboxrijhoofding" | [[verkleinwoord]] | ||
| [[loopje]] | ||
| [[loopjes]] | ||
|}[[Categorie:Zelfstandig naamwoord in het Nederlands]][[Categorie:Telbaar]]""", | ||
) | ||
data = parse_page( | ||
self.wxr, | ||
"loop", | ||
"""==Nederlands== | ||
=====Woordafbreking===== | ||
*loop | ||
{{-nlnoun-|{{pn}}|[[lopen]]|[[{{pn}}je]]|[[{{pn}}jes]]}} | ||
====Zelfstandig naamwoord==== | ||
{{-l-|m}} | ||
#voorste deel van een [[wapen]] | ||
====Werkwoord==== | ||
{{1ps|lopen}}""", | ||
) | ||
self.assertEqual(len(data), 2) | ||
self.assertEqual( | ||
data[0]["categories"], | ||
["Zelfstandig naamwoord in het Nederlands", "Telbaar"], | ||
) | ||
self.assertEqual( | ||
data[0]["forms"], | ||
[ | ||
{"form": "lopen", "tags": ["plural"]}, | ||
{"form": "loopje", "tags": ["diminutive", "singular"]}, | ||
{"form": "loopjes", "tags": ["diminutive", "plural"]}, | ||
], | ||
) | ||
self.assertTrue("categories" not in data[1]) | ||
self.assertTrue("forms" not in data[1]) | ||
|
||
def test_nlnoun_same_pos(self): | ||
self.wxr.wtp.add_page( | ||
"Sjabloon:-nlnoun-", | ||
10, | ||
"""{| class="infobox" | ||
|- | ||
! | ||
! [[enkelvoud]] | ||
! [[meervoud]] | ||
|- | ||
| class="infoboxrijhoofding" | [[zelfstandig naamwoord|naamwoord]] | ||
| hond | ||
| [[honden]] | ||
|- | ||
| class="infoboxrijhoofding" | [[verkleinwoord]] | ||
| [[hondje]] | ||
| [[hondjes]] | ||
|}[[Categorie:Zelfstandig naamwoord in het Nederlands]][[Categorie:Telbaar]] | ||
""", | ||
) | ||
data = parse_page( | ||
self.wxr, | ||
"hond", | ||
"""==Nederlands== | ||
=====Woordherkomst en -opbouw===== | ||
*[A] uiteindelijk | ||
{{-nlnoun-|hond|[[honden]]|[[hondje]]|[[hondjes]]}} | ||
====Zelfstandig naamwoord==== | ||
[A] {{-l-|m}} | ||
# zoogdier | ||
====Zelfstandig naamwoord==== | ||
[B] {{-l-|o}} | ||
# landmaat""", | ||
) | ||
self.assertEqual(len(data), 2) | ||
self.assertEqual(data[0]["categories"], data[1]["categories"]) | ||
self.assertEqual(len(data[0]["forms"]), 3) | ||
self.assertEqual(data[0]["forms"], data[1]["forms"]) |