忍者ブログ
03 July

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

25 December

【AccessVBA】ヘボンローマ字変換用パーツ

これまた自分用。確か、2003で開発。
クラスのなりしてますが、セッターとか諸々不完全で、お見せするのが恥ずかしいんですが。
後ろの方にある、ヘボン式変換のアルゴリズムを作り直すのが激しく面倒なんです…。

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "c_Chg_Hebon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Compare Database
Option Explicit
'=======================================================
'
'       *** c_Chg_Hebon  *** by m_o_co
'
'=======================================================
' 渡されたテキストをヘボン式に変換するGet_Hebon_Romaと
' そのヘボン式変換用ライブラリ配列のクラス

'-------------------------------------------------------
' 2013-6-12 作成
'-------------------------------------------------------
'
' ファンクション Get_Hebon_Roma([任意]ストリング型)  ストリング型
'
'         ・渡し値が無かったら、Sorce_Textの中身を使う
'         ・返した結果と同じものをChenge_Textに格納する
'
'         --------------------------------------------
'
' プロパティ   Sorce_Text 変換前の文章
'         Chenge_Text 変換前の文章
'
'------------------------------------------------------------
'
' ※メモリの都合、都度、配列用意→置換としているので、
'   いくつも文がある場合は、Splitと配列を使って一気に変換するのが良いと思います。
'
'  ReDim Chg_Name(wkCount - 1)
'  Edit_Name_Str = ""
'
'  For i = 0 To UBound(Chg_Name)
'    If Edit_Name_Str <> "" Then Edit_Name_Str = Edit_Name_Str + "★"
'    Edit_Name_Str = Edit_Name_Str + Chg_Name(i)
'  Next
'
'  Set Chg_Hebon = New c_Chg_Hebon
'  Chg_Name = Split(Chg_Hebon.Get_Hebon_Roma(Edit_Name_Str), "★")
'  Set Chg_Hebon = Nothing
'
'------------------------------------------------------------
'=======================================================

Private cAry_Hebon() As String
Private cSorce_Text As String
Private cChenge_Text As String

Public Property Let Sorce_Text(Str As String)
   cSorce_Text = Str
End Property

Public Property Get Sorce_Text() As String
   Sorce_Text = cSorce_Text
End Property

Public Property Get Chenge_Text() As String
   Chenge_Text = cChenge_Text
End Property

Public Function Get_Hebon_Roma(Optional Chg_Hebon As String) As String
Dim i As Long, wkMax_Cont As Long, wkString As String
  
  If Chg_Hebon <> "" Then cSorce_Text = Chg_Hebon
  wkString = cSorce_Text
  
  Call cSet_cAry_Hebon(wkMax_Cont)

  For i = 0 To wkMax_Cont
    
    wkString = Replace(wkString, cAry_Hebon(i, 0), cAry_Hebon(i, 1))
  
  Next
  
  ReDim cAry_Hebon(0, 0)
  
  cChenge_Text = Replace(wkString, " ", " ")
  Get_Hebon_Roma = cChenge_Text

End Function

Private Sub cSet_cAry_Hebon(Optional Max_Cnt As Long)
'=======================================================
' ヘボン式変換用配列の設定
'
' 配列の一次元添え字が変換優先度になる。
' "おう"や"よう"等の、表記音の文字数が減るパターンの
' 優先度を高くすること
'=======================================================
  
  Const Hbn_Max_Count As Long = 166
  
  Max_Cnt = Hbn_Max_Count
  ReDim cAry_Hebon(Hbn_Max_Count, 1)

  cAry_Hebon(0, 0) = "おお"
  cAry_Hebon(0, 1) = "o"
  cAry_Hebon(1, 0) = "おう"
  cAry_Hebon(1, 1) = "o"
  cAry_Hebon(2, 0) = "こう"
  cAry_Hebon(2, 1) = "ko"
  cAry_Hebon(3, 0) = "そう"
  cAry_Hebon(3, 1) = "so"
  cAry_Hebon(4, 0) = "とう"
  cAry_Hebon(4, 1) = "to"
  cAry_Hebon(5, 0) = "のう"
  cAry_Hebon(5, 1) = "no"
  cAry_Hebon(6, 0) = "ほう"
  cAry_Hebon(6, 1) = "ho"
  cAry_Hebon(7, 0) = "もう"
  cAry_Hebon(7, 1) = "mo"
  cAry_Hebon(8, 0) = "ろう"
  cAry_Hebon(8, 1) = "ro"
  cAry_Hebon(9, 0) = "ごう"
  cAry_Hebon(9, 1) = "go"
  cAry_Hebon(10, 0) = "ぞう"
  cAry_Hebon(10, 1) = "zo"
  cAry_Hebon(11, 0) = "どう"
  cAry_Hebon(11, 1) = "do"
  cAry_Hebon(12, 0) = "ぼう"
  cAry_Hebon(12, 1) = "bo"
  cAry_Hebon(13, 0) = "ゆう"
  cAry_Hebon(13, 1) = "yu"
  cAry_Hebon(14, 0) = "ぽう"
  cAry_Hebon(14, 1) = "po"
  cAry_Hebon(15, 0) = "きょう"
  cAry_Hebon(15, 1) = "kyo"
  cAry_Hebon(16, 0) = "しょう"
  cAry_Hebon(16, 1) = "sho"
  cAry_Hebon(17, 0) = "ちょう"
  cAry_Hebon(17, 1) = "cho"
  cAry_Hebon(18, 0) = "にょう"
  cAry_Hebon(18, 1) = "nyo"
  cAry_Hebon(19, 0) = "ひょう"
  cAry_Hebon(19, 1) = "hyo"
  cAry_Hebon(20, 0) = "きゅう"
  cAry_Hebon(20, 1) = "kyu"
  cAry_Hebon(21, 0) = "しゅう"
  cAry_Hebon(21, 1) = "shu"
  cAry_Hebon(22, 0) = "ちゅう"
  cAry_Hebon(22, 1) = "chu"
  cAry_Hebon(23, 0) = "にゅう"
  cAry_Hebon(23, 1) = "nyu"
  cAry_Hebon(24, 0) = "ひゅう"
  cAry_Hebon(24, 1) = "hyu"
  cAry_Hebon(25, 0) = "みゅう"
  cAry_Hebon(25, 1) = "myu"
  cAry_Hebon(26, 0) = "りゅう"
  cAry_Hebon(26, 1) = "ryu"
  cAry_Hebon(27, 0) = "ぎゅう"
  cAry_Hebon(27, 1) = "gyu"
  cAry_Hebon(28, 0) = "じゅう"
  cAry_Hebon(28, 1) = "ju"
  cAry_Hebon(29, 0) = "びゅう"
  cAry_Hebon(29, 1) = "byu"
  cAry_Hebon(30, 0) = "ぴゅう"
  cAry_Hebon(30, 1) = "pyu"
  cAry_Hebon(31, 0) = "みょう"
  cAry_Hebon(31, 1) = "myo"
  cAry_Hebon(32, 0) = "りょう"
  cAry_Hebon(32, 1) = "ryo"
  cAry_Hebon(33, 0) = "ぎょう"
  cAry_Hebon(33, 1) = "gyo"
  cAry_Hebon(34, 0) = "じょう"
  cAry_Hebon(34, 1) = "jo"
  cAry_Hebon(35, 0) = "びょう"
  cAry_Hebon(35, 1) = "byo"
  cAry_Hebon(36, 0) = "ぴょう"
  cAry_Hebon(36, 1) = "pyo"
  cAry_Hebon(37, 0) = "みょ"
  cAry_Hebon(37, 1) = "myo"
  cAry_Hebon(38, 0) = "りょ"
  cAry_Hebon(38, 1) = "ryo"
  cAry_Hebon(39, 0) = "ぎょ"
  cAry_Hebon(39, 1) = "gyo"
  cAry_Hebon(40, 0) = "じょ"
  cAry_Hebon(40, 1) = "jo"
  cAry_Hebon(41, 0) = "びょ"
  cAry_Hebon(41, 1) = "byo"
  cAry_Hebon(42, 0) = "ぴょ"
  cAry_Hebon(42, 1) = "pyo"
  cAry_Hebon(43, 0) = "あ"
  cAry_Hebon(43, 1) = "a"
  cAry_Hebon(44, 0) = "か"
  cAry_Hebon(44, 1) = "ka"
  cAry_Hebon(45, 0) = "さ"
  cAry_Hebon(45, 1) = "sa"
  cAry_Hebon(46, 0) = "た"
  cAry_Hebon(46, 1) = "ta"
  cAry_Hebon(47, 0) = "な"
  cAry_Hebon(47, 1) = "na"
  cAry_Hebon(48, 0) = "は"
  cAry_Hebon(48, 1) = "ha"
  cAry_Hebon(49, 0) = "ま"
  cAry_Hebon(49, 1) = "ma"
  cAry_Hebon(50, 0) = "や"
  cAry_Hebon(50, 1) = "ya"
  cAry_Hebon(51, 0) = "ら"
  cAry_Hebon(51, 1) = "ra"
  cAry_Hebon(52, 0) = "わ"
  cAry_Hebon(52, 1) = "wa"
  cAry_Hebon(53, 0) = "が"
  cAry_Hebon(53, 1) = "ga"
  cAry_Hebon(54, 0) = "ざ"
  cAry_Hebon(54, 1) = "za"
  cAry_Hebon(55, 0) = "だ"
  cAry_Hebon(55, 1) = "da"
  cAry_Hebon(56, 0) = "ば"
  cAry_Hebon(56, 1) = "ba"
  cAry_Hebon(57, 0) = "ぱ"
  cAry_Hebon(57, 1) = "pa"
  cAry_Hebon(58, 0) = "きゃ"
  cAry_Hebon(58, 1) = "kya"
  cAry_Hebon(59, 0) = "しゃ"
  cAry_Hebon(59, 1) = "sha"
  cAry_Hebon(60, 0) = "ちゃ"
  cAry_Hebon(60, 1) = "cha"
  cAry_Hebon(61, 0) = "にゃ"
  cAry_Hebon(61, 1) = "nya"
  cAry_Hebon(62, 0) = "ひゃ"
  cAry_Hebon(62, 1) = "hya"
  cAry_Hebon(63, 0) = "みゃ"
  cAry_Hebon(63, 1) = "mya"
  cAry_Hebon(64, 0) = "りゃ"
  cAry_Hebon(64, 1) = "rya"
  cAry_Hebon(65, 0) = "ぎゃ"
  cAry_Hebon(65, 1) = "gya"
  cAry_Hebon(66, 0) = "じゃ"
  cAry_Hebon(66, 1) = "ja"
  cAry_Hebon(67, 0) = "びゃ"
  cAry_Hebon(67, 1) = "bya"
  cAry_Hebon(68, 0) = "ぴゃ"
  cAry_Hebon(68, 1) = "pya"
  cAry_Hebon(69, 0) = "い"
  cAry_Hebon(69, 1) = "i"
  cAry_Hebon(70, 0) = "き"
  cAry_Hebon(70, 1) = "ki"
  cAry_Hebon(71, 0) = "し"
  cAry_Hebon(71, 1) = "shi"
  cAry_Hebon(72, 0) = "ち"
  cAry_Hebon(72, 1) = "chi"
  cAry_Hebon(73, 0) = "に"
  cAry_Hebon(73, 1) = "ni"
  cAry_Hebon(74, 0) = "ひ"
  cAry_Hebon(74, 1) = "hi"
  cAry_Hebon(75, 0) = "み"
  cAry_Hebon(75, 1) = "mi"
  cAry_Hebon(76, 0) = "ゆ"
  cAry_Hebon(76, 1) = "yu"
  cAry_Hebon(77, 0) = "り"
  cAry_Hebon(77, 1) = "ri"
  cAry_Hebon(78, 0) = "を"
  cAry_Hebon(78, 1) = "o"
  cAry_Hebon(79, 0) = "ぎ"
  cAry_Hebon(79, 1) = "gi"
  cAry_Hebon(80, 0) = "じ"
  cAry_Hebon(80, 1) = "ji"
  cAry_Hebon(81, 0) = "ぢ"
  cAry_Hebon(81, 1) = "ji"
  cAry_Hebon(82, 0) = "び"
  cAry_Hebon(82, 1) = "bi"
  cAry_Hebon(83, 0) = "ぴ"
  cAry_Hebon(83, 1) = "pi"
  cAry_Hebon(84, 0) = "きゅ"
  cAry_Hebon(84, 1) = "kyu"
  cAry_Hebon(85, 0) = "しゅ"
  cAry_Hebon(85, 1) = "shu"
  cAry_Hebon(86, 0) = "ちゅ"
  cAry_Hebon(86, 1) = "chu"
  cAry_Hebon(87, 0) = "にゅ"
  cAry_Hebon(87, 1) = "nyu"
  cAry_Hebon(88, 0) = "ひゅ"
  cAry_Hebon(88, 1) = "hyu"
  cAry_Hebon(89, 0) = "みゅ"
  cAry_Hebon(89, 1) = "myu"
  cAry_Hebon(90, 0) = "りゅ"
  cAry_Hebon(90, 1) = "ryu"
  cAry_Hebon(91, 0) = "ぎゅ"
  cAry_Hebon(91, 1) = "gyu"
  cAry_Hebon(92, 0) = "じゅ"
  cAry_Hebon(92, 1) = "ju"
  cAry_Hebon(93, 0) = "びゅ"
  cAry_Hebon(93, 1) = "byu"
  cAry_Hebon(94, 0) = "ぴゅ"
  cAry_Hebon(94, 1) = "pyu"
  cAry_Hebon(95, 0) = "く"
  cAry_Hebon(95, 1) = "ku"
  cAry_Hebon(96, 0) = "す"
  cAry_Hebon(96, 1) = "su"
  cAry_Hebon(97, 0) = "つ"
  cAry_Hebon(97, 1) = "tsu"
  cAry_Hebon(98, 0) = "ぬ"
  cAry_Hebon(98, 1) = "nu"
  cAry_Hebon(99, 0) = "ふ"
  cAry_Hebon(99, 1) = "fu"
  cAry_Hebon(100, 0) = "む"
  cAry_Hebon(100, 1) = "mu"
  cAry_Hebon(101, 0) = "よ"
  cAry_Hebon(101, 1) = "yo"
  cAry_Hebon(102, 0) = "る"
  cAry_Hebon(102, 1) = "ru"
  cAry_Hebon(103, 0) = "ん"
  cAry_Hebon(103, 1) = "n"
  cAry_Hebon(104, 0) = "ぐ"
  cAry_Hebon(104, 1) = "gu"
  cAry_Hebon(105, 0) = "ず"
  cAry_Hebon(105, 1) = "zu"
  cAry_Hebon(106, 0) = "づ"
  cAry_Hebon(106, 1) = "zu"
  cAry_Hebon(107, 0) = "ぶ"
  cAry_Hebon(107, 1) = "bu"
  cAry_Hebon(108, 0) = "ぷ"
  cAry_Hebon(108, 1) = "pu"
  cAry_Hebon(109, 0) = "え"
  cAry_Hebon(109, 1) = "e"
  cAry_Hebon(110, 0) = "け"
  cAry_Hebon(110, 1) = "ke"
  cAry_Hebon(111, 0) = "せ"
  cAry_Hebon(111, 1) = "se"
  cAry_Hebon(112, 0) = "て"
  cAry_Hebon(112, 1) = "te"
  cAry_Hebon(113, 0) = "ね"
  cAry_Hebon(113, 1) = "ne"
  cAry_Hebon(114, 0) = "へ"
  cAry_Hebon(114, 1) = "he"
  cAry_Hebon(115, 0) = "め"
  cAry_Hebon(115, 1) = "me"
  cAry_Hebon(116, 0) = "よう"
  cAry_Hebon(116, 1) = "yo"
  cAry_Hebon(117, 0) = "れ"
  cAry_Hebon(117, 1) = "re"
  cAry_Hebon(118, 0) = "げ"
  cAry_Hebon(118, 1) = "ge"
  cAry_Hebon(119, 0) = "ぜ"
  cAry_Hebon(119, 1) = "ze"
  cAry_Hebon(120, 0) = "で"
  cAry_Hebon(120, 1) = "de"
  cAry_Hebon(121, 0) = "べ"
  cAry_Hebon(121, 1) = "be"
  cAry_Hebon(122, 0) = "ぺ"
  cAry_Hebon(122, 1) = "pe"
  cAry_Hebon(123, 0) = "こ"
  cAry_Hebon(123, 1) = "ko"
  cAry_Hebon(124, 0) = "そ"
  cAry_Hebon(124, 1) = "so"
  cAry_Hebon(125, 0) = "と"
  cAry_Hebon(125, 1) = "to"
  cAry_Hebon(126, 0) = "の"
  cAry_Hebon(126, 1) = "no"
  cAry_Hebon(127, 0) = "ほ"
  cAry_Hebon(127, 1) = "ho"
  cAry_Hebon(128, 0) = "も"
  cAry_Hebon(128, 1) = "mo"
  cAry_Hebon(129, 0) = "ろ"
  cAry_Hebon(129, 1) = "ro"
  cAry_Hebon(130, 0) = "ご"
  cAry_Hebon(130, 1) = "go"
  cAry_Hebon(131, 0) = "ぞ"
  cAry_Hebon(131, 1) = "zo"
  cAry_Hebon(132, 0) = "ど"
  cAry_Hebon(132, 1) = "do"
  cAry_Hebon(133, 0) = "ぼ"
  cAry_Hebon(133, 1) = "bo"
  cAry_Hebon(134, 0) = "ぽ"
  cAry_Hebon(134, 1) = "po"
  cAry_Hebon(135, 0) = "きょ"
  cAry_Hebon(135, 1) = "kyo"
  cAry_Hebon(136, 0) = "しょ"
  cAry_Hebon(136, 1) = "sho"
  cAry_Hebon(137, 0) = "ちょ"
  cAry_Hebon(137, 1) = "cho"
  cAry_Hebon(138, 0) = "にょ"
  cAry_Hebon(138, 1) = "nyo"
  cAry_Hebon(139, 0) = "ひょ"
  cAry_Hebon(139, 1) = "hyo"
  cAry_Hebon(140, 0) = "お"
  cAry_Hebon(140, 1) = "o"
  cAry_Hebon(141, 0) = "う"
  cAry_Hebon(141, 1) = "u"
  cAry_Hebon(142, 0) = "っa"
  cAry_Hebon(142, 1) = "aa"
  cAry_Hebon(143, 0) = "っb"
  cAry_Hebon(143, 1) = "bb"
  cAry_Hebon(144, 0) = "っc"
  cAry_Hebon(144, 1) = "tc"
  cAry_Hebon(145, 0) = "っd"
  cAry_Hebon(145, 1) = "dd"
  cAry_Hebon(146, 0) = "っe"
  cAry_Hebon(146, 1) = "ee"
  cAry_Hebon(147, 0) = "っf"
  cAry_Hebon(147, 1) = "ff"
  cAry_Hebon(148, 0) = "っg"
  cAry_Hebon(148, 1) = "gg"
  cAry_Hebon(149, 0) = "っh"
  cAry_Hebon(149, 1) = "hh"
  cAry_Hebon(150, 0) = "っi"
  cAry_Hebon(150, 1) = "ii"
  cAry_Hebon(151, 0) = "っj"
  cAry_Hebon(151, 1) = "jj"
  cAry_Hebon(152, 0) = "っk"
  cAry_Hebon(152, 1) = "kk"
  cAry_Hebon(153, 0) = "っm"
  cAry_Hebon(153, 1) = "mm"
  cAry_Hebon(154, 0) = "っn"
  cAry_Hebon(154, 1) = "nn"
  cAry_Hebon(155, 0) = "っo"
  cAry_Hebon(155, 1) = "oo"
  cAry_Hebon(156, 0) = "っp"
  cAry_Hebon(156, 1) = "pp"
  cAry_Hebon(157, 0) = "っr"
  cAry_Hebon(157, 1) = "rr"
  cAry_Hebon(158, 0) = "っs"
  cAry_Hebon(158, 1) = "ss"
  cAry_Hebon(159, 0) = "っt"
  cAry_Hebon(159, 1) = "tt"
  cAry_Hebon(160, 0) = "っu"
  cAry_Hebon(160, 1) = "uu"
  cAry_Hebon(161, 0) = "っw"
  cAry_Hebon(161, 1) = "ww"
  cAry_Hebon(162, 0) = "っy"
  cAry_Hebon(162, 1) = "yy"
  cAry_Hebon(163, 0) = "っz"
  cAry_Hebon(163, 1) = "zz"
  cAry_Hebon(164, 0) = "nb"
  cAry_Hebon(164, 1) = "mb"
  cAry_Hebon(165, 0) = "nm"
  cAry_Hebon(165, 1) = "mm"
  cAry_Hebon(166, 0) = "np"
  cAry_Hebon(166, 1) = "mp"

End Sub

拍手

PR