Korean text: sort-of-working version, in need of validation

This commit is contained in:
Jean-Francois Dockes
2020-03-22 15:49:24 +01:00
parent 384e3a1087
commit c9667b5ba7
3 changed files with 79 additions and 31 deletions
+4 -2
View File
@@ -201,7 +201,9 @@ class CmdTalk:
# Common main routine for testing: either run the normal protocol
# engine or a local loop.
# engine or a local loop. This means that you can call
# cmdtalk.main(proto,processor) instead of proto.mainloop(processor)
# from your module, and get the benefits of command line testing
def main(proto, processor):
if len(sys.argv) == 1:
proto.mainloop(processor)
@@ -220,7 +222,7 @@ def main(proto, processor):
if len(args) == 0 or len(args) % 2 != 0:
usage()
params = dict()
for i in range(len(args)/2):
for i in range(int(len(args)/2)):
params[args[2*i]] = args[2*i+1]
res = processor.process(params)
+13 -9
View File
@@ -28,25 +28,29 @@
import sys
import cmdtalk
from konlpy.tag import Okt
from konlpy.tag import Okt,Kkma
class Processor(object):
def __init__(self, proto):
self.proto = proto
self.okt = Okt()
self.tagger = Okt()
#self.tagger = Kkma()
def process(self, params):
if 'data' not in params:
return {'error':'No data field in parameters'}
pos = self.okt.pos(params['data'])
pos = self.tagger.pos(params['data'])
#proto.log("%s" % pos)
output = ""
text = ""
tags = ""
for e in pos:
if e[1] == 'Noun' or e[1] == 'Verb' or e[1] == 'Adjective' or \
e[1] == 'Adverb':
output += e[0] + '^'
return {'data': output}
word = e[0]
word = word.replace('\t', ' ')
text += word + "\t"
tags += e[1] + "\t"
return {'text': text, 'tags': tags}
proto = cmdtalk.CmdTalk()
processor = Processor(proto)
proto.mainloop(processor)
cmdtalk.main(proto, processor)