Esempio n. 1
0
 def msgindex(self):
     self.fwd_lookup = {}
     self.words = collections.Counter()
     self.msgtok = {}
     for mid, value in self.msgs.items():
         src, text, date, fwd_src, fwd_date, reply_id, media = value
         self.fwd_lookup[(src, date)] = mid
         tok = self.msgtok[mid] = tuple(self.msgpreprocess(zhconv.convert(self.tc.truecase(re_url.sub('', stripreaction(text))), 'zh-hans')))
         for w in frozenset(t.lower() for t in tok):
             self.words[w] += 1
     self.words = dict(self.words)
Esempio n. 2
0
def cmd_ime(expr, chatid, replyid, msg):
    '''/ime [pinyin] Simple Pinyin IME.'''
    tinput = ''
    if 'reply_to_message' in msg:
        tinput = msg['reply_to_message'].get('text', '')
    tinput = (expr or tinput).strip()
    if len(tinput) > 200:
        tinput = tinput[:200] + '…'
    if not tinput:
        sendmsg('Syntax error. Usage: ' + cmd_ime.__doc__, chatid, replyid)
        return
    res = zhconv.convert(simpleime.pinyininput(tinput), 'zh-hans')
    sendmsg(res, chatid, replyid)
Esempio n. 3
0
def getsayingbytext(text='', mode='r'):
    global SAY_P
    with SAY_LCK:
        text = (mode + ' '.join(mosesproxy.cut(zhconv.convert(text, 'zh-hans'), HMM=False)[:60]).strip()).encode('utf-8') + b'\n'
        try:
            SAY_P.stdin.write(text)
            SAY_P.stdin.flush()
            say = SAY_P.stdout.readline().strip().decode('utf-8')
        except BrokenPipeError:
            SAY_P = subprocess.Popen(SAY_CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd='vendor')
            SAY_P.stdin.write(text)
            SAY_P.stdin.flush()
            say = SAY_P.stdout.readline().strip().decode('utf-8')
    return say
Esempio n. 4
0
 def msgindex(self):
     self.fwd_lookup = {}
     self.words = collections.Counter()
     self.msgtok = {}
     for mid, value in self.msgs.items():
         src, text, date, fwd_src, fwd_date, reply_id, media = value
         self.fwd_lookup[(src, date)] = mid
         tok = self.msgtok[mid] = tuple(
             self.msgpreprocess(
                 zhconv.convert(
                     self.tc.truecase(re_url.sub('', stripreaction(text))),
                     'zh-hans')))
         for w in frozenset(t.lower() for t in tok):
             self.words[w] += 1
     self.words = dict(self.words)
Esempio n. 5
0
def cmd_cc(expr):
    if zhconv.issimp(expr):
        return zhconv.convert(expr, 'zh-hant')
    else:
        return zhconv.convert(expr, 'zh-hans')
Esempio n. 6
0
def cmd_ime(expr):
    return zhconv.convert(simpleime.pinyininput(expr.lower()), 'zh-hans')