Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
support passport roman table
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed May 25, 2014
1 parent c7fc54c commit f7d7fd0
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 10 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ Version 0.23 (25, May, 2014)
-v --version -h --help
-O --output: output file
-I --input: input file

- Change default behavior as almost same
as original kakasi

- Zenkaku numbers conversion
- Passport roman conversion table

Version 0.22 (3, May, 2014)

Expand Down
4 changes: 2 additions & 2 deletions kakasi
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def main():
's':False, 'C':False
}
values = ["a","E","H","K",None]
romanvals = {"h":"Hepburn", "k":"Kunrei"}
romanvals = {"h":"Hepburn", "k":"Kunrei", "p":"Passport"}
for o, a in opts:
if o in ["-v","--version"]:
show_version()
Expand All @@ -81,7 +81,7 @@ def main():
mode[o[-1:]] = True
elif o == "-r":
if a in romanvals.keys():
mode[o[-1:]] = romanvals[a]
mode['r'] = romanvals[a]
elif o == "--space":
mode["s"] = True
elif o in ["-S","--separator"]:
Expand Down
8 changes: 6 additions & 2 deletions pykakasi/h2a.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ class H2a (object):

def __init__(self, method="Hepburn"):
if method == "Hepburn":
self._kanadict = jisyo('hepburnhira2.pickle')
self._kanadict = jisyo('hepburnhira2.pickle')
elif method == "Passport":
self._kanadict = jisyo('passporthira2.pickle')
elif method == "Kunrei":
self._kanadict = jisyo('kunreihira2.pickle')
else:
self._kanadict = jisyo('kunreihira2.pickle')
raise "Unsupported roman rule"

def isRegion(self, char):
return (0x3040 < ord(char[0]) and ord(char[0]) < 0x3097)
Expand Down
2 changes: 1 addition & 1 deletion pykakasi/j2a.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# j2a.py
#
# Copyright 2011 Hiroshi Miura <[email protected]>
# Copyright 2011,2014 Hiroshi Miura <[email protected]>
#
# Original Copyright:
# * KAKASI (Kanji Kana Simple inversion program)
Expand Down
8 changes: 6 additions & 2 deletions pykakasi/k2a.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ class K2a (object):

def __init__(self, method="Hepburn"):
if method == "Hepburn":
self._kanadict = jisyo('hepburndict2.pickle')
self._kanadict = jisyo('hepburndict2.pickle')
elif method == "Passport":
self._kanadict = jisyo('passportdict2.pickle')
elif method == "Kunrei":
self._kanadict = jisyo('kunreidict2.pickle')
else:
self._kanadict = jisyo('kunreidict2.pickle')
raise "Unsupported roman rule"

def isRegion(self, char):
return (0x30a0 < ord(char[0]) and ord(char[0]) < 0x30fd)
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def run(self):
('itaijidict.utf8', 'itaijidict2.pickle'),
('hepburndict.utf8', 'hepburndict2.pickle'),
('kunreidict.utf8', 'kunreidict2.pickle'),
('passportdict.utf8', 'passportdict2.pickle'),
('hepburnhira.utf8', 'hepburnhira2.pickle'),
('kunreihira.utf8', 'kunreihira2.pickle')
('kunreihira.utf8', 'kunreihira2.pickle'),
('passporthira.utf8', 'passporthira2.pickle')
]
for (s,p) in DICTS:
self.genDict(s, p)
Expand Down
30 changes: 30 additions & 0 deletions tests/basic_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ def test_K2a_kunrei(self):
for case, result in TESTS:
self.assertEqual(h.convert(case), result)

def test_H2a_passport(self):

TESTS = [
(u"しつもん", ("shi",1)),
(u"ちがい", ("chi",1)),
(u"おおの",("o",2)),
(u"さいとう",("sa",1)),
(u"とう",("to",2)),
(u"なんば", ("na", 1)),
(u"んば", ("mba", 2))
]

h = pykakasi.H2a(method="Passport")
for case, result in TESTS:
self.assertEqual(h.convert(case), result)

def test_J2K(self):

TESTS = [
Expand All @@ -155,6 +171,20 @@ def test_J2K(self):
for case, result in I_TEST:
self.assertEqual(j.itaiji_conv(case), result)


def test_J2a(self):

TESTS = [
(u"構成", ("kousei",2)),
(u"好き", ("suki",2)),
(u"大きい", ("ookii",3)),
(u"日本国民は、", ("nihonkokumin", 4))
]

j = pykakasi.J2a()
for case, result in TESTS:
self.assertEqual(j.convert(case), result)

def test_a2(self):

TESTS = [
Expand Down
59 changes: 59 additions & 0 deletions tests/basic_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ def test_K2a_kunrei(self):
for case, result in TESTS:
self.assertEqual(h.convert(case), result)

def test_H2a_passport(self):

TESTS = [
("しつもん",("shi",1)),
("ちがい", ("chi",1)),
("おおの",("o",2)),
("さいとう",("sa",1)),
("とう",("to",2)),
("なんば", ("na", 1)),
("んば", ("mba", 2))
]

h = pykakasi.H2a(method="Passport")
for case, result in TESTS:
self.assertEqual(h.convert(case), result)

def test_J2K(self):

TESTS = [
Expand All @@ -156,6 +172,49 @@ def test_J2K(self):
for case, result in I_TEST:
self.assertEqual(j.itaiji_conv(case), result)

def test_J2a(self):

TESTS = [
("構成", ("kousei",2)),
("好き", ("suki",2)),
("大きい", ("ookii",3)),
("日本国民は、", ("nihonkokumin", 4))
]

j = pykakasi.J2a()
for case, result in TESTS:
self.assertEqual(j.convert(case), result)

def test_J2a_kunrei(self):

TESTS = [
("構成", ("kousei",2)),
("好き", ("suki",2)),
("大きい", ("ookii",3)),
("日本国民は、", ("nihonkokumin", 4)),
("漢字", ("kanzi",2))
]

j = pykakasi.J2a(method="Kunrei")
for case, result in TESTS:
self.assertEqual(j.convert(case), result)

def test_J2a_passport(self):

TESTS = [
("構成", ("kosei",2)),
("好き", ("suki",2)),
("大きい", ("okii",3)),
("日本国民は、", ("nihonkokumin", 4)),
("漢字", ("kanji", 2)),
("佐藤", ("sato", 2)),
("難波", ("namba",2))
]

j = pykakasi.J2a(method="Passport")
for case, result in TESTS:
self.assertEqual(j.convert(case), result)

def test_a2(self):

TESTS = [
Expand Down

0 comments on commit f7d7fd0

Please sign in to comment.