lolspeak 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +21 -0
- data/README +22 -0
- data/Rakefile +78 -0
- data/bin/lolspeak +149 -0
- data/lib/lolspeak.rb +292 -0
- data/lib/lolspeak/tranzlator.yml +2252 -0
- data/lib/lolspeak/version.rb +3 -0
- data/test/data/tranzlator.yml +7 -0
- data/test/tranzlator_test.rb +269 -0
- metadata +62 -0
@@ -0,0 +1,269 @@
|
|
1
|
+
$KCODE = "UTF-8"
|
2
|
+
|
3
|
+
require 'lolspeak'
|
4
|
+
require 'rexml/document'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TranzlatorTest < Test::Unit::TestCase
|
8
|
+
def new_tranzlator
|
9
|
+
data_dir = File.join(File.dirname(__FILE__), "data")
|
10
|
+
yaml = File.join(data_dir, "tranzlator.yml")
|
11
|
+
return LOLspeak::Tranzlator.from_file(yaml)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_creation
|
15
|
+
tranzlator = LOLspeak::Tranzlator.new(nil)
|
16
|
+
assert_not_nil tranzlator
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_translate_word
|
20
|
+
t = new_tranzlator
|
21
|
+
assert_equal "cheezeburger", t.translate_word("cheeseburger")
|
22
|
+
assert_equal "oh hai", t.translate_word("hi")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_translate_word_with_filter
|
26
|
+
t = new_tranzlator
|
27
|
+
assert_equal "OH HAI", t.translate_word("hi") {|w| w.upcase}
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_translate_missing_word
|
31
|
+
t = new_tranzlator
|
32
|
+
assert_equal "eat", t.translate_word("eat")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_translate_missing_word_with_filter
|
36
|
+
t = new_tranzlator
|
37
|
+
assert_equal "EAT", t.translate_word("eat") {|w| w.upcase}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_downcase
|
41
|
+
t = new_tranzlator
|
42
|
+
assert_equal "oh hai", t.translate_word("Hi")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_downcase_missing
|
46
|
+
t = new_tranzlator
|
47
|
+
assert_equal "eat", t.translate_word("Eat")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_tranzlate_ascii_apostrophe
|
51
|
+
t = new_tranzlator
|
52
|
+
assert_equal "me", t.translate_word("I'm")
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_tranzlate_unicode_apostrophe
|
56
|
+
t = new_tranzlator
|
57
|
+
assert_equal "me", t.translate_word("I’m")
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_tranzlate_ascii_apostrophe_missing
|
61
|
+
t = new_tranzlator
|
62
|
+
assert_equal "it's", t.translate_word("it's")
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_tranzlate_unicode_apostrophe_missing
|
66
|
+
t = new_tranzlator
|
67
|
+
assert_equal "it’s", t.translate_word("it’s")
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_tranzlate_with_nonalpanum
|
71
|
+
t = new_tranzlator
|
72
|
+
assert_equal "f&#^bar", t.translate_word("foobar")
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_translate_before_apostrophe
|
76
|
+
t = new_tranzlator
|
77
|
+
assert_equal "kitteh's", t.translate_word("cat's")
|
78
|
+
assert_equal "kitteh’s", t.translate_word("cat’s")
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_tranzlate_words
|
82
|
+
t = new_tranzlator
|
83
|
+
assert_equal "oh hai, me kitteh! ur eating it’s cheezeburger",
|
84
|
+
t.translate_words("Hi, I'm a cat! Your eating it’s cheeseburger")
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_tranzlate_words_with_filter
|
88
|
+
t = new_tranzlator
|
89
|
+
assert_equal "OH HAI, ME KITTEH!",
|
90
|
+
t.translate_words("Hi, I'm a cat!") { |w| w.upcase }
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_tranzlate_xml_string
|
94
|
+
t = new_tranzlator
|
95
|
+
xml = <<-XML
|
96
|
+
<cat cheeseburger='hi'>cat <b>cheeseburger</b> hi</cat>
|
97
|
+
XML
|
98
|
+
expected = <<-EXPECTED
|
99
|
+
<cat cheeseburger='hi'>kitteh <b>cheezeburger</b> oh hai</cat>
|
100
|
+
EXPECTED
|
101
|
+
|
102
|
+
assert_equal expected, t.translate_xml_string(xml)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_tranzlate_xml_string_with_ampersand
|
106
|
+
t = new_tranzlator
|
107
|
+
assert_equal "<b> oh hai</b>",
|
108
|
+
t.translate_xml_string("<b> hi</b>")
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_tranzlate_xml_string_escape
|
112
|
+
t = new_tranzlator
|
113
|
+
assert_equal "<b>f&#^bar</b>",
|
114
|
+
t.translate_xml_string("<b>foobar</b>")
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_tranzlate_xml_string_normalize
|
118
|
+
t = new_tranzlator
|
119
|
+
assert_equal "<b>me</b>",
|
120
|
+
t.translate_xml_string("<b>I’m</b>")
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_tranzlate_xml_string_with_filter
|
124
|
+
t = new_tranzlator
|
125
|
+
assert_equal "<b>OH HAI&NBSP;EAT</b>",
|
126
|
+
t.translate_xml_string("<b>hi eat</b>") { |w| w.upcase }
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_string_to_lolspeak
|
130
|
+
LOLspeak.default_tranzlator = new_tranzlator
|
131
|
+
assert_equal "oh hai, me eating it’s cheezeburger",
|
132
|
+
"Hi, I'm eating it’s cheeseburger".to_lolspeak
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_string_xml_to_lolspeak
|
136
|
+
LOLspeak.default_tranzlator = new_tranzlator
|
137
|
+
assert_equal "<b>oh hai kitteh</b>",
|
138
|
+
"<b>hi cat</b>".xml_to_lolspeak
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_string_xml_to_lolspeak_with_filter
|
142
|
+
LOLspeak.default_tranzlator = new_tranzlator
|
143
|
+
assert_equal "<b>OH HAI KITTEH</b>",
|
144
|
+
"<b>hi cat</b>".xml_to_lolspeak { |w| w.upcase}
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_string_to_lolspeak_with_filter
|
148
|
+
LOLspeak.default_tranzlator = new_tranzlator
|
149
|
+
assert_equal "OH HAI, ME EATING IT’S CHEEZEBURGER",
|
150
|
+
"Hi, I'm eating it’s cheeseburger".to_lolspeak { |w| w.upcase }
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_xml_element_recursive_to_lolspeak
|
154
|
+
LOLspeak.default_tranzlator = new_tranzlator
|
155
|
+
xml = <<-XML
|
156
|
+
<cat cheeseburger='hi'>cat <b>cheeseburger</b> hi</cat>
|
157
|
+
XML
|
158
|
+
document = REXML::Document.new xml
|
159
|
+
|
160
|
+
expected = <<-EXPECTED
|
161
|
+
<cat cheeseburger='hi'>cat <b>cheezeburger</b> hi</cat>
|
162
|
+
EXPECTED
|
163
|
+
document.root.to_lolspeak_recursive!
|
164
|
+
assert_equal expected, document.to_s
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_xml_element_to_lolspeak
|
168
|
+
LOLspeak.default_tranzlator = new_tranzlator
|
169
|
+
xml = <<-XML
|
170
|
+
<cat cheeseburger='hi'>cat <b>cheeseburger</b> hi</cat>
|
171
|
+
XML
|
172
|
+
document = REXML::Document.new xml
|
173
|
+
|
174
|
+
expected = <<-EXPECTED
|
175
|
+
<cat cheeseburger='hi'>kitteh <b>cheeseburger</b> oh hai</cat>
|
176
|
+
EXPECTED
|
177
|
+
document.root.to_lolspeak!
|
178
|
+
assert_equal expected, document.to_s
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_xml_element_to_lolspeak_with_filter
|
182
|
+
LOLspeak.default_tranzlator = new_tranzlator
|
183
|
+
xml = <<-XML
|
184
|
+
<cat cheeseburger='hi'>cat <b>cheeseburger</b> hi</cat>
|
185
|
+
XML
|
186
|
+
document = REXML::Document.new xml
|
187
|
+
|
188
|
+
expected = <<-EXPECTED
|
189
|
+
<cat cheeseburger='hi'>KITTEH <b>cheeseburger</b> OH HAI</cat>
|
190
|
+
EXPECTED
|
191
|
+
document.root.to_lolspeak! { |w| w.upcase }
|
192
|
+
assert_equal expected, document.to_s
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_xml_element_to_lolspeak_recursive
|
196
|
+
LOLspeak.default_tranzlator = new_tranzlator
|
197
|
+
xml = <<-XML
|
198
|
+
<cat cheeseburger='hi'>cat <b>cheeseburger</b> hi</cat>
|
199
|
+
XML
|
200
|
+
document = REXML::Document.new xml
|
201
|
+
|
202
|
+
expected = <<-EXPECTED
|
203
|
+
<cat cheeseburger='hi'>kitteh <b>cheezeburger</b> oh hai</cat>
|
204
|
+
EXPECTED
|
205
|
+
document.to_lolspeak_recursive!
|
206
|
+
assert_equal expected, document.to_s
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_xml_element_to_lolspeak_recursive_with_filter
|
210
|
+
LOLspeak.default_tranzlator = new_tranzlator
|
211
|
+
xml = <<-XML
|
212
|
+
<cat cheeseburger='hi'>cat <b>cheeseburger</b> hi</cat>
|
213
|
+
XML
|
214
|
+
document = REXML::Document.new xml
|
215
|
+
|
216
|
+
expected = <<-EXPECTED
|
217
|
+
<cat cheeseburger='hi'>KITTEH <b>CHEEZEBURGER</b> OH HAI</cat>
|
218
|
+
EXPECTED
|
219
|
+
document.to_lolspeak_recursive! { |w| w.upcase }
|
220
|
+
assert_equal expected, document.to_s
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_default_tranzlator
|
224
|
+
LOLspeak.default_tranzlator = nil
|
225
|
+
assert_not_nil LOLspeak.default_tranzlator
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_trace
|
229
|
+
t = new_tranzlator
|
230
|
+
t.trace = true
|
231
|
+
t.translate_words("hi good cat")
|
232
|
+
expected = {"hi" => "oh hai", "cat" => "kitteh"}
|
233
|
+
assert_equal expected, t.traced_words
|
234
|
+
|
235
|
+
t.clear_traced_words
|
236
|
+
expected = {}
|
237
|
+
assert_equal expected, t.traced_words
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_heuristics
|
241
|
+
t = new_tranzlator
|
242
|
+
t.try_heuristics = true
|
243
|
+
assert_equal "the mothr of invenshun fotograf humorous foo's",
|
244
|
+
t.translate_words("the mother of invention photograph humorous foo's")
|
245
|
+
|
246
|
+
expected = {"mother" => "mothr", "invention" => "invenshun",
|
247
|
+
"photograph" => "fotograf"}
|
248
|
+
assert_equal expected, t.translated_heuristics
|
249
|
+
|
250
|
+
expected = {}
|
251
|
+
t.clear_translated_heuristics
|
252
|
+
assert_equal expected, t.translated_heuristics
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_heuristics_exclude
|
256
|
+
t = new_tranzlator
|
257
|
+
t.try_heuristics = true
|
258
|
+
t.heuristics_exclude = Set.new ['invention']
|
259
|
+
assert_equal "the mothr of invention",
|
260
|
+
t.translate_words("the mother of invention")
|
261
|
+
|
262
|
+
expected = {"mother" => "mothr"}
|
263
|
+
assert_equal expected, t.translated_heuristics
|
264
|
+
|
265
|
+
expected = {}
|
266
|
+
t.clear_translated_heuristics
|
267
|
+
assert_equal expected, t.translated_heuristics
|
268
|
+
end
|
269
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lolspeak
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Dribin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-04 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Translates English text into LOLspeak.
|
17
|
+
email:
|
18
|
+
executables:
|
19
|
+
- lolspeak
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- COPYING
|
26
|
+
- Rakefile
|
27
|
+
- README
|
28
|
+
- bin/lolspeak
|
29
|
+
- lib/lolspeak/version.rb
|
30
|
+
- lib/lolspeak.rb
|
31
|
+
- lib/lolspeak/tranzlator.yml
|
32
|
+
- test/data
|
33
|
+
- test/data/tranzlator.yml
|
34
|
+
- test/tranzlator_test.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://www.dribin.org/dave/software/lolspeak/
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements:
|
55
|
+
- none
|
56
|
+
rubyforge_project: lolspeak
|
57
|
+
rubygems_version: 1.0.1
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: LOLspeak translator
|
61
|
+
test_files: []
|
62
|
+
|