mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
fix import path on pykakasi
This commit is contained in:
parent
e6e2c066bd
commit
d432d4b46a
@ -16,24 +16,23 @@ Tranliterate the string from unicode characters to ASCII in Chinese and others.
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from calibre.ebooks.unihandecode.unidecoder import Unidecoder
|
|
||||||
from calibre.ebooks.unihandecode.jadecoder import Jadecoder
|
|
||||||
from calibre.ebooks.unihandecode.krdecoder import Krdecoder
|
|
||||||
from calibre.ebooks.unihandecode.vndecoder import Vndecoder
|
|
||||||
|
|
||||||
class Unihandecoder(object):
|
class Unihandecoder(object):
|
||||||
preferred_encoding = None
|
preferred_encoding = None
|
||||||
decoder = None
|
decoder = None
|
||||||
|
|
||||||
def __init__(self, lang="zh", encoding='utf-8'):
|
def __init__(self, lang="zh", encoding='utf-8'):
|
||||||
self.preferred_encoding = encoding
|
self.preferred_encoding = encoding
|
||||||
if lang is "ja":
|
if lang is u"ja":
|
||||||
|
from calibre.ebooks.unihandecode.jadecoder import Jadecoder
|
||||||
self.decoder = Jadecoder()
|
self.decoder = Jadecoder()
|
||||||
elif lang is "kr":
|
elif lang is u"kr":
|
||||||
|
from calibre.ebooks.unihandecode.krdecoder import Krdecoder
|
||||||
self.decoder = Krdecoder()
|
self.decoder = Krdecoder()
|
||||||
elif lang is "vn":
|
elif lang is u"vn":
|
||||||
|
from calibre.ebooks.unihandecode.vndecoder import Vndecoder
|
||||||
self.decoder = Vndecoder()
|
self.decoder = Vndecoder()
|
||||||
else: #zh and others
|
else: #zh and others
|
||||||
|
from calibre.ebooks.unihandecode.unidecoder import Unidecoder
|
||||||
self.decoder = Unidecoder()
|
self.decoder = Unidecoder()
|
||||||
|
|
||||||
def decode(self, text):
|
def decode(self, text):
|
||||||
@ -55,5 +54,6 @@ def unidecode(text):
|
|||||||
'''
|
'''
|
||||||
backword compatibility to unidecode
|
backword compatibility to unidecode
|
||||||
'''
|
'''
|
||||||
|
from calibre.ebooks.unihandecode.unidecoder import Unidecoder
|
||||||
decoder = Unihandecoder()
|
decoder = Unihandecoder()
|
||||||
return decoder.decode(text)
|
return decoder.decode(text)
|
||||||
|
@ -34,7 +34,7 @@ class Jadecoder(Unidecoder):
|
|||||||
|
|
||||||
def decode(self, text):
|
def decode(self, text):
|
||||||
try:
|
try:
|
||||||
dummy = text.encode('euc-jp') # test if text contains only Japanese and ASCII characters.
|
dummy = text.encode("eucjp") # test if text contains only Japanese and ASCII characters.
|
||||||
result=self.kakasi.do(text)
|
result=self.kakasi.do(text)
|
||||||
return re.sub('[^\x00-\x7f]', lambda x: self.replace_point(x.group()),result)
|
return re.sub('[^\x00-\x7f]', lambda x: self.replace_point(x.group()),result)
|
||||||
except:
|
except:
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
# * 02111-1307, USA.
|
# * 02111-1307, USA.
|
||||||
# */
|
# */
|
||||||
|
|
||||||
from jisyo import jisyo
|
from calibre.ebooks.unihandecode.pykakasi.jisyo import jisyo
|
||||||
|
|
||||||
class H2a (object):
|
class H2a (object):
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
# * 02111-1307, USA.
|
# * 02111-1307, USA.
|
||||||
# */
|
# */
|
||||||
|
|
||||||
from jisyo import jisyo
|
from calibre.ebooks.unihandecode.pykakasi.jisyo import jisyo
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class J2H (object):
|
class J2H (object):
|
||||||
|
@ -14,10 +14,10 @@ class jisyo (object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if self.kanwadict is None:
|
if self.kanwadict is None:
|
||||||
dictpath = os.path.join('unihandecode','pykakasi','kanwadict2.db')
|
dictpath = os.path.join('calibre','ebooks','unihandecode','pykakasi','kanwadict2.db')
|
||||||
self.kanwadict = anydbm.open(dictpath,'r')
|
self.kanwadict = anydbm.open(dictpath,'r')
|
||||||
if self.itaijidict is None:
|
if self.itaijidict is None:
|
||||||
itaijipath = os.path.join('unihandecode','pykakasi','itaijidict2.pickle')
|
itaijipath = os.path.join('calibre','ebooks','unihandecode','pykakasi','itaijidict2.pickle')
|
||||||
itaiji_pkl = open(itaijipath, 'rb')
|
itaiji_pkl = open(itaijipath, 'rb')
|
||||||
self.itaijidict = load(itaiji_pkl)
|
self.itaijidict = load(itaiji_pkl)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
# * 02111-1307, USA.
|
# * 02111-1307, USA.
|
||||||
# */
|
# */
|
||||||
|
|
||||||
from jisyo import jisyo
|
from calibre.ebooks.unihandecode.pykakasi.jisyo import jisyo
|
||||||
|
|
||||||
class K2a (object):
|
class K2a (object):
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import sys, os
|
import sys, os
|
||||||
from j2h import J2H
|
from calibre.ebooks.unihandecode.pykakasi.j2h import J2H
|
||||||
from h2a import H2a
|
from calibre.ebooks.unihandecode.pykakasi.h2a import H2a
|
||||||
from k2a import K2a
|
from calibre.ebooks.unihandecode.pykakasi.k2a import K2a
|
||||||
|
|
||||||
class kakasi(object):
|
class kakasi(object):
|
||||||
|
|
||||||
@ -37,12 +37,11 @@ class kakasi(object):
|
|||||||
h2a = None
|
h2a = None
|
||||||
k2a = None
|
k2a = None
|
||||||
|
|
||||||
def __init__(self, mode="-J2a -H2a -K2a"):
|
def __init__(self):
|
||||||
#now we don't allow mode selection
|
|
||||||
self.j2h = J2H()
|
self.j2h = J2H()
|
||||||
self.h2a = H2a()
|
self.h2a = H2a()
|
||||||
self.k2a = K2a()
|
self.k2a = K2a()
|
||||||
return
|
|
||||||
|
|
||||||
def do(self, text):
|
def do(self, text):
|
||||||
otext = ''
|
otext = ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user