Skip to content

Commit

Permalink
[ko] extract "l" template in proverbs section lists
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed Oct 30, 2024
1 parent e012012 commit d9ef41b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/wiktextract/extractor/ko/linkage.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,31 @@ def extract_proverb_section(
break
if linkage.word != "":
word_entry.proverbs.append(linkage)
else:
for t_node in list_item.find_child(NodeKind.TEMPLATE):
if t_node.template_name in ["l", "연결"]:
extract_l_template(wxr, word_entry, t_node, "proverbs")


def extract_l_template(
wxr: WiktextractContext,
word_entry: WordEntry,
t_node: TemplateNode,
linkage_type: str,
) -> None:
# https://ko.wiktionary.org/wiki/틀:연결
# https://en.wiktionary.org/wiki/Template:link
for word_arg in [3, 2]:
if word_arg in t_node.template_parameters:
word = clean_node(wxr, None, t_node.template_parameters[word_arg])
if word == "":
break
linkage = Linkage(word=word)
for sense_arg in ["t", 4]:
if sense_arg in t_node.template_parameters:
linkage.sense = clean_node(
wxr, None, t_node.template_parameters[sense_arg]
)
break
getattr(word_entry, linkage_type).append(linkage)
break
20 changes: 20 additions & 0 deletions tests/test_ko_linkage.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,23 @@ def test_zh_pinyin(self):
{"word": "土产", "roman": "tǔchǎn", "sense": "흙, 땅"},
],
)

def test_l_template(self):
data = parse_page(
self.wxr,
"병신",
"""== 중국어 ==
=== 명사 ===
# 다쳐서
==== 관용구 ====
* {{l|ko|병신도 제 재미에 산다|t=사람은 각자 자기 잘 난 맛에 산다라는 뜻}}""",
)
self.assertEqual(
data[0]["proverbs"],
[
{
"word": "병신도 제 재미에 산다",
"sense": "사람은 각자 자기 잘 난 맛에 산다라는 뜻",
}
],
)

0 comments on commit d9ef41b

Please sign in to comment.