Repository: ikegami-yukino/jaconv

Issue:
alphabet2kana bug
1. `su` is converted before `tsu` leading to words like 'atsui' being converted to 「あっすい」
2. Trailing `oh` is converted too soon leaving words like 'itoh' as 「いっおお」
3. Remaining `oh` replacements should be done after other replacements, current placement causes words like `toho` to become 「っおおお」
3. singular `m` remains unconverted and becomes 「っ」, e.g., `namba => なっば`
4. `dzu` is not converted, e.g. `tsudsuku => っすっずく`

```
>>> from jaconv import alphabet2kana as a2k
>>> a2k('tsudzuku')
'っすっずく'
>>> a2k('namba')
'なっば'
>>> a2k('itoh')
'いっおお'
>>> a2k('toho')
'っおおお'
```

Discussion:

Patch:
diff --git a/README.rst b/README.rst
index 76c89af..60e4c6c 100644
--- a/README.rst
+++ b/README.rst
@@ -41,12 +41,12 @@ See also `document <http://ikegami-yukino.github.io/jaconv/jaconv.html>`_
 
   # half-width character to full-width character
   # but only ascii characters
-  jaconv.h2z(u'abc', kana=False, ascii=True, digit=False)
+  jaconv.h2z(u'abc', ascii=True)
   # => u'ａｂｃ'
 
   # half-width character to full-width character
   # but only digit characters
-  jaconv.h2z(u'123', kana=False, ascii=False, digit=True)
+  jaconv.h2z(u'123', digit=True)
   # => u'１２３'
 
   # half-width character to full-width character
@@ -60,12 +60,12 @@ See also `document <http://ikegami-yukino.github.io/jaconv/jaconv.html>`_
 
   # full-width character to half-width character
   # but only ascii characters
-  jaconv.z2h(u'ａｂｃ', kana=False, ascii=True, digit=False)
+  jaconv.z2h(u'ａｂｃ', ascii=True)
   # => u'abc'
 
   # full-width character to half-width character
   # but only digit characters
-  jaconv.z2h(u'１２３', kana=False, ascii=False, digit=True)
+  jaconv.z2h(u'１２３', digit=True)
   # => u'123'
 
   # full-width character to half-width character
diff --git a/README_JP.rst b/README_JP.rst
index 611cee3..2ed9d50 100644
--- a/README_JP.rst
+++ b/README_JP.rst
@@ -33,32 +33,32 @@ USAGE
   jaconv.kata2hira(u'巴マミ')
   # => u'巴まみ'
 
-  # 半角かな文字 to 全角かな文字
+  # 半角文字 to 全角文字
   jaconv.h2z(u'ﾃｨﾛ･ﾌｨﾅｰﾚ')
   # => u'ティロ･フィナーレ'
 
-  # 半角ASCII to 全角ASCII
-  jaconv.h2z(u'abc', kana=False, ascii=True, digit=False)
+  # ASCII以外の半角文字 to 全角文字
+  jaconv.h2z(u'abc', ascii=True)
   # => u'ａｂｃ'
 
   # 数字以外の半角文字 to 全角文字
-  jaconv.h2z(u'123', kana=False, ascii=False, digit=True)
+  jaconv.h2z(u'123', digit=True)
   # => u'１２３'
 
   # カタカナ以外の半角文字 to 全角文字
   jaconv.h2z(u'ｱabc123', kana=False, digit=True, ascii=True)
   # => u'ｱａｂｃ１２３'
 
-  # 全角かな文字 to 半角かな文字
+  # 全角文字 to 半角文字
   jaconv.z2h(u'ティロ・フィナーレ')
   # => u'ﾃｨﾛ・ﾌｨﾅｰﾚ'
 
-  # 全角ASCII to 半角ASCII
-  jaconv.z2h(u'ａｂｃ', kana=False, ascii=True, digit=False)
+  # ASCII以外の全角文字 to 半角文字
+  jaconv.z2h(u'ａｂｃ', ascii=True)
   # => u'abc'
 
-  # 全角アラビア数字 to 半角アラビア数字
-  jaconv.z2h(u'１２３', kana=False, ascii=False, digit=True)
+  # 数字以外の全角文字 to 半角文字
+  jaconv.z2h(u'１２３', digit=True)
   # => u'123'
 
   # カタカナ以外の全角文字 to 半角文字
diff --git a/jaconv/jaconv.py b/jaconv/jaconv.py
index c629be9..1e0551e 100644
--- a/jaconv/jaconv.py
+++ b/jaconv/jaconv.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
+import re
 import unicodedata
 from .conv_table import (H2K_TABLE, H2HK_TABLE, K2H_TABLE, H2Z_A, H2Z_AD,
                          H2Z_AK, H2Z_D, H2Z_K, H2Z_DK, H2Z_ALL, Z2H_A, Z2H_AD,
@@ -7,6 +8,8 @@ from .conv_table import (H2K_TABLE, H2HK_TABLE, K2H_TABLE, H2Z_A, H2Z_AD,
 from .compat import map
 
 consonants = frozenset('sdfghjklqwrtypzxcvbnm')
+ending_h_pattern = re.compile(r'h$')
+
 
 def _exclude_ignorechar(ignore, conv_map):
     for character in map(ord, ignore):
@@ -349,6 +352,8 @@ def alphabet2kana(text):
     >>> print(jaconv.alphabet2kana('mamisan'))
     まみさん
     """
+    # replace final h with う, e.g., Itoh -> いとう
+    text = re.sub(ending_h_pattern, 'う', text)
     text = text.replace('kya', 'きゃ').replace('kyu', 'きゅ').replace('kyo', 'きょ')
     text = text.replace('gya', 'ぎゃ').replace('gyu', 'ぎゅ').replace('gyo', 'ぎょ')
     text = text.replace('sha', 'しゃ').replace('shu', 'しゅ').replace('sho', 'しょ')
@@ -364,7 +369,7 @@ def alphabet2kana(text):
     text = text.replace('rya', 'りゃ').replace('ryu', 'りゅ').replace('ryo', 'りょ')
     text = text.replace('bya', 'びゃ').replace('byu', 'びゅ').replace('byo', 'びょ')
     text = text.replace('pya', 'ぴゃ').replace('pyu', 'ぴゅ').replace('pyo', 'ぴょ')
-    text = text.replace('oh', 'おお')
+    text = text.replace('tsu', 'つ')
     text = text.replace('ga', 'が').replace('gi', 'ぎ').replace('gu', 'ぐ')
     text = text.replace('ge', 'げ').replace('go', 'ご').replace('za', 'ざ')
     text = text.replace('ji', 'じ').replace('zu', 'ず').replace('ze', 'ぜ')
@@ -373,7 +378,8 @@ def alphabet2kana(text):
     text = text.replace('ve', 'ゔぇ').replace('vo', 'ゔぉ').replace('vya', 'ゔゃ')
     text = text.replace('vyi', 'ゔぃ').replace('vyu', 'ゔゅ').replace('vye', 'ゔぇ')
     text = text.replace('vyo', 'ゔょ')
-    text = text.replace('zu', 'づ').replace('de', 'で').replace('do', 'ど')
+    text = text.replace('zu', 'づ').replace('du', 'づ')
+    text = text.replace('de', 'で').replace('do', 'ど')
     text = text.replace('ba', 'ば').replace('bi', 'び').replace('bu', 'ぶ')
     text = text.replace('be', 'べ').replace('bo', 'ぼ').replace('pa', 'ぱ')
     text = text.replace('pi', 'ぴ').replace('pu', 'ぷ').replace('pe', 'ぺ')
@@ -383,7 +389,7 @@ def alphabet2kana(text):
     text = text.replace('ke', 'け').replace('ko', 'こ').replace('sa', 'さ')
     text = text.replace('shi', 'し').replace('su', 'す').replace('se', 'せ')
     text = text.replace('so', 'そ').replace('ta', 'た').replace('chi', 'ち')
-    text = text.replace('tsu', 'つ').replace('te', 'て').replace('to', 'と')
+    text = text.replace('te', 'て').replace('to', 'と')
     text = text.replace('na', 'な').replace('ni', 'に').replace('nu', 'ぬ')
     text = text.replace('ne', 'ね').replace('no', 'の').replace('ha', 'は')
     text = text.replace('hi', 'ひ').replace('fu', 'ふ').replace('he', 'へ')
@@ -394,9 +400,10 @@ def alphabet2kana(text):
     text = text.replace('ya', 'や').replace('yu', 'ゆ').replace('yo', 'よ')
     text = text.replace('wa', 'わ').replace('wi', 'ゐ').replace('we', 'ゑ')
     text = text.replace('wo', 'を')
-    text = text.replace('nn', 'ん').replace('tu', 'つ').replace('hu', 'ふ')
+    text = text.replace('nn', 'ん').replace('m', 'ん')
+    text = text.replace('tu', 'つ').replace('hu', 'ふ')
     text = text.replace('fa', 'ふぁ').replace('fi', 'ふぃ').replace('fe', 'ふぇ')
-    text = text.replace('fo', 'ふぉ').replace('-', 'ー')
+    text = text.replace('fo', 'ふぉ').replace('oh', 'おお').replace('-', 'ー')
     text = _convert(text, HEP2KANA)
     ret = []
     for (i, char) in enumerate(text):


Test patch:
diff --git a/test_jaconv.py b/test_jaconv.py
index dce83f6..805ccb4 100644
--- a/test_jaconv.py
+++ b/test_jaconv.py
@@ -113,3 +113,7 @@ def test_alphabet2kana():
     assert_equal(jaconv.alphabet2kana('doggu doguu'), 'どっぐ どぐう')
     assert_equal(jaconv.alphabet2kana('botchi'), 'ぼっち')
     assert_equal(jaconv.alphabet2kana('fainarufantaji-'), 'ふぁいなるふぁんたじー')
+    assert_equal(jaconv.alphabet2kana('atsui'), 'あつい')
+    assert_equal(jaconv.alphabet2kana('itoh'), 'いとう')
+    assert_equal(jaconv.alphabet2kana('ohtaku'), 'おおたく')
+    assert_equal(jaconv.alphabet2kana('namba'), 'なんば')