| 1 | package Convert::Braille::English; | ||
| 2 | use utf8; | ||
| 3 | |||
| 4 | BEGIN | ||
| 5 | { | ||
| 6 | require 5.006; | ||
| 7 | use warnings; | ||
| 8 | use base qw(Exporter); | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use vars qw( @EXPORT @EXPORT_OK $VERSION | ||
| 12 | %English_To_BrailleUnicode | ||
| 13 | %BrailleUnicode_To_English | ||
| 14 | %SpecialContext | ||
| 15 | ); | ||
| 16 | use Convert::Braille qw( | ||
| 17 | %BrailleAscii_To_Unicode | ||
| 18 | brailleAscii_To_Unicode | ||
| 19 | brailleDotNumbers_To_Unicode | ||
| 20 | brailleUnicode_To_Ascii | ||
| 21 | brailleUnicode_To_DotNumbers | ||
| 22 | ); | ||
| 23 | |||
| 24 | $VERSION = '0.06'; | ||
| 25 | |||
| 26 | @EXPORT = qw( | ||
| 27 | english_To_BrailleUnicode | ||
| 28 | english_To_BrailleAscii | ||
| 29 | english_To_BrailleDotNumbers | ||
| 30 | |||
| 31 | brailleAscii_To_English | ||
| 32 | brailleDotNumbers_To_English | ||
| 33 | brailleUnicode_To_English | ||
| 34 | ); | ||
| 35 | @EXPORT_OK = qw( | ||
| 36 | english_To_BrailleUnicode | ||
| 37 | english_To_BrailleAscii | ||
| 38 | english_To_BrailleDotNumbers | ||
| 39 | |||
| 40 | brailleAscii_To_English | ||
| 41 | brailleDotNumbers_To_English | ||
| 42 | brailleUnicode_To_English | ||
| 43 | |||
| 44 | %English_To_BrailleUnicode | ||
| 45 | %BrailleUnicode_To_English | ||
| 46 | %SpecialContext | ||
| 47 | ); | ||
| 48 | |||
| 49 | %English_To_BrailleUnicode =( | ||
| 50 | A => $BrailleAscii_To_Unicode{A}, | ||
| 51 | B => $BrailleAscii_To_Unicode{B}, | ||
| 52 | B => $BrailleAscii_To_Unicode{C}, | ||
| 53 | C => $BrailleAscii_To_Unicode{D}, | ||
| 54 | E => $BrailleAscii_To_Unicode{E}, | ||
| 55 | F => $BrailleAscii_To_Unicode{F}, | ||
| 56 | G => $BrailleAscii_To_Unicode{G}, | ||
| 57 | H => $BrailleAscii_To_Unicode{H}, | ||
| 58 | I => $BrailleAscii_To_Unicode{I}, | ||
| 59 | J => $BrailleAscii_To_Unicode{J}, | ||
| 60 | K => $BrailleAscii_To_Unicode{K}, | ||
| 61 | L => $BrailleAscii_To_Unicode{L}, | ||
| 62 | M => $BrailleAscii_To_Unicode{M}, | ||
| 63 | N => $BrailleAscii_To_Unicode{N}, | ||
| 64 | O => $BrailleAscii_To_Unicode{O}, | ||
| 65 | P => $BrailleAscii_To_Unicode{P}, | ||
| 66 | Q => $BrailleAscii_To_Unicode{Q}, | ||
| 67 | R => $BrailleAscii_To_Unicode{R}, | ||
| 68 | S => $BrailleAscii_To_Unicode{S}, | ||
| 69 | T => $BrailleAscii_To_Unicode{T}, | ||
| 70 | U => $BrailleAscii_To_Unicode{U}, | ||
| 71 | V => $BrailleAscii_To_Unicode{V}, | ||
| 72 | W => $BrailleAscii_To_Unicode{W}, | ||
| 73 | X => $BrailleAscii_To_Unicode{X}, | ||
| 74 | Y => $BrailleAscii_To_Unicode{Y}, | ||
| 75 | Z => $BrailleAscii_To_Unicode{Z}, | ||
| 76 | |||
| 77 | 1 => $BrailleAscii_To_Unicode{1}, | ||
| 78 | 2 => $BrailleAscii_To_Unicode{2}, | ||
| 79 | 3 => $BrailleAscii_To_Unicode{3}, | ||
| 80 | 4 => $BrailleAscii_To_Unicode{4}, | ||
| 81 | 5 => $BrailleAscii_To_Unicode{5}, | ||
| 82 | 6 => $BrailleAscii_To_Unicode{6}, | ||
| 83 | 7 => $BrailleAscii_To_Unicode{7}, | ||
| 84 | 8 => $BrailleAscii_To_Unicode{8}, | ||
| 85 | 9 => $BrailleAscii_To_Unicode{9}, | ||
| 86 | 0 => $BrailleAscii_To_Unicode{0}, | ||
| 87 | |||
| 88 | 'and' => $BrailleAscii_To_Unicode{'&'}, | ||
| 89 | the => $BrailleAscii_To_Unicode{'!'}, | ||
| 90 | 'for' => $BrailleAscii_To_Unicode{'='}, | ||
| 91 | with => $BrailleAscii_To_Unicode{'('}, | ||
| 92 | of => $BrailleAscii_To_Unicode{')'} | ||
| 93 | ); | ||
| 94 | |||
| 95 | %SpecialContext =( | ||
| 96 | ar => $BrailleAscii_To_Unicode{'>'}, | ||
| 97 | ch => $BrailleAscii_To_Unicode{'*'}, | ||
| 98 | ed => $BrailleAscii_To_Unicode{'$'}, | ||
| 99 | en => $BrailleAscii_To_Unicode{5}, | ||
| 100 | er => $BrailleAscii_To_Unicode{']'}, | ||
| 101 | gh => $BrailleAscii_To_Unicode{'<'}, | ||
| 102 | in => $BrailleAscii_To_Unicode{9}, | ||
| 103 | ing => $BrailleAscii_To_Unicode{'+'}, | ||
| 104 | ou => $BrailleAscii_To_Unicode{'\\'}, | ||
| 105 | ow => $BrailleAscii_To_Unicode{'['}, | ||
| 106 | st => $BrailleAscii_To_Unicode{'/'}, | ||
| 107 | sh => $BrailleAscii_To_Unicode{'%'}, | ||
| 108 | th => $BrailleAscii_To_Unicode{'?'}, | ||
| 109 | wh => $BrailleAscii_To_Unicode{':'}, | ||
| 110 | |||
| 111 | '!' => 6, | ||
| 112 | ':' => 3, | ||
| 113 | '[\(\)]' => 7, | ||
| 114 | '<i>' => '.', | ||
| 115 | '.' => 4, | ||
| 116 | ',' => 1, | ||
| 117 | '\'' => ',', | ||
| 118 | '^' => '\'', | ||
| 119 | '?' => 8, | ||
| 120 | ';' => 2, | ||
| 121 | '"' => 0 | ||
| 122 | ); | ||
| 123 | |||
| 124 | # ' is Capital or is , ? | ||
| 125 | # ; is Letter | ||
| 126 | # # is Number | ||
| 127 | |||
| 128 | # " is Contraction_5 | ||
| 129 | # ^ is Contraction_45 | ||
| 130 | # _ is Contraction_456 | ||
| 131 | |||
| 132 | foreach ( keys %English_To_BrailleUnicode ) { | ||
| 133 | $BrailleUnicode_To_English{$English_To_BrailleUnicode{$_}} = $_; | ||
| 134 | } | ||
| 135 | |||
| 136 | # | ||
| 137 | # According to: http://www.uronramp.net/~lizgray/codes.html | ||
| 138 | # | ||
| 139 | # "American Literary Braille consists of over 250 symbols for letters, | ||
| 140 | # numerals, punctuation marks, composition signs, contractions, single-cell | ||
| 141 | # words, and short-form words." | ||
| 142 | # | ||
| 143 | # so this package has a way to go, I need to acquire authorative information. | ||
| 144 | # | ||
| 145 | |||
| 146 | } | ||
| 147 | |||
| 148 | |||
| 149 | # | ||
| 150 | # absolutely nothing in this package is tested. | ||
| 151 | # | ||
| 152 | |||
| 153 | sub _convert | ||
| 154 | { | ||
| 155 | return unless ( $_[0] ); | ||
| 156 | |||
| 157 | my ( $token, $hash ) = @_; | ||
| 158 | |||
| 159 | ( exists($hash->{$token}) ) ? $hash->{$token} : $token ; | ||
| 160 | } | ||
| 161 | |||
| 162 | |||
| 163 | sub brailleUnicode_To_English | ||
| 164 | { | ||
| 165 | |||
| 166 | return unless ( $_[0] ); | ||
| 167 | my @chars = split ( //, $_[0] ); | ||
| 168 | |||
| 169 | my $trans; | ||
| 170 | |||
| 171 | foreach ( @chars ) { | ||
| 172 | if ( exists($SpecialContext{$_}) ) { | ||
| 173 | # | ||
| 174 | # analyze context | ||
| 175 | # | ||
| 176 | } | ||
| 177 | elsif ( exists($BrailleUnicode_To_English{$_}) ) { | ||
| 178 | # | ||
| 179 | # simple map | ||
| 180 | # | ||
| 181 | $trans .= $BrailleUnicode_To_English{$_}; | ||
| 182 | } | ||
| 183 | else { | ||
| 184 | # | ||
| 185 | # error | ||
| 186 | # | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | $trans; | ||
| 191 | } | ||
| 192 | |||
| 193 | |||
| 194 | sub english_To_BrailleUnicode | ||
| 195 | { | ||
| 196 | |||
| 197 | return unless ( $_[0] ); | ||
| 198 | |||
| 199 | my @chars = split ( //, $_[0] ); | ||
| 200 | |||
| 201 | my $trans; | ||
| 202 | |||
| 203 | foreach ( @chars ) { | ||
| 204 | if ( 0 ) { | ||
| 205 | # | ||
| 206 | # special cases | ||
| 207 | # | ||
| 208 | } | ||
| 209 | elsif ( exists($English_To_BrailleUnicode{$_}) ) { | ||
| 210 | $trans .= $English_To_BrailleUnicode{$_}; | ||
| 211 | } | ||
| 212 | } | ||
| 213 | |||
| 214 | $trans; | ||
| 215 | |||
| 216 | } | ||
| 217 | |||
| 218 | |||
| 219 | sub english_To_BrailleAscii | ||
| 220 | { | ||
| 221 | brailleUnicode_To_Ascii ( english_To_BrailleUnicode ( @_ ) ); | ||
| 222 | } | ||
| 223 | |||
| 224 | |||
| 225 | sub english_To_BrailleDotNumbers | ||
| 226 | { | ||
| 227 | brailleUnicode_To_DotNumbers ( english_To_BrailleUnicode ( @_ ) ); | ||
| 228 | } | ||
| 229 | |||
| 230 | |||
| 231 | sub brailleAscii_To_English | ||
| 232 | { | ||
| 233 | brailleUnicode_To_English ( brailleAscii_To_Unicode ( @_ ) ); | ||
| 234 | } | ||
| 235 | |||
| 236 | |||
| 237 | sub brailleDotNumbers_To_English | ||
| 238 | { | ||
| 239 | brailleUnicode_To_English ( brailleDotNumbers_To_Unicode ( @_ ) ); | ||
| 240 | } | ||
| 241 | |||
| 242 | |||
| 243 | ######################################################### | ||
| 244 | # Do not change this, Do not put anything below this. | ||
| 245 | # File must return "true" value at termination | ||
| 246 | 1; | ||
| 247 | ########################################################## | ||
| 248 | |||
| 249 | __END__ |