“kotoba” (言葉) means ‘word’ in Japanese.
openwferu-kotoba は、大きい integer の数字を日本語のように聞こえる単語みたいなもの に変換(これはどんな日本語でも integer に変換するわけではありませんが)します。
詳しくは、私の Blog エントリ initial blog post を参照してください。
ヒューマンフレンドリーなワークフローインスタンスIDを生成するために、OpenWFEru は kotoba を使っています 。
gem があります。 :
$ sudo gem install openwferu-kotoba
この gem は RubyForge からもダウンロードできます。
直接 ソースを見る こともできます。
‘kotoba.rb’ と同じディレクトリで、以下のように…。
$ ruby kotoba.rb
ruby kotoba.rb {arg}
If the arg is a 'Kotoba' word, will turn it into the equivalent
integer.
Else, it will consider the arg as an integer and attempt at
turning it into a Kotoba [word].
Kotoba uses 70 syllables.
$ ruby kotoba.rb tsunashima
20412170
$ ruby kotoba.rb 20412170
tsunashima
$ ruby kotoba.rb 20412171
tsunashime
$ ruby kotoba.rb matsu
2159
$ ruby kotoba.rb machi
2157
$ ruby kotoba.rb 2157
machi
$ ruby kotoba.rb sushi
3832
$ ruby kotoba.rb sashimi
248672
$ ruby kotoba.rb yokohama
23462280
$ ruby kotoba.rb 23433534234
gowayujozusu
$ ruby kotoba.rb 234335342
dusogonishi
$ ruby kotoba.rb 1
be
$ ruby kotoba.rb 1973
kogo
$ ruby kotoba.rb kogo
1973
openwferu-kotoba の rdoc もできました。
openwferu-kotoba を使った小さなプログラム例が以下です。
require 'pp'
require 'rubygems'
require 'openwfe/util/kotoba'
3.times do
i = (rand * 1000000).to_i
s = Kotoba::from_integer i
puts "#{i} => #{s}"
puts "#{s} => #{Kotoba::to_integer(s)}"
# forth and back
a = Kotoba::split s
print "#{s} => "; pp a
# showing how the 'word' is split
puts "."
end
この例での出力は例えばこんな感じです…。
sonanda:~/openwfe-ruby mettraux$ ruby -I lib examples/kotoba.rb 201371 => pedese pedese => 201371 pedese => ["pe", "de", "se"] . 687109 => bibahatsu bibahatsu => 687109 bibahatsu => ["bi", "ba", "ha", "tsu"] . 948993 => bisoribo bisoribo => 948993 bisoribo => ["bi", "so", "ri", "bo"] .
openwferu-kotoba のフィードバックには、OpenWFEru user mailing list か、OpenWFEru trackers を使ってください。
もしいらないとかきらいとかなら…。
$ sudo gem uninstall openwferu-kotoba