Module Kotoba
In: lib/openwfe/util/kotoba.rb

Kotoba

This module contains methods for converting plain integers (base 10) into words that are easier to read and remember.

For example, the equivalent of the (base 10) integer 1329724967 is "takeshimaya".

Kotoba uses 70 of the syllables of the Japanese language, it is thus a base 10 to base 70 converter.

Kotoba is meant to be used for generating human readable (or more easily rememberable) identifiers. Its first usage is within the OpenWFEru Ruby workflow and bpm engine for generating ‘kawaii’ business process intance ids.

Kotoba from the command line

You can use Kotoba directly from the command line :

    $ ruby kotoba.rb kotoba
    141260
    $ ruby kotoba.rb rubi
    3432
    $ ruby kotoba.rb 2455
    nada

might be useful when used from some scripts.

Methods

Constants

V = %w{ a e i o u }
C = %w{ b d g h j k m n p r s t z }
SYL = []
SPECIAL = [ [ "hu", "fu" ], [ "si", "shi" ], [ "ti", "chi" ], [ "tu", "tsu" ], [ "zi", "tzu" ]

Public Class methods

Turns the given integer into a Kotoba word.

[Source]

     # File lib/openwfe/util/kotoba.rb, line 112
112:     def Kotoba.from_integer (integer)
113:         s = from_i(integer)
114:         to_special(s)
115:     end

Returns if the string is a Kotoba word, like "fugu" or "toriyamanobashi".

[Source]

     # File lib/openwfe/util/kotoba.rb, line 151
151:     def Kotoba.is_kotoba_word (string)
152:         begin
153:             to_integer(string)
154:             true
155:         rescue #Exception => e
156:             false
157:         end
158:     end

Given a Kotoba ‘word’, will split into its list of syllables. For example, "tsunashima" will be split into [ "tsu", "na", "shi", "ma" ]

[Source]

     # File lib/openwfe/util/kotoba.rb, line 141
141:     def Kotoba.split (word)
142:         word = from_special(word)
143:         a = string_split(word)
144:         a_to_special(a)
145:     end

Turns the given Kotoba word to its equivalent integer.

[Source]

     # File lib/openwfe/util/kotoba.rb, line 120
120:     def Kotoba.to_integer (string)
121:         s = from_special(string)
122:         to_i(s)
123:     end

Turns a simple syllable into the equivalent number. For example Kotoba::to_number("fu") will yield 19.

[Source]

     # File lib/openwfe/util/kotoba.rb, line 129
129:     def Kotoba.to_number (syllable)
130:         SYL.each_with_index do |s, index|
131:             return index if syllable == s
132:         end
133:         raise "did not find syllable '#{syllable}'"
134:     end

Protected Class methods

[Source]

     # File lib/openwfe/util/kotoba.rb, line 168
168:         def Kotoba.a_to_special (a)
169:             a.collect do |syl|
170:                 SPECIAL.each do |a, b|
171:                     if syl == a
172:                         syl = b
173:                         break
174:                     end
175:                 end
176:                 syl
177:             end
178:         end

[Source]

     # File lib/openwfe/util/kotoba.rb, line 194
194:         def Kotoba.from_i (integer)
195: 
196:             return '' if integer == 0
197: 
198:             mod = integer % SYL.length
199:             rest = integer / SYL.length
200: 
201:             return from_i(rest) + SYL[mod]
202:         end

[Source]

     # File lib/openwfe/util/kotoba.rb, line 187
187:         def Kotoba.from_special (s)
188:             SPECIAL.each do |a, b|
189:                 s = s.gsub(b, a)
190:             end
191:             s
192:         end

[Source]

     # File lib/openwfe/util/kotoba.rb, line 162
162:         def Kotoba.string_split (s, result=[])
163:             return result if s.length < 1
164:             result << s[0, 2]
165:             string_split(s[2..-1], result)
166:         end

[Source]

     # File lib/openwfe/util/kotoba.rb, line 204
204:         def Kotoba.to_i (s)
205:             return 0 if s.length == 0
206:             return SYL.length * to_i(s[0..-3]) + to_number(s[-2, 2])
207:         end

[Source]

     # File lib/openwfe/util/kotoba.rb, line 180
180:         def Kotoba.to_special (s)
181:             SPECIAL.each do |a, b|
182:                 s = s.gsub(a, b)
183:             end
184:             s
185:         end

[Validate]