def convertToKana(self): inputLen = len(self.lookup.text()) if inputLen > 0: if scripts.script_type(self.lookup.text()) == scripts.Script.Kanji: pass #TODO: ... #if re.search('n{1}', self.lookup.text()[ inputLen - 2: ]) is None: #NB: yes, regexp would be better, yet I failed miserably at it if self.lookup.text()[ inputLen - 1 ] != u'n' and self.lookup.text()[ inputLen - 2:] != u'ny': converted = romkan(self.lookup.text()) #NB: does not convert naninuneno, somehow (purpotedly, 'n' normalization is to blame) self.lookup.setText(converted) #self.testConvert.setText(converted) if self.lookup.text()[ inputLen - 2:] == u'nn': converted = romkan(normalize_double_n(self.lookup.text())) self.lookup.setText(converted) #print self.lookup.text() #scripts.script_type(cluster) == scripts.Script.Kanji: if len(scripts.script_boundaries(self.lookup.text())) == 1: if scripts.script_type(self.lookup.text()) == scripts.Script.Hiragana: self.updateLookupResults(self.lookup.text()) else: self.lookupResults.clearContents() self.lookupResults.setRowCount(0)
def convertToKana(self): inputLen = len(self.reading.text()) if inputLen > 0: if self.reading.text()[ inputLen - 1 ] != u'n' and self.reading.text()[ inputLen - 2:] != u'ny': converted = romkan(self.reading.text()) self.reading.setText(converted) if self.reading.text()[ inputLen - 2:] == u'nn': converted = romkan(normalize_double_n(self.reading.text())) self.reading.setText(converted)
def OnDocumentChanged(properties, context): doc = context.GetBlipById(properties['blipId']).GetDocument() input = doc.GetText() delta = 0 for m in re.finditer(ur'\[([\u0020-\u007e]+?)\]', input): roman = re.sub(ur'\s+', u'', m.group(1)) m2 = re.search(ur'^([HK])(.+)$', roman) if m2: script = m2.group(1) roman = m2.group(2) else: script = None roman = re.sub(ur'(c+)([aiueoy])', lambda m: 'k' * len(m.group(1)) + m.group(2), roman) hira = re.sub(r"'", '', uromkan.romkan(roman.encode('utf-8'))) if script == u'H': output = unicode(hira, 'utf-8') elif script == u'K': output = unicode(uromkan.hirakata(hira), 'utf-8') else: url = 'http://www.social-ime.com/api/?string=%s&charset=utf-8' % urllib.quote(hira) logging.debug(url) res = urlfetch.fetch(url, deadline=10) content = unicode(res.content, 'utf-8') output = u'' for line in content.split(u'\n')[:-1]: output += line.split(u'\t')[0] # Inserts and then deletes, instead of using SetTextInRange, to prevent caret # to move before the inserted string. doc.InsertText(m.start(0) + delta, output) delta += len(output) doc.DeleteRange( document.Range(m.start(0) + delta, m.end(0) + delta)) delta -= len(m.group(0))