-
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 #465 from xxyzz/ru
Extract linkage tags for ru edition
- Loading branch information
Showing
3 changed files
with
85 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
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,47 @@ | ||
from unittest import TestCase | ||
|
||
from wikitextprocessor import Wtp | ||
from wiktextract.config import WiktionaryConfig | ||
from wiktextract.extractor.ru.linkage import extract_linkages | ||
from wiktextract.extractor.ru.models import WordEntry | ||
from wiktextract.wxr_context import WiktextractContext | ||
|
||
|
||
class TestLinkage(TestCase): | ||
def setUp(self) -> None: | ||
self.wxr = WiktextractContext( | ||
Wtp(lang_code="ru"), WiktionaryConfig(dump_file_lang_code="ru") | ||
) | ||
|
||
def tearDown(self) -> None: | ||
self.wxr.wtp.close_db_conn() | ||
|
||
def test_linkage(self): | ||
word_entry = WordEntry( | ||
word="русский", pos="adj", lang_code="ru", lang="Русский" | ||
) | ||
self.wxr.wtp.start_page("русский") | ||
self.wxr.wtp.add_page("Шаблон:помета", 10, "<span>экзоэтнонимы</span>") | ||
self.wxr.wtp.add_page( | ||
"Шаблон:собир.", | ||
10, | ||
'[[Викисловарь:Условные сокращения|<span title="собирательное">собир.</span>]]', | ||
) | ||
self.wxr.wtp.add_page( | ||
"Шаблон:уничиж.", | ||
10, | ||
'[[Викисловарь:Условные сокращения|<span title="уничижительное">уничиж.</span>]]', | ||
) | ||
root = self.wxr.wtp.parse( | ||
"# {{помета|экзоэтнонимы}}: [[кацап]], [[москаль]], [[шурави]]; {{собир.|-}}, {{уничиж.|-}}: [[русня]]" | ||
) | ||
extract_linkages(self.wxr, word_entry, "synonyms", root.children[0]) | ||
self.assertEqual( | ||
[d.model_dump(exclude_defaults=True) for d in word_entry.synonyms], | ||
[ | ||
{"word": "кацап", "tags": ["экзоэтнонимы"]}, | ||
{"word": "москаль", "tags": ["экзоэтнонимы"]}, | ||
{"word": "шурави", "tags": ["экзоэтнонимы"]}, | ||
{"word": "русня", "tags": ["собирательное", "уничижительное"]}, | ||
], | ||
) |