braille_ueb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README +1 -0
- data/lib/braille_ueb.rb +14 -0
- data/lib/braille_ueb/char.rb +27 -0
- data/lib/braille_ueb/constants.rb +68 -0
- data/lib/braille_ueb/word.rb +85 -0
- data/spec/braille_ueb_spec.rb +49 -0
- metadata +51 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Chris Geihsler
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Braille Translator for Unified English Braille (UEB)
|
data/lib/braille_ueb.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'braille_ueb/constants'
|
2
|
+
require 'braille_ueb/char'
|
3
|
+
require 'braille_ueb/word'
|
4
|
+
|
5
|
+
module BrailleUEB
|
6
|
+
|
7
|
+
def self.translate(input)
|
8
|
+
words = input.scan(/[0-9A-Za-z_.!?,,]+/)
|
9
|
+
translated = words.map { |w| Token.new(w).translate }
|
10
|
+
translated.join(' ')
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module BrailleUEB
|
2
|
+
class Char < String
|
3
|
+
|
4
|
+
def upper?
|
5
|
+
c == c.upcase
|
6
|
+
end
|
7
|
+
|
8
|
+
def number?
|
9
|
+
NUMBER.has_key?(c)
|
10
|
+
end
|
11
|
+
|
12
|
+
def punctuation?
|
13
|
+
PUNCTUATION.has_key?(c)
|
14
|
+
end
|
15
|
+
|
16
|
+
def letter?
|
17
|
+
ALPHA.has_key?(c.downcase)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def c
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module BrailleUEB
|
2
|
+
|
3
|
+
ALPHA = {
|
4
|
+
"a" => "\u2801",
|
5
|
+
"b" => "\u2803",
|
6
|
+
"c" => "\u2809",
|
7
|
+
"d" => "\u2819",
|
8
|
+
"e" => "\u2811",
|
9
|
+
"f" => "\u280b",
|
10
|
+
"g" => "\u281b",
|
11
|
+
"h" => "\u2813",
|
12
|
+
"i" => "\u280a",
|
13
|
+
"j" => "\u281a",
|
14
|
+
"k" => "\u2805",
|
15
|
+
"l" => "\u2807",
|
16
|
+
"m" => "\u280d",
|
17
|
+
"n" => "\u281d",
|
18
|
+
"o" => "\u2815",
|
19
|
+
"p" => "\u280f",
|
20
|
+
"q" => "\u281f",
|
21
|
+
"r" => "\u2817",
|
22
|
+
"s" => "\u280e",
|
23
|
+
"t" => "\u281e",
|
24
|
+
"u" => "\u2825",
|
25
|
+
"v" => "\u2827",
|
26
|
+
"w" => "\u283a",
|
27
|
+
"x" => "\u282d",
|
28
|
+
"y" => "\u283d",
|
29
|
+
"z" => "\u2835",
|
30
|
+
}
|
31
|
+
|
32
|
+
NUMBER = {
|
33
|
+
"1" => "\u2801",
|
34
|
+
"2" => "\u2803",
|
35
|
+
"3" => "\u2809",
|
36
|
+
"4" => "\u2819",
|
37
|
+
"5" => "\u2811",
|
38
|
+
"6" => "\u280b",
|
39
|
+
"7" => "\u281b",
|
40
|
+
"8" => "\u2813",
|
41
|
+
"9" => "\u280a",
|
42
|
+
"0" => "\u281a",
|
43
|
+
}
|
44
|
+
|
45
|
+
SPECIAL = {
|
46
|
+
:capital => "\u2820",
|
47
|
+
:number => "\u283c",
|
48
|
+
}
|
49
|
+
|
50
|
+
PUNCTUATION = {
|
51
|
+
"." => "\u2832",
|
52
|
+
"," => "\u2802"
|
53
|
+
}
|
54
|
+
|
55
|
+
CONTRACTIONS = {
|
56
|
+
"like" => "\u2807",
|
57
|
+
"but" => "\u2803",
|
58
|
+
"you" => "\u283D",
|
59
|
+
"will" => "\u283A",
|
60
|
+
"just" => "\u281A",
|
61
|
+
"do" => "\u2819",
|
62
|
+
"that" => "\u281E",
|
63
|
+
"so" => "\u280E",
|
64
|
+
"can" => "\u2809",
|
65
|
+
"go" => "\u281B",
|
66
|
+
}
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module BrailleUEB
|
2
|
+
class Token
|
3
|
+
def initialize(token)
|
4
|
+
@word, @punc = split(token)
|
5
|
+
end
|
6
|
+
|
7
|
+
def translate
|
8
|
+
braille = @word.translate
|
9
|
+
braille << PUNCTUATION[@punc] if @punc
|
10
|
+
braille
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def split(token)
|
16
|
+
punctuation = PUNCTUATION.keys.join("")
|
17
|
+
word = token.tr(punctuation, "")
|
18
|
+
punc = token.match("[#{punctuation}]")
|
19
|
+
punc = punc[0] if punc
|
20
|
+
[ Word.new(word), punc ]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Word
|
25
|
+
def initialize(word)
|
26
|
+
@word = word
|
27
|
+
end
|
28
|
+
|
29
|
+
def translate
|
30
|
+
if contraction?
|
31
|
+
contracted
|
32
|
+
else
|
33
|
+
letter_by_letter
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def contraction?
|
40
|
+
CONTRACTIONS.has_key?(@word.downcase)
|
41
|
+
end
|
42
|
+
|
43
|
+
def contracted
|
44
|
+
braille = ""
|
45
|
+
braille << SPECIAL[:capital] if starts_with_upper?
|
46
|
+
braille << CONTRACTIONS[@word.downcase]
|
47
|
+
braille
|
48
|
+
end
|
49
|
+
|
50
|
+
def starts_with_upper?
|
51
|
+
Char.new(@word[0]).upper?
|
52
|
+
end
|
53
|
+
|
54
|
+
def letter_by_letter
|
55
|
+
braille = ""
|
56
|
+
previous = Char.new("")
|
57
|
+
|
58
|
+
@word.each_char do |c|
|
59
|
+
c = Char.new(c)
|
60
|
+
braille << translate_char(previous, c)
|
61
|
+
previous = c
|
62
|
+
end
|
63
|
+
|
64
|
+
braille
|
65
|
+
end
|
66
|
+
|
67
|
+
def translate_char(previous, c)
|
68
|
+
result = ""
|
69
|
+
|
70
|
+
if c.letter?
|
71
|
+
result << SPECIAL[:capital] if c.upper?
|
72
|
+
result << ALPHA[c.downcase]
|
73
|
+
elsif c.number?
|
74
|
+
result << SPECIAL[:number] unless previous.number?
|
75
|
+
result << NUMBER[c]
|
76
|
+
else
|
77
|
+
result << c
|
78
|
+
end
|
79
|
+
|
80
|
+
result
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../lib/braille_ueb'
|
2
|
+
|
3
|
+
describe BrailleUEB do
|
4
|
+
|
5
|
+
it "should convert the alphabet" do
|
6
|
+
verify "a", "\u2801"
|
7
|
+
verify "b", "\u2803"
|
8
|
+
verify "c", "\u2809"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should convert capital letters" do
|
12
|
+
verify "Z", "\u2820\u2835"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should convert single numbers" do
|
16
|
+
verify "1", "\u283c\u2801"
|
17
|
+
verify "2", "\u283c\u2803"
|
18
|
+
verify "3", "\u283c\u2809"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should only put the number prefix for the the first number" do
|
22
|
+
verify "12", "\u283c\u2801\u2803"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should convert a period to a full stop" do
|
26
|
+
verify "Z.", "\u2820\u2835\u2832"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should convert a comma" do
|
30
|
+
verify ",", "\u2802"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should perform contractions" do
|
34
|
+
verify "like", "\u2807"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should perform contractions that end with punctuation" do
|
38
|
+
verify "like.", "\u2807\u2832"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should captialize contractions" do
|
42
|
+
verify "Like", "\u2820\u2807"
|
43
|
+
end
|
44
|
+
|
45
|
+
def verify(english, braille)
|
46
|
+
BrailleUEB.translate(english).should == braille
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: braille_ueb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Geihsler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A translator for Unified English Braille (UEB)
|
15
|
+
email: chris@geihsler.net
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/braille_ueb/char.rb
|
21
|
+
- lib/braille_ueb/constants.rb
|
22
|
+
- lib/braille_ueb/word.rb
|
23
|
+
- lib/braille_ueb.rb
|
24
|
+
- spec/braille_ueb_spec.rb
|
25
|
+
- README
|
26
|
+
- LICENSE
|
27
|
+
homepage: https://github.com/seejee/braille_ueb/
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 1.8.24
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: A translator for Unified English Braille (UEB)
|
51
|
+
test_files: []
|