babelfish 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2007 Suraj N. Kurapati <sunaku@gmail.com>
2
+
3
+ Permission to use, copy, modify, and distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
data/README ADDED
@@ -0,0 +1,87 @@
1
+ babelfish : Ruby interface to Yahoo! BabelFish translation service
2
+ ==================================================================
3
+
4
+ This is a completely *unofficial* (and incredibly simple) Ruby
5
+ interface to the Yahoo! BabelFish translation service. Enjoy!
6
+
7
+
8
+ Installation
9
+ ------------
10
+
11
+ Run the following command to install this library:
12
+
13
+ sudo gem install babelfish
14
+
15
+
16
+ Usage: Command Line
17
+ --------------------
18
+
19
+ Here are some examples of using the command-line interface:
20
+
21
+ # echo "Hello world!" | babelfish en es
22
+ ¡Hola mundo!
23
+
24
+ # echo "How are you?" > foo.txt
25
+ # babelfish en es foo.txt
26
+ ¿Cómo está usted?
27
+
28
+ Run `babelfish --help` to see the list of supported languages.
29
+
30
+
31
+ Usage: Ruby Library
32
+ --------------------
33
+
34
+ Here is an example of using the library in Ruby:
35
+
36
+ require 'rubygems'
37
+ require 'babelfish'
38
+
39
+ input_text = "I am well, thank you."
40
+ input_code = "en"
41
+
42
+ puts input_text
43
+ BabelFish::LANGUAGE_PAIRS[input_code].each do |output_code|
44
+ print " in #{BabelFish::LANGUAGE_NAMES[output_code]} is: "
45
+ puts BabelFish.translate(input_text, input_code, output_code)
46
+ end
47
+
48
+ The result of running the above example is:
49
+
50
+ I am well, thank you.
51
+ in Italian is: Sono bene, grazie.
52
+ in Japanese is: 私は元気でいる、ありがとう。
53
+ in German is: Ich fÃehle mich gut, danke.
54
+ in French is: Je vais bien, merci.
55
+ in Spanish is: Estoy bien, gracias.
56
+ in Russian is: Я наилучшим образом, вы.
57
+ in Chinese-simp is: 我很好,谢谢。
58
+ in Portuguese is: Eu sou bem, obrigado.
59
+ in Korean is: 나는 잘 있다, 당신을 감사하십시오.
60
+ in Chinese-trad is:
61
+ in Greek is: Είμαι καλά, σας ευχαριστώ.
62
+ in Dutch is: Ik ben goed, dank u.
63
+
64
+ Read the [RDoc documentation](api/index.html) for more information.
65
+
66
+
67
+ License
68
+ -------
69
+
70
+ Copyright 2007 Suraj N. Kurapati <sunaku@gmail.com>
71
+
72
+ Permission to use, copy, modify, and distribute this software for any
73
+ purpose with or without fee is hereby granted, provided that the above
74
+ copyright notice and this permission notice appear in all copies.
75
+
76
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
77
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
78
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
79
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
80
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
81
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
82
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
83
+
84
+
85
+ * * *
86
+
87
+ Visit [http://snk.tuxfamily.org/lib/babelfish/]() for more information.
@@ -0,0 +1,92 @@
1
+ require 'rake/clean'
2
+
3
+ ##
4
+ # documentation
5
+ #
6
+
7
+ desc "Build the documentation."
8
+ task :doc
9
+
10
+ # user manual
11
+ task :doc => 'index.html'
12
+
13
+ file 'index.html' => 'README' do |t|
14
+ sh 'maruku', t.prerequisites[0], '-o', t.name
15
+ end
16
+
17
+ CLOBBER.include 'index.html'
18
+
19
+ # API reference
20
+ task :doc => 'api'
21
+
22
+ require 'rake/rdoctask'
23
+ Rake::RDocTask.new 'api' do |t|
24
+ t.rdoc_dir = t.name
25
+ t.rdoc_files.exclude('pkg').include('**/*.rb')
26
+ end
27
+
28
+
29
+ ##
30
+ # packaging
31
+ #
32
+
33
+ require 'rake/gempackagetask'
34
+ require 'lib/babelfish' # project info
35
+
36
+ spec = Gem::Specification.new do |s|
37
+ s.rubyforge_project = 'sunaku'
38
+ s.author, s.email = File.read('LICENSE').
39
+ scan(/Copyright \d+ (.*) <(.*?)>/).first
40
+
41
+ s.name = BabelFish::PROJECT
42
+ s.version = BabelFish::VERSION
43
+ s.summary = BabelFish::SUMMARY
44
+ s.description = s.summary
45
+ s.homepage = BabelFish::WEBSITE
46
+ s.files = FileList['**/*']
47
+ s.executables = s.name
48
+ s.has_rdoc = true
49
+
50
+ # gems needed by the command line interface
51
+ s.add_dependency 'trollop', '~> 1.10'
52
+
53
+ # gems needed by the ruby library
54
+ s.add_dependency 'hpricot', '~> 0.6'
55
+ end
56
+
57
+ Rake::GemPackageTask.new(spec) do |pkg|
58
+ pkg.need_tar = true
59
+ pkg.need_zip = true
60
+ end
61
+
62
+ desc 'Build release packages.'
63
+ task :pack => [:clobber, :doc] do
64
+ sh $0, 'package'
65
+ end
66
+
67
+
68
+ ##
69
+ # releasing
70
+ #
71
+
72
+ desc 'Upload to project website.'
73
+ task :website => :doc do
74
+ sh "rsync -av index.html api ~/www/lib/#{spec.name} --delete"
75
+ end
76
+
77
+ desc 'Publish release packages.'
78
+ task :publish => :pack do
79
+ sh 'rubyforge', 'login'
80
+
81
+ pusher = lambda do |cmd, pkg|
82
+ sh 'rubyforge', cmd, '--release_date', BabelFish::RELEASE,
83
+ spec.rubyforge_project, spec.name, spec.version.to_s, pkg
84
+ end
85
+
86
+ packs = Dir['pkg/*.[a-z]*']
87
+
88
+ # push ONLY the first package using 'add_release'. otherwise, we
89
+ # get one package per sub-section on the RubyForge download page!
90
+ pusher['add_release', packs.shift]
91
+ packs.each {|pkg| pusher['add_file', pkg] }
92
+ end
@@ -0,0 +1,246 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: BabelFish</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">BabelFish</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/babelfish_rb.html">
59
+ lib/babelfish.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+ <div id="description">
76
+ <p>
77
+ Ruby interface to Yahoo! <a href="BabelFish.html">BabelFish</a> translation
78
+ service.
79
+ </p>
80
+
81
+ </div>
82
+
83
+
84
+ </div>
85
+
86
+ <div id="method-list">
87
+ <h3 class="section-bar">Methods</h3>
88
+
89
+ <div class="name-list">
90
+ <a href="#M000001">translate</a>&nbsp;&nbsp;
91
+ </div>
92
+ </div>
93
+
94
+ </div>
95
+
96
+
97
+ <!-- if includes -->
98
+
99
+ <div id="section">
100
+
101
+
102
+ <div id="constants-list">
103
+ <h3 class="section-bar">Constants</h3>
104
+
105
+ <div class="name-list">
106
+ <table summary="Constants">
107
+ <tr class="top-aligned-row context-row">
108
+ <td class="context-item-name">PROJECT</td>
109
+ <td>=</td>
110
+ <td class="context-item-value">'babelfish'</td>
111
+ <td width="3em">&nbsp;</td>
112
+ <td class="context-item-desc">
113
+ project information
114
+
115
+ </td>
116
+ </tr>
117
+ <tr class="top-aligned-row context-row">
118
+ <td class="context-item-name">VERSION</td>
119
+ <td>=</td>
120
+ <td class="context-item-value">'0.0.1'</td>
121
+ </tr>
122
+ <tr class="top-aligned-row context-row">
123
+ <td class="context-item-name">RELEASE</td>
124
+ <td>=</td>
125
+ <td class="context-item-value">'2008-12-30'</td>
126
+ </tr>
127
+ <tr class="top-aligned-row context-row">
128
+ <td class="context-item-name">WEBSITE</td>
129
+ <td>=</td>
130
+ <td class="context-item-value">&quot;http://snk.tuxfamily.org/lib/#{PROJECT}&quot;</td>
131
+ </tr>
132
+ <tr class="top-aligned-row context-row">
133
+ <td class="context-item-name">SUMMARY</td>
134
+ <td>=</td>
135
+ <td class="context-item-value">'Ruby interface to Yahoo! BabelFish translation service.'</td>
136
+ </tr>
137
+ <tr class="top-aligned-row context-row">
138
+ <td class="context-item-name">DISPLAY</td>
139
+ <td>=</td>
140
+ <td class="context-item-value">PROJECT + ' ' + VERSION</td>
141
+ </tr>
142
+ <tr class="top-aligned-row context-row">
143
+ <td class="context-item-name">INSTALL</td>
144
+ <td>=</td>
145
+ <td class="context-item-value">File.expand_path(File.join(File.dirname(__FILE__), '..'))</td>
146
+ </tr>
147
+ <tr class="top-aligned-row context-row">
148
+ <td class="context-item-name">SERVICE_URI</td>
149
+ <td>=</td>
150
+ <td class="context-item-value">URI.parse('http://babelfish.yahoo.com/translate_txt')</td>
151
+ <td width="3em">&nbsp;</td>
152
+ <td class="context-item-desc">
153
+ the URI through which the translation service is accessed
154
+
155
+ </td>
156
+ </tr>
157
+ <tr class="top-aligned-row context-row">
158
+ <td class="context-item-name">LANGUAGE_NAMES</td>
159
+ <td>=</td>
160
+ <td class="context-item-value">{}</td>
161
+ <td width="3em">&nbsp;</td>
162
+ <td class="context-item-desc">
163
+ Provides access to a language&#8216;s name when given a language code.
164
+
165
+ </td>
166
+ </tr>
167
+ <tr class="top-aligned-row context-row">
168
+ <td class="context-item-name">LANGUAGE_PAIRS</td>
169
+ <td>=</td>
170
+ <td class="context-item-value">Hash.new {|h,k| h[k] = Set.new }</td>
171
+ <td width="3em">&nbsp;</td>
172
+ <td class="context-item-desc">
173
+ Provides access to a list of destination language codes when given a source
174
+ language code. In other words, this hash tells you the possible
175
+ translations that are supported by the service.
176
+
177
+ </td>
178
+ </tr>
179
+ <tr class="top-aligned-row context-row">
180
+ <td class="context-item-name">LANGUAGE_CODES</td>
181
+ <td>=</td>
182
+ <td class="context-item-value">LANGUAGE_PAIRS.keys</td>
183
+ <td width="3em">&nbsp;</td>
184
+ <td class="context-item-desc">
185
+ A list of possible language codes supported by the service.
186
+
187
+ </td>
188
+ </tr>
189
+ </table>
190
+ </div>
191
+ </div>
192
+
193
+
194
+
195
+
196
+
197
+
198
+ <!-- if method_list -->
199
+ <div id="methods">
200
+ <h3 class="section-bar">Public Class methods</h3>
201
+
202
+ <div id="method-M000001" class="method-detail">
203
+ <a name="M000001"></a>
204
+
205
+ <div class="method-heading">
206
+ <a href="BabelFish.src/M000001.html" target="Code" class="method-signature"
207
+ onclick="popupCode('BabelFish.src/M000001.html');return false;">
208
+ <span class="method-name">translate</span><span class="method-args">(input_text, input_lang_code, output_lang_code, output_encoding = 'utf-8')</span>
209
+ </a>
210
+ </div>
211
+
212
+ <div class="method-description">
213
+ <p>
214
+ Translates the given input from the given source language into the given
215
+ destination language.
216
+ </p>
217
+ <table>
218
+ <tr><td valign="top">input_text:</td><td>the text you want to <a href="BabelFish.html#M000001">translate</a>
219
+
220
+ </td></tr>
221
+ <tr><td valign="top">input_lang_code:</td><td>the code of the language in which the input text is written
222
+
223
+ </td></tr>
224
+ <tr><td valign="top">output_lang_code:</td><td>language code of the result of translation
225
+
226
+ </td></tr>
227
+ <tr><td valign="top">output_encoding:</td><td>desired encoding of the result of translation
228
+
229
+ </td></tr>
230
+ </table>
231
+ </div>
232
+ </div>
233
+
234
+
235
+ </div>
236
+
237
+
238
+ </div>
239
+
240
+
241
+ <div id="validator-badges">
242
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
243
+ </div>
244
+
245
+ </body>
246
+ </html>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>translate (BabelFish)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/babelfish.rb, line 64</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-constant">BabelFish</span>.<span class="ruby-identifier">translate</span> <span class="ruby-identifier">input_text</span>, <span class="ruby-identifier">input_lang_code</span>, <span class="ruby-identifier">output_lang_code</span>, <span class="ruby-identifier">output_encoding</span> = <span class="ruby-value str">'utf-8'</span>
15
+ <span class="ruby-identifier">output_page</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">post_form</span>(
16
+ <span class="ruby-constant">SERVICE_URI</span>,
17
+ <span class="ruby-identifier">:eo</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">output_encoding</span>,
18
+ <span class="ruby-identifier">:lp</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;#{input_lang_code}_#{output_lang_code}&quot;</span>,
19
+ <span class="ruby-identifier">:trtext</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">input_text</span>.<span class="ruby-identifier">to_s</span>
20
+ )
21
+
22
+ <span class="ruby-identifier">doc</span> = <span class="ruby-constant">Hpricot</span>(<span class="ruby-identifier">output_page</span>.<span class="ruby-identifier">body</span>)
23
+ (<span class="ruby-identifier">doc</span> <span class="ruby-operator">/</span> <span class="ruby-value str">'#result'</span> <span class="ruby-operator">/</span> <span class="ruby-value str">'div'</span>).<span class="ruby-identifier">inner_html</span>
24
+ <span class="ruby-keyword kw">end</span></pre>
25
+ </body>
26
+ </html>
@@ -0,0 +1 @@
1
+ Tue, 30 Dec 2008 00:56:39 -0800
@@ -0,0 +1,113 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: babelfish.rb</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>babelfish.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>lib/babelfish.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Tue Dec 30 00:39:25 -0800 2008</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+
72
+ <div id="requires-list">
73
+ <h3 class="section-bar">Required files</h3>
74
+
75
+ <div class="name-list">
76
+ open-uri&nbsp;&nbsp;
77
+ net/http&nbsp;&nbsp;
78
+ uri&nbsp;&nbsp;
79
+ set&nbsp;&nbsp;
80
+ rubygems&nbsp;&nbsp;
81
+ hpricot&nbsp;&nbsp;
82
+ </div>
83
+ </div>
84
+
85
+ </div>
86
+
87
+
88
+ </div>
89
+
90
+
91
+ <!-- if includes -->
92
+
93
+ <div id="section">
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ <!-- if method_list -->
103
+
104
+
105
+ </div>
106
+
107
+
108
+ <div id="validator-badges">
109
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
110
+ </div>
111
+
112
+ </body>
113
+ </html>
@@ -0,0 +1,27 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Classes
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Classes</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Classes</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/BabelFish.html">BabelFish</a><br />
24
+ </div>
25
+ </div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,27 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Files
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Files</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Files</h1>
22
+ <div id="index-entries">
23
+ <a href="files/lib/babelfish_rb.html">lib/babelfish.rb</a><br />
24
+ </div>
25
+ </div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,27 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Methods
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Methods</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Methods</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/BabelFish.html#M000001">translate (BabelFish)</a><br />
24
+ </div>
25
+ </div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ RDoc Documentation
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>RDoc Documentation</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="files/lib/babelfish_rb.html" name="docwin" />
23
+ </frameset>
24
+ </html>
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # Command-line interface to the Ruby BabelFish library.
4
+ #
5
+ # * The standard input stream will be read if an input file is not specified.
6
+ #
7
+ # * The result of translation will be written to the standard output stream.
8
+ #
9
+ # Usage:
10
+ #
11
+ # babelfish [Option...] InputLanguage OutputLanguage [InputFile]
12
+ #
13
+
14
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
15
+ require 'babelfish'
16
+
17
+ ##
18
+ # command line
19
+ #
20
+
21
+ require 'rubygems'
22
+ require 'trollop'
23
+
24
+ opts = Trollop.options do
25
+ # show program description located at the top of this file
26
+ banner File.read(__FILE__)[/\A.*?^$\n/m].
27
+ gsub(/^# ?/, '').sub(/\A.*?\n/, '')
28
+ banner ''
29
+
30
+ # show list of available languages
31
+ banner 'Languages:'
32
+ BabelFish::LANGUAGE_NAMES.each_pair do |code, name|
33
+ banner '%13s : %s' % [code, name]
34
+ end
35
+ banner ''
36
+
37
+ # show list of available language combinations
38
+ banner 'Input-Output Language Combinations:'
39
+ BabelFish::LANGUAGE_PAIRS.each_pair do |src, dsts|
40
+ dsts.each do |dst|
41
+ banner '%8s %4s : %s to %s' % [
42
+ src, dst,
43
+ BabelFish::LANGUAGE_NAMES[src],
44
+ BabelFish::LANGUAGE_NAMES[dst]
45
+ ]
46
+ end
47
+ end
48
+ banner ''
49
+
50
+ # show list of command-line options
51
+ banner 'Options:'
52
+ opt :encoding, 'Encoding of the result of translation.', :default => 'utf-8'
53
+
54
+ # show program version information
55
+ version [
56
+ "project: #{BabelFish::PROJECT}",
57
+ "version: #{BabelFish::VERSION}",
58
+ "release: #{BabelFish::RELEASE}",
59
+ "website: #{BabelFish::WEBSITE}",
60
+ "install: #{BabelFish::INSTALL}",
61
+ ].join("\n")
62
+ end
63
+
64
+ ##
65
+ # program body
66
+ #
67
+
68
+ input_code = ARGV.shift or
69
+ raise ArgumentError, 'InputLanguage was not specified'
70
+
71
+ output_code = ARGV.shift or
72
+ raise ArgumentError, 'OutputLanguage was not specified'
73
+
74
+ puts BabelFish.translate(ARGF.read, input_code, output_code, opts[:encoding])
@@ -0,0 +1,74 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC
3
+ "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
4
+ "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
5
+ <html xmlns:svg='http://www.w3.org/2000/svg' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
6
+ <head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title>babelfish : Ruby interface to Yahoo! BabelFish translation service</title></head>
7
+ <body>
8
+ <h1 id='babelfish__ruby_interface_to_yahoo_babelfish_translation_service'>babelfish : Ruby interface to Yahoo! BabelFish translation service</h1>
9
+
10
+ <p>This is a completely <em>unofficial</em> (and incredibly simple) Ruby interface to the Yahoo! BabelFish translation service. Enjoy!</p>
11
+
12
+ <h2 id='installation'>Installation</h2>
13
+
14
+ <p>Run the following command to install this library:</p>
15
+
16
+ <pre><code>sudo gem install babelfish</code></pre>
17
+
18
+ <h2 id='usage_command_line'>Usage: Command Line</h2>
19
+
20
+ <p>Here are some examples of using the command-line interface:</p>
21
+
22
+ <pre><code># echo &quot;Hello world!&quot; | babelfish en es
23
+ ¡Hola mundo!
24
+
25
+ # echo &quot;How are you?&quot; &gt; foo.txt
26
+ # babelfish en es foo.txt
27
+ ¿Cómo está usted?</code></pre>
28
+
29
+ <p>Run <code>babelfish --help</code> to see the list of supported languages.</p>
30
+
31
+ <h2 id='usage_ruby_library'>Usage: Ruby Library</h2>
32
+
33
+ <p>Here is an example of using the library in Ruby:</p>
34
+
35
+ <pre><code>require &#39;rubygems&#39;
36
+ require &#39;babelfish&#39;
37
+
38
+ input_text = &quot;I am well, thank you.&quot;
39
+ input_code = &quot;en&quot;
40
+
41
+ puts input_text
42
+ BabelFish::LANGUAGE_PAIRS[input_code].each do |output_code|
43
+ print &quot; in #{BabelFish::LANGUAGE_NAMES[output_code]} is: &quot;
44
+ puts BabelFish.translate(input_text, input_code, output_code)
45
+ end</code></pre>
46
+
47
+ <p>The result of running the above example is:</p>
48
+
49
+ <pre><code>I am well, thank you.
50
+ in Italian is: Sono bene, grazie.
51
+ in Japanese is: 私は元気でいる、ありがとう。
52
+ in German is: Ich fÃehle mich gut, danke.
53
+ in French is: Je vais bien, merci.
54
+ in Spanish is: Estoy bien, gracias.
55
+ in Russian is: Я наилучшим образом, вы.
56
+ in Chinese-simp is: 我很好,谢谢。
57
+ in Portuguese is: Eu sou bem, obrigado.
58
+ in Korean is: 나는 잘 있다, 당신을 감사하십시오.
59
+ in Chinese-trad is:
60
+ in Greek is: Είμαι καλά, σας ευχαριστώ.
61
+ in Dutch is: Ik ben goed, dank u.</code></pre>
62
+
63
+ <p>Read the <a href='api/index.html'>RDoc documentation</a> for more information.</p>
64
+
65
+ <h2 id='license'>License</h2>
66
+
67
+ <p>Copyright 2007 Suraj N. Kurapati <a href='mailto:sunaku@gmail.com'>&#115;&#117;&#110;&#097;&#107;&#117;&#064;&#103;&#109;&#097;&#105;&#108;&#046;&#099;&#111;&#109;</a></p>
68
+
69
+ <p>Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.</p>
70
+
71
+ <p>THE SOFTWARE IS PROVIDED &#8220;AS IS&#8221; AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</p>
72
+ <hr />
73
+ <p>Visit <a href=''>http://snk.tuxfamily.org/lib/babelfish/</a> for more information.</p>
74
+ </body></html>
@@ -0,0 +1,75 @@
1
+ require 'open-uri'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'set'
5
+
6
+ require 'rubygems'
7
+ require 'hpricot'
8
+
9
+ # Ruby interface to Yahoo! BabelFish translation service.
10
+ module BabelFish
11
+ ##
12
+ # project information
13
+ #
14
+
15
+ PROJECT = 'babelfish'
16
+ VERSION = '0.0.1'
17
+ RELEASE = '2008-12-30'
18
+ WEBSITE = "http://snk.tuxfamily.org/lib/#{PROJECT}"
19
+ SUMMARY = 'Ruby interface to Yahoo! BabelFish translation service.'
20
+ DISPLAY = PROJECT + ' ' + VERSION
21
+ INSTALL = File.expand_path(File.join(File.dirname(__FILE__), '..'))
22
+
23
+ ##
24
+ # service connection
25
+ #
26
+
27
+ # the URI through which the translation service is accessed
28
+ SERVICE_URI = URI.parse('http://babelfish.yahoo.com/translate_txt')
29
+
30
+ # Provides access to a language's name when given a language code.
31
+ LANGUAGE_NAMES = {} # code => name
32
+
33
+ # Provides access to a list of destination language codes when
34
+ # given a source language code. In other words, this hash tells
35
+ # you the possible translations that are supported by the service.
36
+ LANGUAGE_PAIRS = Hash.new {|h,k| h[k] = Set.new } # code => [code]
37
+
38
+ # determine what translations are supported by the service
39
+ open(SERVICE_URI).read.
40
+ scan(/<option\s+value="(\w+)_(\w+)">(.*?)\s+to\s+(.*?)</).
41
+ each do |src_code, dst_code, src_name, dst_name|
42
+ LANGUAGE_NAMES[src_code] = src_name
43
+ LANGUAGE_NAMES[dst_code] = dst_name
44
+
45
+ LANGUAGE_PAIRS[src_code] << dst_code
46
+ end
47
+
48
+ # A list of possible language codes supported by the service.
49
+ LANGUAGE_CODES = LANGUAGE_PAIRS.keys
50
+
51
+ ##
52
+ # service interface
53
+ #
54
+
55
+ # Translates the given input from the given source
56
+ # language into the given destination language.
57
+ #
58
+ # input_text:: the text you want to translate
59
+ # input_lang_code:: the code of the language in
60
+ # which the input text is written
61
+ # output_lang_code:: language code of the result of translation
62
+ # output_encoding:: desired encoding of the result of translation
63
+ #
64
+ def BabelFish.translate input_text, input_lang_code, output_lang_code, output_encoding = 'utf-8'
65
+ output_page = Net::HTTP.post_form(
66
+ SERVICE_URI,
67
+ :eo => output_encoding,
68
+ :lp => "#{input_lang_code}_#{output_lang_code}",
69
+ :trtext => input_text.to_s
70
+ )
71
+
72
+ doc = Hpricot(output_page.body)
73
+ (doc / '#result' / 'div').inner_html
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: babelfish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Suraj N. Kurapati
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-30 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: trollop
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "1.10"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hpricot
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: "0.6"
34
+ version:
35
+ description: Ruby interface to Yahoo! BabelFish translation service.
36
+ email: sunaku@gmail.com
37
+ executables:
38
+ - babelfish
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib
45
+ - lib/babelfish.rb
46
+ - Rakefile
47
+ - bin
48
+ - bin/babelfish
49
+ - index.html
50
+ - api
51
+ - api/classes
52
+ - api/classes/BabelFish.src
53
+ - api/classes/BabelFish.src/M000001.html
54
+ - api/classes/BabelFish.html
55
+ - api/fr_method_index.html
56
+ - api/rdoc-style.css
57
+ - api/files
58
+ - api/files/lib
59
+ - api/files/lib/babelfish_rb.html
60
+ - api/created.rid
61
+ - api/index.html
62
+ - api/fr_file_index.html
63
+ - api/fr_class_index.html
64
+ - LICENSE
65
+ - README
66
+ has_rdoc: true
67
+ homepage: http://snk.tuxfamily.org/lib/babelfish
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project: sunaku
88
+ rubygems_version: 1.3.1
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: Ruby interface to Yahoo! BabelFish translation service.
92
+ test_files: []
93
+