Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[id] add section templates and extract etymology section #1050

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 111 additions & 1 deletion src/wiktextract/data/overrides/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"need_pre_expand": true
},
"Templat:-syn-": {
"body": "====Sinonim====\n",
"body": "====Sinonim====\n{{#ifeq:{{{1|}}}|id||{{-syn2-|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|{{{6|}}}|{{{7|}}}|{{{8|}}}|{{{9|}}}|{{{10|}}}|{{{11|}}}|{{{12|}}}|{{{13|}}}|{{{14|}}}|{{{15|}}}|{{{16|}}}|{{{17|}}}|{{{18|}}}|{{{19|}}}|{{{20|}}}|{{{21|}}}|{{{22|}}}|{{{23|}}}|{{{24|}}}|{{{25|}}}|{{{26|}}}|{{{27|}}}|{{{28|}}}|{{{29|}}}|{{{30|}}}}}}}\n",
"namespace_id": 10,
"need_pre_expand": true
},
Expand All @@ -23,11 +23,21 @@
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-drv-multi-": {
"body": "====Kata turunan====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-frasa-": {
"body": "====Frasa dan kata majemuk====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-frasa2-": {
"body": "====Frasa dan kata majemuk====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-lihat-": {
"body": "====Lihat pula====\n",
"namespace_id": 10,
Expand All @@ -47,5 +57,105 @@
"body": "====Terjemahan====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-ref-": {
"body": "====Referensi====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-akar-": {
"body": "===Akar kata===\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-akhir-": {
"body": "===Akhiran===[[Kategori:{{{1|id}}}:Akhiran]]\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-alt-": {
"body": "====Alternatif====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-awal-": {
"body": "===Awalan===[[Kategori:{{{1|id}}}:Awalan]]\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-cog-": {
"body": "====Kognat====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-desc-": {
"body": "====Turunan====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-huruf-": {
"body": "===Huruf===\n''huruf kecil'' [[{{lc:{{PAGENAME}}}}]]; ''huruf besar'' [[{{uc:{{PAGENAME}}}}]][[Kategori:Huruf]]\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-inisialisme-": {
"body": "===Inisialisme===[[Kategori:{{{1|id}}}:Inisialisme]]\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-keluarga-": {
"body": "====Keluarga kata====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-kiasan-": {
"body": "====Kiasan====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-kontraksi-": {
"body": "===Kontraksi===[[Kategori:{{{1}}}:Kontraksi]]\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-lafal-": {
"body": "====Pelafalan====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-noun-": {
"body": "===Nomina===[[Kategori:{{{1|id}}}:{{nom}}]]\n'''{{PAGENAME}}''' (''plural'' '''[[{{PAGENAME}}-{{PAGENAME}}]]''', ''posesif orang pertama'' '''{{PAGENAME}}[[-ku|ku]]''', ''posesif orang kedua'' '''{{PAGENAME}}[[-mu|mu]]''', ''posesif orang ketiga'' '''{{PAGENAME}}[[-nya|nya]]''')\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-peribahasa-": {
"body": "====Peribahasa====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-singkatan-": {
"body": "===Singkatan===[[Kategori:{{{1}}}:Singkatan]]\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-syn-multi-": {
"body": "====Sinonim====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-ucap-": {
"body": "====Pengucapan====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:-var-": {
"body": "====Variasi====\n",
"namespace_id": 10,
"need_pre_expand": true
},
"Templat:=drv=": {
"body": "====Frasa turunan====\n",
"namespace_id": 10,
"need_pre_expand": true
}
}
7 changes: 5 additions & 2 deletions src/wiktextract/extractor/id/analyze_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# https://id.wiktionary.org/wiki/Wikikamus:Penjelasan_tataletak_entri
# https://id.wiktionary.org/wiki/Kategori:Templat_kelas_kata
# https://id.wiktionary.org/wiki/Kategori:Templat_umum
SECTION_TITLE_TEMPLATES = {
"Templat:-adj-",
"Templat:-adv-",
Expand Down Expand Up @@ -33,8 +34,8 @@
"Templat:=pron=",
"Templat:=pronom=",
"Templat:=verb=",
"Templat:nomina -nya",
"Templat:ulang",
"Templat:-sdd-",
}


Expand All @@ -48,6 +49,8 @@ def analyze_template(wtp: Wtp, page: Page) -> tuple[set[str], bool]:
"Templat:sisipan ",
"Templat:ulang ",
"Templat:verba ",
"Templat:nomina ",
)
),
)
or page.title.endswith(("proper noun", "-nm")),
)
25 changes: 25 additions & 0 deletions src/wiktextract/extractor/id/etymology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from wikitextprocessor.parser import LEVEL_KIND_FLAGS, LevelNode, NodeKind

from ...page import clean_node
from ...wxr_context import WiktextractContext
from .models import WordEntry


def extract_etymology_section(
wxr: WiktextractContext,
word_entry: WordEntry,
level_node: LevelNode,
) -> None:
for list_node in level_node.find_child(NodeKind.LIST):
for list_item in list_node.find_child(NodeKind.LIST_ITEM):
e_str = clean_node(wxr, word_entry, list_item.children)
if e_str != "":
word_entry.etymology_texts.append(e_str)
if len(word_entry.etymology_texts) == 0:
e_str = clean_node(
wxr,
word_entry,
list(level_node.invert_find_child(LEVEL_KIND_FLAGS)),
)
if e_str != "":
word_entry.etymology_texts.append(e_str)
1 change: 1 addition & 0 deletions src/wiktextract/extractor/id/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ class WordEntry(IndonesianBaseModel):
categories: list[str] = []
tags: list[str] = []
raw_tags: list[str] = []
etymology_texts: list[str] = []
5 changes: 5 additions & 0 deletions src/wiktextract/extractor/id/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ...page import clean_node
from ...wxr_context import WiktextractContext
from .etymology import extract_etymology_section
from .models import Sense, WordEntry
from .pos import extract_pos_section
from .section_titles import POS_DATA
Expand All @@ -20,6 +21,10 @@ def parse_section(
wxr.wtp.start_subsection(title_text)
if title_text in POS_DATA:
extract_pos_section(wxr, page_data, base_data, level_node, title_text)
elif title_text == "Etimologi":
extract_etymology_section(
wxr, page_data[-1] if len(page_data) > 0 else base_data, level_node
)

for next_level in level_node.find_child(LEVEL_KIND_FLAGS):
parse_section(wxr, page_data, base_data, next_level)
Expand Down
9 changes: 9 additions & 0 deletions src/wiktextract/extractor/id/section_titles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# https://id.wiktionary.org/wiki/Kategori:Templat_kelas_kata
# https://id.wiktionary.org/wiki/Kategori:Templat_umum
POS_DATA = {
"Adjektiva": {"pos": "adj"},
"Adverbia": {"pos": "adv"},
Expand All @@ -16,4 +17,12 @@
"Pronomina": {"pos": "pron"},
"Subjungsi": {"pos": "conj"},
"Verba": {"pos": "verb"},
"Akar kata": {"pos": "root", "tags": ["morpheme"]},
"Akhiran": {"pos": "suffix", "tags": ["morpheme"]},
"Huruf": {"pos": "character", "tags": ["letter"]},
"Inisialisme": {"pos": "abbrev", "tags": ["abbreviation"]},
"Awalan": {"pos": "prefix", "tags": ["morpheme"]},
"Kontraksi": {"pos": "contraction", "tags": ["contraction"]},
"Singkatan": {"pos": "abbrev", "tags": ["abbreviation"]},
"Nama diri": {"pos": "name"},
}