flatulent 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +60 -16
- data/flatulent-0.0.2.gem +0 -0
- data/lib/flatulent/crypt/blowfish-tables.rb +190 -0
- data/lib/flatulent/crypt/blowfish.rb +109 -0
- data/lib/flatulent/crypt/cbc.rb +123 -0
- data/lib/flatulent/crypt/gost.rb +140 -0
- data/lib/flatulent/crypt/idea.rb +193 -0
- data/lib/flatulent/crypt/noise.rb +94 -0
- data/lib/flatulent/crypt/purerubystringio.rb +378 -0
- data/lib/flatulent/crypt/rijndael-tables.rb +117 -0
- data/lib/flatulent/crypt/rijndael.rb +269 -0
- data/lib/flatulent/crypt/stringxor.rb +27 -0
- data/lib/flatulent.rb +332 -121
- data/lib/flatulent.rb.bak +337 -0
- data/rails/app/controllers/flatulent_controller.rb +61 -6
- data/rails/lib/flatulent/attributes.rb +79 -0
- data/rails/lib/flatulent/crypt/blowfish-tables.rb +190 -0
- data/rails/lib/flatulent/crypt/blowfish.rb +109 -0
- data/rails/lib/flatulent/crypt/cbc.rb +123 -0
- data/rails/lib/flatulent/crypt/gost.rb +140 -0
- data/rails/lib/flatulent/crypt/idea.rb +193 -0
- data/rails/lib/flatulent/crypt/noise.rb +94 -0
- data/rails/lib/flatulent/crypt/purerubystringio.rb +378 -0
- data/rails/lib/flatulent/crypt/rijndael-tables.rb +117 -0
- data/rails/lib/flatulent/crypt/rijndael.rb +269 -0
- data/rails/lib/flatulent/fontfiles/banner.flf +2494 -0
- data/rails/lib/flatulent/fontfiles/big.flf +2204 -0
- data/rails/lib/flatulent/fontfiles/block.flf +1691 -0
- data/rails/lib/flatulent/fontfiles/bubble.flf +1630 -0
- data/rails/lib/flatulent/fontfiles/digital.flf +1286 -0
- data/rails/lib/flatulent/fontfiles/ivrit.flf +900 -0
- data/rails/lib/flatulent/fontfiles/lean.flf +1691 -0
- data/rails/lib/flatulent/fontfiles/mini.flf +899 -0
- data/rails/lib/flatulent/fontfiles/mnemonic.flf +3702 -0
- data/rails/lib/flatulent/fontfiles/script.flf +1493 -0
- data/rails/lib/flatulent/fontfiles/shadow.flf +1097 -0
- data/rails/lib/flatulent/fontfiles/slant.flf +1295 -0
- data/rails/lib/flatulent/fontfiles/small.flf +1097 -0
- data/rails/lib/flatulent/fontfiles/smscript.flf +1097 -0
- data/rails/lib/flatulent/fontfiles/smshadow.flf +899 -0
- data/rails/lib/flatulent/fontfiles/smslant.flf +1097 -0
- data/rails/lib/flatulent/fontfiles/standard.flf +2227 -0
- data/rails/lib/flatulent/fontfiles/term.flf +600 -0
- data/rails/lib/flatulent/pervasives.rb +32 -0
- data/rails/lib/flatulent/stringxor.rb +27 -0
- data/rails/lib/flatulent/text/double_metaphone.rb +356 -0
- data/rails/lib/flatulent/text/figlet/font.rb +117 -0
- data/rails/lib/flatulent/text/figlet/smusher.rb +64 -0
- data/rails/lib/flatulent/text/figlet/typesetter.rb +68 -0
- data/rails/lib/flatulent/text/figlet.rb +17 -0
- data/rails/lib/flatulent/text/levenshtein.rb +65 -0
- data/rails/lib/flatulent/text/metaphone.rb +97 -0
- data/rails/lib/flatulent/text/porter_stemming.rb +171 -0
- data/rails/lib/flatulent/text/soundex.rb +61 -0
- data/rails/lib/flatulent/text.rb +6 -0
- data/rails/lib/flatulent.rb +450 -0
- data/rails/log/development.log +14297 -0
- data/rails/log/fastcgi.crash.log +111 -0
- data/rails/log/lighttpd.access.log +3993 -0
- data/rails/log/lighttpd.error.log +111 -0
- data/rails/tmp/cache/javascripts/prototype.js-gzip-3275912-71260-1183440172 +0 -0
- data/rails/tmp/sessions/ruby_sess.32d68bc997054475 +0 -0
- data/rails/tmp/sessions/ruby_sess.4694a4b9bdf9bcf4 +0 -0
- data/rails/tmp/sessions/ruby_sess.99469fde69043a05 +0 -0
- data/rails/tmp/sessions/ruby_sess.a588c0a457345912 +0 -0
- data/rails/tmp/sessions/ruby_sess.b3344125a84a3efa +0 -0
- data/samples.rb +10 -0
- metadata +69 -3
- data/flatulent-0.0.0.gem +0 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
#
|
2
|
+
# An implementation of the Metaphone phonetic coding system in Ruby.
|
3
|
+
#
|
4
|
+
# Metaphone encodes names into a phonetic form such that similar-sounding names
|
5
|
+
# have the same or similar Metaphone encodings.
|
6
|
+
#
|
7
|
+
# The original system was described by Lawrence Philips in Computer Language
|
8
|
+
# Vol. 7 No. 12, December 1990, pp 39-43.
|
9
|
+
#
|
10
|
+
# As there are multiple implementations of Metaphone, each with their own
|
11
|
+
# quirks, I have based this on my interpretation of the algorithm specification.
|
12
|
+
# Even LP's original BASIC implementation appears to contain bugs (specifically
|
13
|
+
# with the handling of CC and MB), when compared to his explanation of the
|
14
|
+
# algorithm.
|
15
|
+
#
|
16
|
+
# I have also compared this implementation with that found in PHP's standard
|
17
|
+
# library, which appears to mimic the behaviour of LP's original BASIC
|
18
|
+
# implementation. For compatibility, these rules can also be used by passing
|
19
|
+
# :buggy=>true to the methods.
|
20
|
+
#
|
21
|
+
# Author: Paul Battley (pbattley@gmail.com)
|
22
|
+
#
|
23
|
+
|
24
|
+
module Text # :nodoc:
|
25
|
+
module Metaphone
|
26
|
+
|
27
|
+
module Rules # :nodoc:all
|
28
|
+
|
29
|
+
# Metaphone rules. These are simply applied in order.
|
30
|
+
#
|
31
|
+
STANDARD = [
|
32
|
+
# Regexp, replacement
|
33
|
+
[ /([bcdfhjklmnpqrstvwxyz])\1+/,
|
34
|
+
'\1' ], # Remove doubled consonants except g.
|
35
|
+
# [PHP] remove c from regexp.
|
36
|
+
[ /^ae/, 'E' ],
|
37
|
+
[ /^[gkp]n/, 'N' ],
|
38
|
+
[ /^wr/, 'R' ],
|
39
|
+
[ /^x/, 'S' ],
|
40
|
+
[ /^wh/, 'W' ],
|
41
|
+
[ /mb$/, 'M' ], # [PHP] remove $ from regexp.
|
42
|
+
[ /(?!^)sch/, 'SK' ],
|
43
|
+
[ /th/, '0' ],
|
44
|
+
[ /t?ch|sh/, 'X' ],
|
45
|
+
[ /c(?=ia)/, 'X' ],
|
46
|
+
[ /[st](?=i[ao])/, 'X' ],
|
47
|
+
[ /s?c(?=[iey])/, 'S' ],
|
48
|
+
[ /[cq]/, 'K' ],
|
49
|
+
[ /dg(?=[iey])/, 'J' ],
|
50
|
+
[ /d/, 'T' ],
|
51
|
+
[ /g(?=h[^aeiou])/, '' ],
|
52
|
+
[ /gn(ed)?/, 'N' ],
|
53
|
+
[ /([^g]|^)g(?=[iey])/,
|
54
|
+
'\1J' ],
|
55
|
+
[ /g+/, 'K' ],
|
56
|
+
[ /ph/, 'F' ],
|
57
|
+
[ /([aeiou])h(?=\b|[^aeiou])/,
|
58
|
+
'\1' ],
|
59
|
+
[ /[wy](?![aeiou])/, '' ],
|
60
|
+
[ /z/, 'S' ],
|
61
|
+
[ /v/, 'F' ],
|
62
|
+
[ /(?!^)[aeiou]+/, '' ],
|
63
|
+
]
|
64
|
+
|
65
|
+
# The rules for the 'buggy' alternate implementation used by PHP etc.
|
66
|
+
#
|
67
|
+
BUGGY = STANDARD.dup
|
68
|
+
BUGGY[0] = [ /([bdfhjklmnpqrstvwxyz])\1+/, '\1' ]
|
69
|
+
BUGGY[6] = [ /mb/, 'M' ]
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the Metaphone representation of a string. If the string contains
|
73
|
+
# multiple words, each word in turn is converted into its Metaphone
|
74
|
+
# representation. Note that only the letters A-Z are supported, so any
|
75
|
+
# language-specific processing should be done beforehand.
|
76
|
+
#
|
77
|
+
# If the :buggy option is set, alternate 'buggy' rules are used.
|
78
|
+
#
|
79
|
+
def metaphone(str, options={})
|
80
|
+
return str.strip.split(/\s+/).map { |w| metaphone_word(w, options) }.join(' ')
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def metaphone_word(w, options={})
|
86
|
+
# Normalise case and remove non-ASCII
|
87
|
+
s = w.downcase.gsub(/[^a-z]/, '')
|
88
|
+
# Apply the Metaphone rules
|
89
|
+
rules = options[:buggy] ? Rules::BUGGY : Rules::STANDARD
|
90
|
+
rules.each { |rx, rep| s.gsub!(rx, rep) }
|
91
|
+
return s.upcase
|
92
|
+
end
|
93
|
+
|
94
|
+
extend self
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
#
|
2
|
+
# This is the Porter Stemming algorithm, ported to Ruby from the
|
3
|
+
# version coded up in Perl. It's easy to follow against the rules
|
4
|
+
# in the original paper in:
|
5
|
+
#
|
6
|
+
# Porter, 1980, An algorithm for suffix stripping, Program, Vol. 14,
|
7
|
+
# no. 3, pp 130-137,
|
8
|
+
#
|
9
|
+
# Taken from http://www.tartarus.org/~martin/PorterStemmer (Public Domain)
|
10
|
+
#
|
11
|
+
module Text # :nodoc:
|
12
|
+
module PorterStemming
|
13
|
+
|
14
|
+
STEP_2_LIST = {
|
15
|
+
'ational' => 'ate', 'tional' => 'tion', 'enci' => 'ence', 'anci' => 'ance',
|
16
|
+
'izer' => 'ize', 'bli' => 'ble',
|
17
|
+
'alli' => 'al', 'entli' => 'ent', 'eli' => 'e', 'ousli' => 'ous',
|
18
|
+
'ization' => 'ize', 'ation' => 'ate',
|
19
|
+
'ator' => 'ate', 'alism' => 'al', 'iveness' => 'ive', 'fulness' => 'ful',
|
20
|
+
'ousness' => 'ous', 'aliti' => 'al',
|
21
|
+
'iviti' => 'ive', 'biliti' => 'ble', 'logi' => 'log'
|
22
|
+
}
|
23
|
+
|
24
|
+
STEP_3_LIST = {
|
25
|
+
'icate' => 'ic', 'ative' => '', 'alize' => 'al', 'iciti' => 'ic',
|
26
|
+
'ical' => 'ic', 'ful' => '', 'ness' => ''
|
27
|
+
}
|
28
|
+
|
29
|
+
SUFFIX_1_REGEXP = /(
|
30
|
+
ational |
|
31
|
+
tional |
|
32
|
+
enci |
|
33
|
+
anci |
|
34
|
+
izer |
|
35
|
+
bli |
|
36
|
+
alli |
|
37
|
+
entli |
|
38
|
+
eli |
|
39
|
+
ousli |
|
40
|
+
ization |
|
41
|
+
ation |
|
42
|
+
ator |
|
43
|
+
alism |
|
44
|
+
iveness |
|
45
|
+
fulness |
|
46
|
+
ousness |
|
47
|
+
aliti |
|
48
|
+
iviti |
|
49
|
+
biliti |
|
50
|
+
logi)$/x
|
51
|
+
|
52
|
+
SUFFIX_2_REGEXP = /(
|
53
|
+
al |
|
54
|
+
ance |
|
55
|
+
ence |
|
56
|
+
er |
|
57
|
+
ic |
|
58
|
+
able |
|
59
|
+
ible |
|
60
|
+
ant |
|
61
|
+
ement |
|
62
|
+
ment |
|
63
|
+
ent |
|
64
|
+
ou |
|
65
|
+
ism |
|
66
|
+
ate |
|
67
|
+
iti |
|
68
|
+
ous |
|
69
|
+
ive |
|
70
|
+
ize)$/x
|
71
|
+
|
72
|
+
C = "[^aeiou]" # consonant
|
73
|
+
V = "[aeiouy]" # vowel
|
74
|
+
CC = "#{C}(?>[^aeiouy]*)" # consonant sequence
|
75
|
+
VV = "#{V}(?>[aeiou]*)" # vowel sequence
|
76
|
+
|
77
|
+
MGR0 = /^(#{CC})?#{VV}#{CC}/o # [cc]vvcc... is m>0
|
78
|
+
MEQ1 = /^(#{CC})?#{VV}#{CC}(#{VV})?$/o # [cc]vvcc[vv] is m=1
|
79
|
+
MGR1 = /^(#{CC})?#{VV}#{CC}#{VV}#{CC}/o # [cc]vvccvvcc... is m>1
|
80
|
+
VOWEL_IN_STEM = /^(#{CC})?#{V}/o # vowel in stem
|
81
|
+
|
82
|
+
def self.stem(word)
|
83
|
+
|
84
|
+
# make a copy of the given object and convert it to a string.
|
85
|
+
word = word.dup.to_str
|
86
|
+
|
87
|
+
return word if word.length < 3
|
88
|
+
|
89
|
+
# now map initial y to Y so that the patterns never treat it as vowel
|
90
|
+
word[0] = 'Y' if word[0] == ?y
|
91
|
+
|
92
|
+
# Step 1a
|
93
|
+
if word =~ /(ss|i)es$/
|
94
|
+
word = $` + $1
|
95
|
+
elsif word =~ /([^s])s$/
|
96
|
+
word = $` + $1
|
97
|
+
end
|
98
|
+
|
99
|
+
# Step 1b
|
100
|
+
if word =~ /eed$/
|
101
|
+
word.chop! if $` =~ MGR0
|
102
|
+
elsif word =~ /(ed|ing)$/
|
103
|
+
stem = $`
|
104
|
+
if stem =~ VOWEL_IN_STEM
|
105
|
+
word = stem
|
106
|
+
case word
|
107
|
+
when /(at|bl|iz)$/ then word << "e"
|
108
|
+
when /([^aeiouylsz])\1$/ then word.chop!
|
109
|
+
when /^#{CC}#{V}[^aeiouwxy]$/o then word << "e"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
if word =~ /y$/
|
115
|
+
stem = $`
|
116
|
+
word = stem + "i" if stem =~ VOWEL_IN_STEM
|
117
|
+
end
|
118
|
+
|
119
|
+
# Step 2
|
120
|
+
if word =~ SUFFIX_1_REGEXP
|
121
|
+
stem = $`
|
122
|
+
suffix = $1
|
123
|
+
# print "stem= " + stem + "\n" + "suffix=" + suffix + "\n"
|
124
|
+
if stem =~ MGR0
|
125
|
+
word = stem + STEP_2_LIST[suffix]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Step 3
|
130
|
+
if word =~ /(icate|ative|alize|iciti|ical|ful|ness)$/
|
131
|
+
stem = $`
|
132
|
+
suffix = $1
|
133
|
+
if stem =~ MGR0
|
134
|
+
word = stem + STEP_3_LIST[suffix]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Step 4
|
139
|
+
if word =~ SUFFIX_2_REGEXP
|
140
|
+
stem = $`
|
141
|
+
if stem =~ MGR1
|
142
|
+
word = stem
|
143
|
+
end
|
144
|
+
elsif word =~ /(s|t)(ion)$/
|
145
|
+
stem = $` + $1
|
146
|
+
if stem =~ MGR1
|
147
|
+
word = stem
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Step 5
|
152
|
+
if word =~ /e$/
|
153
|
+
stem = $`
|
154
|
+
if (stem =~ MGR1) ||
|
155
|
+
(stem =~ MEQ1 && stem !~ /^#{CC}#{V}[^aeiouwxy]$/o)
|
156
|
+
word = stem
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
if word =~ /ll$/ && word =~ MGR1
|
161
|
+
word.chop!
|
162
|
+
end
|
163
|
+
|
164
|
+
# and turn initial Y back to y
|
165
|
+
word[0] = 'y' if word[0] == ?Y
|
166
|
+
|
167
|
+
word
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#
|
2
|
+
# Ruby implementation of the Soundex algorithm,
|
3
|
+
# as described by Knuth in volume 3 of The Art of Computer Programming.
|
4
|
+
#
|
5
|
+
# Author: Michael Neumann (neumann@s-direktnet.de)
|
6
|
+
#
|
7
|
+
|
8
|
+
module Text # :nodoc:
|
9
|
+
module Soundex
|
10
|
+
|
11
|
+
def soundex(str_or_arr)
|
12
|
+
case str_or_arr
|
13
|
+
when String
|
14
|
+
soundex_str(str_or_arr)
|
15
|
+
when Array
|
16
|
+
str_or_arr.collect{|ele| soundex_str(ele)}
|
17
|
+
else
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
module_function :soundex
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
#
|
26
|
+
# returns nil if the value couldn't be calculated (empty-string, wrong-character)
|
27
|
+
# do not change the parameter "str"
|
28
|
+
#
|
29
|
+
def soundex_str(str)
|
30
|
+
return nil if str.empty?
|
31
|
+
|
32
|
+
str = str.upcase
|
33
|
+
last_code = get_code(str[0,1])
|
34
|
+
soundex_code = str[0,1]
|
35
|
+
|
36
|
+
for index in 1...(str.size) do
|
37
|
+
return soundex_code if soundex_code.size == 4
|
38
|
+
|
39
|
+
code = get_code(str[index,1])
|
40
|
+
|
41
|
+
if code == "0" then
|
42
|
+
last_code = nil
|
43
|
+
elsif code == nil then
|
44
|
+
return nil
|
45
|
+
elsif code != last_code then
|
46
|
+
soundex_code += code
|
47
|
+
last_code = code
|
48
|
+
end
|
49
|
+
end # for
|
50
|
+
|
51
|
+
return soundex_code + "000"[0,4-soundex_code.size]
|
52
|
+
end
|
53
|
+
module_function :soundex_str
|
54
|
+
|
55
|
+
def get_code(char)
|
56
|
+
char.tr! "AEIOUYWHBPFVCSKGJQXZDTLMNR", "00000000111122222222334556"
|
57
|
+
end
|
58
|
+
module_function :get_code
|
59
|
+
|
60
|
+
end # module Soundex
|
61
|
+
end # module Text
|