From 6bd9e4e4136b2482ee43d6a8fb4ea316a9a23ce8 Mon Sep 17 00:00:00 2001 From: Soumt Nam Date: Tue, 12 Sep 2023 21:44:28 +0900 Subject: [PATCH] feat: add korean postposition process --- modules/Ai_tem.py | 25 +++++++++++++++---------- modules/Amumal.py | 4 +++- modules/KJosa.py | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 modules/KJosa.py diff --git a/modules/Ai_tem.py b/modules/Ai_tem.py index f37f3b9..b379160 100644 --- a/modules/Ai_tem.py +++ b/modules/Ai_tem.py @@ -216,14 +216,14 @@ items = [ ] ands = [ - '에 빙의한', - '에 들어가는', - '에 묻힌', - '을 연상시키는', - ' 같은', - '로 가장한', - '에 올려진', - ' 옆에 있는', + [None, None, '에 빙의한'], + [None, None, '에 들어가는'], + [None, None, '에 묻힌'], + ['을', '를', ' 연상시키는'], + [None, None, ' 같은'], + ['으로', '로', ' 가장한'], + [None, None, '에 올려진'], + [None, None, ' 옆에 있는'], ]; from mipac.models import Note @@ -233,7 +233,7 @@ class AiTem(ModuleInterface): self.name = "Ai-tem" self.regex_pattern = ".*Test_AI-tem" - self.funcs["generate"] = self._generate() + self.funcs["generate"] = self._generate print("[Ai-tem] Ai-like item generator, Ai-tem V1 loaded.") async def execute_module(self, ctx: Note): @@ -241,7 +241,12 @@ class AiTem(ModuleInterface): await ctx.api.action.reply(str(self._generate()), visibility="home") def _generate(self): - return random.choice(itemPrefixes) + ' ' + random.choice(items) + ((random.choice(ands) + ' ' + random.choice(itemPrefixes) + ' ' + random.choice(items)) if random.choice([True, False]) else "") + item1_sel = random.choice(items) + con_sel = random.choice(ands) + item1_comp = self.manager.require("K-Josa").get_func("process_josa")(item1_sel, con_sel[0], con_sel[1]) + con_sel[2] + + print(item1_sel, item1_comp) + return random.choice(itemPrefixes) + ' ' + ((item1_comp + ' ' + random.choice(itemPrefixes) + ' ' + random.choice(items)) if random.choice([True, False]) else item1_sel) def module_ready(self): print("[Ai-tem] Module Ready.") diff --git a/modules/Amumal.py b/modules/Amumal.py index e36bd5f..2e90eb9 100644 --- a/modules/Amumal.py +++ b/modules/Amumal.py @@ -47,7 +47,9 @@ class Amumal(ModuleInterface): @tasks.loop(seconds=600.0) async def amumal_task(self): aitem = str(self.manager.require("Ai-tem").get_func("generate")()) + kjosa = self.manager.require("K-Josa").get_func("process_josa") + if random.choice([True, False]): - await self.manager.bot.client.note.action.send(random.choice(Amumals["notes"] + [aitem + "이 가지고 싶어요...", "오늘 산책 중에 " + aitem + "을 봤어요!"]), visibility="home") + await self.manager.bot.client.note.action.send(random.choice(Amumals["notes"] + [kjosa(aitem, "이", "가") + " 가지고 싶어요...", "오늘 산책 중에 " + kjosa(aitem, "을", "를") + " 봤어요!"]), visibility="home") print("[Amumal] Sent Amumal!") diff --git a/modules/KJosa.py b/modules/KJosa.py new file mode 100644 index 0000000..8eabfc8 --- /dev/null +++ b/modules/KJosa.py @@ -0,0 +1,20 @@ +from module_interface import ModuleInterface + +from mipac.models import Note +class KJosa(ModuleInterface): + def __init__(self): + super().__init__() + self.name = "K-Josa" + self.regex_pattern = None + + self.funcs["process_josa"] = self._process + print("[K-Josa] Korean postposition processor, K-Josa V1 loaded.") + + async def execute_module(self, ctx: Note): + pass + + def _process(self, w, t, f): + return (w + ((t if (ord(w[-1])- 44032 % 28 == 0) else f ) if (44032 <= ord(w[-1]) <= 55203) else f"{t}({f})")) if t and f else w + + def module_ready(self): + print("[K-josa] Module Ready.")