-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
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,24 @@ | ||
from wikitextprocessor import NodeKind, WikiNode | ||
|
||
from ...page import clean_node | ||
from ...wxr_context import WiktextractContext | ||
from .models import Example, Sense | ||
|
||
|
||
def extract_example_list_item( | ||
wxr: WiktextractContext, sense: Sense, list_item: WikiNode | ||
) -> None: | ||
example = Example() | ||
for node in list_item.children: | ||
if isinstance(node, WikiNode): | ||
match node.kind: | ||
case NodeKind.ITALIC: | ||
example.text = clean_node(wxr, sense, node) | ||
case NodeKind.LIST: | ||
for tr_list_item in node.find_child(NodeKind.LIST_ITEM): | ||
example.translation = clean_node( | ||
wxr, sense, tr_list_item.children | ||
) | ||
|
||
if example.text != "": | ||
sense.examples.append(example) |
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,45 @@ | ||
from unittest import TestCase | ||
|
||
from wikitextprocessor import Wtp | ||
|
||
from wiktextract.config import WiktionaryConfig | ||
from wiktextract.extractor.it.page import parse_page | ||
from wiktextract.wxr_context import WiktextractContext | ||
|
||
|
||
class TestItExample(TestCase): | ||
maxDiff = None | ||
|
||
def setUp(self) -> None: | ||
self.wxr = WiktextractContext( | ||
Wtp(lang_code="it"), | ||
WiktionaryConfig( | ||
dump_file_lang_code="it", capture_language_codes=None | ||
), | ||
) | ||
|
||
def test_list_example(self): | ||
self.wxr.wtp.add_page("Template:-br-", 10, "Bretone") | ||
data = parse_page( | ||
self.wxr, | ||
"dog", | ||
"""== {{-br-}} == | ||
===Sostantivo=== | ||
# mutazione | ||
#* ''Da '''dog''', e '''dog'''.'' | ||
#*: Il tuo cappello, il suo cappello.""", | ||
) | ||
self.assertEqual( | ||
data[0]["senses"], | ||
[ | ||
{ | ||
"glosses": ["mutazione"], | ||
"examples": [ | ||
{ | ||
"text": "Da dog, e dog.", | ||
"translation": "Il tuo cappello, il suo cappello.", | ||
} | ||
], | ||
} | ||
], | ||
) |