Skip to content

Commit

Permalink
Perbaiki pengolahan prakategorial jika terautentikasi
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed Mar 20, 2020
1 parent 279fe4c commit b8e2d3c
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions kbbi/kbbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,18 @@ def _init_terkait(self, entri):
self.terkait[jenis] = [k.text for k in kumpulan if k]

def _init_makna(self, entri):
if entri.find(color="darkgreen"):
makna = [entri]
prakategorial = entri.find(color="darkgreen")
if prakategorial:
makna = [prakategorial]
else:
makna = entri.find_all("li")
if self.terautentikasi:
if self.terautentikasi and not prakategorial:
makna = [
m for m in makna if m and "Usulkan makna baru" not in m.text
]
terkait = sum([bool(t) for t in self.terkait.values()])
if terkait:
makna = makna[:-terkait]
terkait = sum([bool(t) for t in self.terkait.values()])
if terkait:
makna = makna[:-terkait]
self.makna = [Makna(m) for m in makna]

def serialisasi(self):
Expand Down Expand Up @@ -322,13 +323,23 @@ def __init__(self, makna_label):
self._init_contoh(makna_label)
self.submakna = self.submakna.split("; ")

def _init_prakategorial(self, prakategorial):
cari = prakategorial.next_sibling
self.submakna = cari.strip()
self.submakna += f" {cari.next_sibling.text.strip()}"

def _init_rujukan(self, rujukan):
self.submakna = f"→ {ambil_teks_dalam_label(rujukan)}"
nomor = rujukan.find("sup")
if nomor:
self.submakna += f" ({nomor.text.strip()})"

def _init_submakna(self, makna_label):
baku = makna_label.find("a")
if baku:
self.submakna = f"→ {ambil_teks_dalam_label(baku)}"
nomor = baku.find("sup")
if nomor:
self.submakna += f" ({nomor.text.strip()})"
rujukan = makna_label.find("a")
if rujukan:
self._init_rujukan(rujukan)
elif makna_label.get("color") == "darkgreen":
self._init_prakategorial(makna_label)
else:
self.submakna = (
"".join(
Expand All @@ -340,17 +351,12 @@ def _init_submakna(self, makna_label):

def _init_kelas(self, makna_label):
kelas = makna_label.find(color="red")
lain = makna_label.find(color="darkgreen")
info = makna_label.find(color="green")

if kelas:
kelas = kelas.find_all("span")
if lain:
kelas = [lain]
self.submakna = lain.next_sibling.strip()
self.submakna += (
f" {makna_label.find(color='grey').get_text().strip()}"
)
if makna_label.get("color") == "darkgreen": # prakategorial
kelas = [makna_label]

self.kelas = []
for k in kelas:
Expand Down

0 comments on commit b8e2d3c

Please sign in to comment.