catspeak 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/catspeak.gemspec +1 -1
- data/lib/catspeak/cat.rb +3 -0
- data/lib/catspeak/translator.rb +113 -37
- data/lib/catspeak/version.rb +1 -1
- data/spec/cat_spec.rb +6 -2
- data/spec/translator_spec.rb +25 -8
- metadata +5 -5
data/.gitignore
CHANGED
data/catspeak.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["erinata"]
|
9
9
|
s.email = ["erinata@gmail.com"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = %q{Catspeak provides translation between
|
11
|
+
s.summary = %q{Catspeak provides translation between Human Language and Cats' language}
|
12
12
|
s.description = %q{You can view it as some kind of encryption and decrpytion gem........... but cats do speak.}
|
13
13
|
# TODO: write better description
|
14
14
|
s.rubyforge_project = "catspeak"
|
data/lib/catspeak/cat.rb
CHANGED
data/lib/catspeak/translator.rb
CHANGED
@@ -10,8 +10,7 @@ module Translator
|
|
10
10
|
#number_text = Zlib::deflate(number_text, 1)
|
11
11
|
number_text = number_text.bytes.to_a
|
12
12
|
number_text
|
13
|
-
end
|
14
|
-
|
13
|
+
end
|
15
14
|
|
16
15
|
def number_to_human(name, number_text)
|
17
16
|
human_text = ''
|
@@ -27,50 +26,108 @@ module Translator
|
|
27
26
|
module CatLang
|
28
27
|
include NumberLang
|
29
28
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
29
|
+
def cat_char_dict
|
30
|
+
[
|
31
|
+
'MEOW','MeOW','MEoW','MEOw','MEow','MeOw','MeoW','Meow', #8
|
32
|
+
'mEOW','meOW','mEoW','mEOw','mEow','meOw','meoW','meow', #16
|
33
|
+
'MEOU','MeOU','MEoU','MEOu','MEou','MeOu','MeoU','Meou', #24
|
34
|
+
'mEOU','meOU','mEoU','mEOu','mEou','meOu','meoU','meou', #32
|
35
|
+
'MEO' ,'MEo' ,'MeO' ,'Meo' ,'mEO' ,'mEo' ,'meO' ,'meo' , #40
|
36
|
+
'MAOW','MaOW','MAoW','MAOw','MAow','MaOw','MaoW','Maow', #48
|
37
|
+
'mAOW','maOW','mAoW','mAOw','mAow','maOw','maoW','maow', #56
|
38
|
+
'MAOU','MaOU','MAoU','MAOu','MAou','MaOu','MaoU','Maou', #64
|
39
|
+
'mAOU','maOU','mAoU','mAOu','mAou','maOu','maoU','maou', #72
|
40
|
+
'MAO' ,'MAo' ,'MaO' ,'Mao' ,'mAO' ,'mAo' ,'maO' ,'mao' , #80
|
41
|
+
'MIAO','MIaO','MIAo','MiAO','MiAo','MiaO','MIao','Miao', #88
|
42
|
+
'mIAO','mIaO','mIAo','miAO','miAo','miaO','mIao','miao', #96
|
43
|
+
'MIA' ,'MIa' ,'MiA' ,'Mia' ,'mIA' ,'mIa' ,'miA' ,'mia' , #104
|
44
|
+
'ME' ,'Me' ,'mE' ,'me' ,'MA' ,'Ma' ,'mA' ,'ma' , #112
|
45
|
+
'MW' ,'Mw' ,'mW' ,'mw' ,'MU' ,'Mu' ,'mU' ,'mu' , #120
|
46
|
+
'MI' ,'Mi' ,'mI' ,'mi' ,'MM' ,'Mm' ,'mM' ,'mm' , #128
|
47
|
+
'MEE' ,'MEe' ,'MeE' ,'Mee' ,'mEE' ,'mEe' ,'meE' ,'mee' , #136
|
48
|
+
'MAW' ,'MAw' ,'MaW' ,'Maw' ,'mAW' ,'mAw' ,'maW' ,'maw' , #144
|
49
|
+
'EE' ,'Ee' ,'eE' ,'ee' ,'II' ,'Ii' ,'iI' ,'ii' , #152
|
50
|
+
'I' ,'i' ,'E' ,'e' ,'M' ,'m' ,'A' ,'a' , #160
|
51
|
+
'MOW' ,'MoW' ,'MOw' ,'Mow' ,'mOW' ,'moW' ,'mOw' ,'mow' , #168
|
52
|
+
'MImi','Mimi','mImi','mimi','MIMi','MiMi','mIMi','miMi', #176
|
53
|
+
'MImI','MimI','mImI','mimI','MIMI','MiMI','mIMI','miMI', #184
|
54
|
+
'MEA' ,'MEa' ,'MeA' ,'Mea' ,'mEA' ,'mEa' ,'meA' ,'mea' , #192
|
55
|
+
'MIU' ,'MIu' ,'MiU' ,'Miu' ,'mIU' ,'mIu' ,'miU' ,'miu' , #200
|
56
|
+
'MAAO','MAAo','MaAO','MaAo','mAAO','mAAo','maAO','maAo', #208
|
57
|
+
'MAaO','MAao','MaaO','Maao','mAaO','mAao','maaO','maao', #216
|
58
|
+
'MEAO','MEaO','MEAo','MeAO','MeAo','MeaO','MEao','Meao', #224
|
59
|
+
'mEAO','mEaO','mEAo','meAO','meAo','meaO','mEao','meao', #232
|
60
|
+
'MOO' ,'MOo' ,'MoO' ,'Moo' ,'mOO' ,'mOo' ,'moO' ,'moo' , #240
|
61
|
+
'UM' ,'Um' ,'uM' ,'um' ,'MUM' ,'Mum' ,'mum' ,'MeeoW', #248
|
62
|
+
'MEU' ,'Meu' ,'meu' ,'MEW' ,'Mew' ,'mew' ,'Meeow','meeow' #256
|
63
|
+
|
64
|
+
]
|
65
|
+
end
|
33
66
|
|
34
|
-
def
|
35
|
-
[
|
36
|
-
'
|
37
|
-
'
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'
|
42
|
-
'
|
43
|
-
'
|
44
|
-
'
|
45
|
-
'
|
46
|
-
'
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
def cat_tone_dict
|
68
|
+
[
|
69
|
+
' ' ,' ' ,'!!~' ,'~!!','~??','?~?','!~!',
|
70
|
+
'.' ,'. ' ,'...' ,'??~p',
|
71
|
+
'^','^^','^ ','^^ ','~^','~^ ','~~^','~~^ ','~~?','~~? ','~~!','~~! ',
|
72
|
+
' ~~^',' ~~^ ',' ~~?',' ~~? ',' ~~!',' ~~! ',' ~^',' ~^ ',
|
73
|
+
'! ','~ ','- ','? ','. ',
|
74
|
+
' !',' ~',' -',' ?',' .',
|
75
|
+
' ! ',' ~ ',' - ',' ? ',' . ',
|
76
|
+
'!' ,'!!' ,'!!!' ,'!!!!','! ' ,'!! ' ,'!!! ' ,'!!!! ',
|
77
|
+
'~' ,'~~' ,'~~~' ,'~~~~','~ ' ,'~~ ' ,'~~~ ' ,'~~~~ ',
|
78
|
+
'-' ,'--' ,'---' ,'----','- ' ,'-- ' ,'--- ' ,'---- ',
|
79
|
+
'?' ,'??' ,'???' ,'????','? ' ,'?? ' ,'??? ' ,'???? ',
|
80
|
+
"!!!?", "!!?!", "!!??", "!?!!", "!?!?", "!??!", "!???",
|
81
|
+
"?!!!", "?!!?", "?!?!", "?!??", "??!!", "??!?", "???!",
|
82
|
+
"!!!? ", "!!?! ", "!!?? ", "!?!! ", "!?!? ", "!??! ", "!??? ",
|
83
|
+
"?!!! ", "?!!? ", "?!?! ", "?!?? ", "??!! ", "??!? ", "???! ",
|
84
|
+
"~~~?", "~~?~", "~~??", "~?~~", "~?~?", "~??~", "~???",
|
85
|
+
"?~~~", "?~~?", "?~?~", "?~??", "??~~", "??~?", "???~",
|
86
|
+
"~~~? ", "~~?~ ", "~~?? ", "~?~~ ", "~?~? ", "~??~ ", "~??? ",
|
87
|
+
"?~~~ ", "?~~? ", "?~?~ ", "?~?? ", "??~~ ", "??~? ", "???~ ",
|
88
|
+
"~~~!", "~~!~", "~~!!", "~!~~", "~!~!", "~!!~", "~!!!",
|
89
|
+
"!~~~", "!~~!", "!~!~", "!~!!", "!!~~", "!!~!", "!!!~",
|
90
|
+
"~~~! ", "~~!~ ", "~~!! ", "~!~~ ", "~!~! ", "~!!~ ", "~!!! ",
|
91
|
+
"!~~~ ", "!~~! ", "!~!~ ", "!~!! ", "!!~~ ", "!!~! ", "!!!~ ",
|
92
|
+
"---?", "--?-", "--??", "-?--", "-?-?", "-??-", "-???",
|
93
|
+
"?---", "?--?", "?-?-", "?-??", "??--", "??-?", "???-",
|
94
|
+
"---? ", "--?- ", "--?? ", "-?-- ", "-?-? ", "-??- ", "-??? ",
|
95
|
+
"?--- ", "?--? ", "?-?- ", "?-?? ", "??-- ", "??-? ", "???- ",
|
96
|
+
"---!", "--!-", "--!!", "-!--", "-!-!", "-!!-", "-!!!",
|
97
|
+
"!---", "!--!", "!-!-", "!-!!", "!!--", "!!-!", "!!!-",
|
98
|
+
"---! ", "--!- ", "--!! ", "-!-- ", "-!-! ", "-!!- ", "-!!! ",
|
99
|
+
"!--- ", "!--! ", "!-!- ", "!-!! ", "!!-- ", "!!-! ", "!!!- ",
|
100
|
+
'=(>.<)=', '-(>.<)-','=(".")=','-(".")-',"=('.')=","-('.')-",
|
101
|
+
'\(>.<)/', '\(".")/','=(^.^)=','-(^.^)-','\(^.^)/','=(*.*)=',
|
102
|
+
'-(*.*)-', '\(*.*)/','=(`.`)=','-(`.`)-','\(`.`)/','=(-.-)=','\(-.-)/',
|
103
|
+
'=(>.<)= ', '-(>.<)- ','=(".")= ','-(".")- ',"=('.')= ","-('.')- ",
|
104
|
+
'\(>.<)/ ', '\(".")/ ','=(^.^)= ','-(^.^)- ','\(^.^)/ ','=(*.*)= ',
|
105
|
+
'-(*.*)- ', '\(*.*)/ ','=(`.`)= ','-(`.`)- ','\(`.`)/ ','=(-.-)= ','\(-.-)/ '
|
106
|
+
]
|
107
|
+
|
62
108
|
end
|
63
109
|
|
64
110
|
def number_to_cat(number_text)
|
65
111
|
cat_text = ''
|
66
|
-
number_text.
|
112
|
+
number_text.length.times do |i|
|
113
|
+
if (i.even?)
|
114
|
+
cat_text = cat_text + cat_char_dict[number_text[i]]
|
115
|
+
else
|
116
|
+
cat_text = cat_text + cat_tone_dict[number_text[i]]
|
117
|
+
end
|
118
|
+
end
|
67
119
|
cat_text
|
68
120
|
end
|
69
121
|
|
70
122
|
def cat_to_number(cat_text)
|
71
|
-
number_text = cat_text
|
72
|
-
number_text.
|
73
|
-
|
123
|
+
number_text = decompose(cat_text)
|
124
|
+
number_text.each_index do |i|
|
125
|
+
if (i.even?)
|
126
|
+
number_text[i] = cat_char_dict.index(number_text[i])
|
127
|
+
else
|
128
|
+
number_text[i] = cat_tone_dict.index(number_text[i])
|
129
|
+
end
|
130
|
+
end
|
74
131
|
number_text
|
75
132
|
end
|
76
133
|
|
@@ -84,5 +141,24 @@ module Translator
|
|
84
141
|
number_to_human(name, number_text)
|
85
142
|
end
|
86
143
|
|
144
|
+
def decompose(statement)
|
145
|
+
a1 = statement.split(/\W+/)
|
146
|
+
a2 = statement.split(/\w+/)
|
147
|
+
a2.delete_at(0)
|
148
|
+
a2.each_index do |i|
|
149
|
+
a1.insert(2*i+1,a2[i])
|
150
|
+
end
|
151
|
+
a1
|
152
|
+
|
153
|
+
#a3 = []
|
154
|
+
#a1.each_index do |i|
|
155
|
+
# a3 = a3+Array.new(1,a1[i])
|
156
|
+
# if (!a2[i].nil?)
|
157
|
+
# a3 = a3+Array.new(1,a2[i])
|
158
|
+
# end
|
159
|
+
#end
|
160
|
+
#a3
|
161
|
+
end
|
162
|
+
|
87
163
|
end
|
88
164
|
end
|
data/lib/catspeak/version.rb
CHANGED
data/spec/cat_spec.rb
CHANGED
@@ -13,8 +13,12 @@ describe 'Cat' do
|
|
13
13
|
Catspeak::Cat.new('Kitty').should respond_to :speak
|
14
14
|
end
|
15
15
|
|
16
|
-
it "should speak
|
17
|
-
Catspeak::Cat.new('Kitty').speak('Hello').should == '
|
16
|
+
it "should speak in cat lang" do
|
17
|
+
Catspeak::Cat.new('Kitty').speak('Hello').should == 'MM M^Mu!M~MEOW!!!Mi? Ma'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should understand cat lang" do
|
21
|
+
Catspeak::Cat.new('Kitty').hear('MM M^Mu!M~MEOW!!!Mi? Ma').should == 'Hello'
|
18
22
|
end
|
19
23
|
|
20
24
|
end
|
data/spec/translator_spec.rb
CHANGED
@@ -17,30 +17,47 @@ describe "CatLang" do
|
|
17
17
|
include Translator::CatLang
|
18
18
|
|
19
19
|
it "should translate cat lang to number lang" do
|
20
|
-
cat_to_number('
|
20
|
+
cat_to_number('MI ee').should == [120, 1, 147]
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should translate number lang to cat lang" do
|
24
|
-
number_to_cat([120, 1, 147]).should == '
|
24
|
+
number_to_cat([120, 1, 147]).should == 'MI ee'
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should translate human lang to cat lang" do
|
28
|
-
human_to_cat("Kitty","Hello").should == '
|
28
|
+
human_to_cat("Kitty","Hello").should == 'mEOU MAow?~?~maow!---MeeoW?!!! '
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should translate cat lang to human lang" do
|
32
|
-
cat_to_human("Kitty",'
|
32
|
+
cat_to_human("Kitty",'mEOU MAow?~?~maow!---MeeoW?!!! ').should == "Hello"
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should be consistent in translating betwen cat and human lang" do
|
36
36
|
cat_to_human("Kitty", human_to_cat("Kitty",'How are you doing?')).should == 'How are you doing?'
|
37
37
|
end
|
38
38
|
|
39
|
-
it "should have dictionary with length 256" do
|
40
|
-
|
39
|
+
it "should have char dictionary with length 256" do
|
40
|
+
cat_char_dict.length.should eq(256)
|
41
41
|
end
|
42
42
|
|
43
|
-
it "should have dictionary with unique words" do
|
44
|
-
|
43
|
+
it "should have char dictionary with unique words" do
|
44
|
+
cat_char_dict.uniq.should eq(cat_char_dict)
|
45
45
|
end
|
46
|
+
|
47
|
+
it "should have tone dictionary with length 256" do
|
48
|
+
cat_tone_dict.length.should eq(256)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should have tone dictionary with unique words" do
|
52
|
+
cat_tone_dict.uniq.should eq(cat_tone_dict)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should decompose array correctly" do
|
56
|
+
decompose('Meow!!Mea ? Mi^^ Moo~~~Meow~Maao ***').should == ['Meow','!!','Mea',' ? ','Mi','^^ ','Moo','~~~','Meow','~','Maao',' ***']
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should decompose array with odd index correctly" do
|
60
|
+
decompose('Meow!!Mea ? Mi^^ Moo~~~Meow~Maao').should == ['Meow','!!','Mea',' ? ','Mi','^^ ','Moo','~~~','Meow','~','Maao']
|
61
|
+
end
|
62
|
+
|
46
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catspeak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &25494168 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *25494168
|
25
25
|
description: You can view it as some kind of encryption and decrpytion gem...........
|
26
26
|
but cats do speak.
|
27
27
|
email:
|
@@ -66,5 +66,5 @@ rubyforge_project: catspeak
|
|
66
66
|
rubygems_version: 1.8.17
|
67
67
|
signing_key:
|
68
68
|
specification_version: 3
|
69
|
-
summary: Catspeak provides translation between
|
69
|
+
summary: Catspeak provides translation between Human Language and Cats' language
|
70
70
|
test_files: []
|