1

Removing useless code

This commit is contained in:
Alex Yatskov 2016-05-29 16:18:07 -07:00
parent 5421d0bde7
commit 9819229fcd
3 changed files with 5 additions and 66 deletions

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import util import re
class Translator: class Translator:
@ -27,7 +27,9 @@ class Translator:
def findTerm(self, text, wildcards=False): def findTerm(self, text, wildcards=False):
text = util.sanitize(text, wildcards=wildcards) if wildcards:
text = re.sub(u'[\*]', u'%', text)
text = re.sub(u'[\?]', u'_', text)
groups = {} groups = {}
for i in xrange(len(text), 0, -1): for i in xrange(len(text), 0, -1):
@ -60,8 +62,6 @@ class Translator:
def findKanji(self, text): def findKanji(self, text):
text = util.sanitize(text, kana=False)
processed = {} processed = {}
results = [] results = []
for c in text: for c in text:

View File

@ -1,61 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Alex Yatskov
# This module is based on Rikaichan code written by Jonathan Zarate
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
def isHiragana(c):
return 0x3040 <= ord(c) < 0x30a0
def isKatakana(c):
return 0x30a0 <= ord(c) < 0x3100
def isKana(c):
return isHiragana(c) or isKatakana(c)
def isKanji(c):
return 0x4e00 <= ord(c) < 0x9fb0 or 0x3400 <= ord(c) < 0x4dc0
def isJapanese(c):
return isKana(c) or isKanji(c) or c == u''
def sanitize(text, kana=True, wildcards=False):
if kana:
checker = isJapanese
else:
checker = isKanji
if wildcards:
text = re.sub(u'[\*]', u'%', text)
text = re.sub(u'[\?]', u'_', text)
overrides = [u'%', u'_']
else:
overrides = []
result = u''
for c in text:
if checker(c) or c in overrides:
result += c
return result

View File

@ -497,7 +497,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
cursor = self.textContent.textCursor() cursor = self.textContent.textCursor()
if len(contentSampleFlat) == 0 or not japanese.util.isJapanese(contentSampleFlat[0]): if len(contentSampleFlat) == 0:
cursor.clearSelection() cursor.clearSelection()
self.textContent.setTextCursor(cursor) self.textContent.setTextCursor(cursor)
return return