Skip to content

Commit

Permalink
konlpy apply
Browse files Browse the repository at this point in the history
  • Loading branch information
hyounoon2 committed Jun 18, 2018
1 parent 9f9b5d6 commit 813bea6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions chat/management/commands/makedata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.core.management.base import BaseCommand, CommandError
from chat.models import Chat
from core.chat import remove_special_char
from core.chat import remove_special_char, apply_nlpy
import subprocess
import os
import time
Expand Down Expand Up @@ -30,7 +30,7 @@ def make_train_data(self, t_input, t_output):
rep = open(t_output, 'w')

for chat in chats:
req.write(remove_special_char(chat.question)+'\n')
req.write(apply_nlpy(remove_special_char(chat.question))+'\n')
rep.write(chat.answer +'\n')

req.close()
Expand Down
12 changes: 11 additions & 1 deletion core/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from . import model_helper

from . import constants
from konlpy.tag import Mecab

from .utils import vocab_utils

Expand All @@ -24,11 +25,20 @@

FLAGS = constants

mecab = Mecab()

def remove_special_char(s_input):
return re.sub("([.,!?\"':;)(])", "", s_input)


def apply_nlpy(s_input):
"""
형태소 분석을 통해서 교육 효율을 높인다.
"""
result = mecab.morphs(s_input)
return ' '.join(result)


class ChatBot:
ckpt = None
hparams = None
Expand All @@ -47,7 +57,7 @@ def _do_reply(self, input):
if len(input) == 0:
return ''

infer_data = [remove_special_char(input)]
infer_data = [apply_nlpy(remove_special_char(input))]

self.sess.run(
self.infer_model.iterator.initializer,
Expand Down

0 comments on commit 813bea6

Please sign in to comment.