本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7577660
建立时间:2006年5月29日




[Ruby on Rails]利用google在线翻译制作自己的翻译程序之ruby版
软件技术

lhwork 发表于 2007/2/7 8:46:47

刚学ruby时写的工具,我自己一直在用,放在桌面上,遇到不懂单词就得问它。发在railscn上,ranchgirl修改的更为ruby way。 受blogjava上的帖子启发,实在是个有趣的主意,写了个ruby版本的,对俺这等英语一般的同学来说,google在线翻译经常使用呐,原贴之java版http://www.blogjava.net/ekinglong/archive/2006/11/12/80704.html?Pending=true#Post 500)this.width=500'>require 'net/http'500)this.width=500'>def translate500)this.width=500'>  txt=STDIN.gets500)this.width=500'>  break if txt.strip=='e' or txt.strip=='exit'500)this.width=500'>  temp=txt.split(' ')500)this.width=500'>  if temp[1]=='1' or temp.size==1500)this.width=500'>    langpair='en|zh-CN'500)this.width=500'>  else500)this.width=500'>    langpair='zh-CN|en'500)this.width=500'>  end500)this.width=500'> #使用代理  500)this.width=500'>  $proxy_addr = '127.0.0.1'500)this.width=500'>  $proxy_port = 80500)this.width=500'>500)this.width=500'>  response = Net::HTTP.Proxy($proxy_addr, $proxy_port).post_form(URI.parse("http://translate.google.com/translate_t"),{'text'=>temp[0],'langpair'=>langpair})500)this.width=500'>  response.body =~ /<div id=result_box dir=ltr>(.*)<\/div>/500)this.width=500'>  result = $1 500)this.width=500'>  puts '翻译内容:'+temp[0]500)this.width=500'>  puts 'google返回:'+result500)this.width=500'>  puts '-------------------退出请打e或者exit---------------'500)this.width=500'>  translate500)this.width=500'>end500)this.width=500'>translate500)this.width=500'>ranchgirl修改的版本,没有使用递归: 500)this.width=500'>require 'net/http'500)this.width=500'>def usage500)this.width=500'>  "usage: word [lang2 [lang1]]\n" +500)this.width=500'>  "Translate word from lang1 (default en, English) to lang2 (default es, Spanish)\n" +500)this.width=500'>  "ISO language code: http://www.unicode.org/unicode/onlinedat/languages.html" 500)this.width=500'>end500)this.width=500'>def translate500)this.width=500'>  arr = ARGV500)this.width=500'>  if !arr[0] then puts usage; return end500)this.width=500'>  arr[1] = "es" unless arr[1]500)this.width=500'>  arr[2] = "en" unless arr[2] 500)this.width=500'>  langpair = "#{arr[2]}|#{arr[1]}"   500)this.width=500'>  response = Net::HTTP.post_form(URI.parse("http://translate.google.com/translate_t"),500)this.width=500'>                                 {:text => arr[0], :langpair => langpair})500)this.width=500'>  response.body =~ /<div id=result_box dir=ltr>(.*)<\/div>/500)this.width=500'>  result = $1 500)this.width=500'>  result = "No #{langpair} translation available for #{arr[0]}" if result.size == 0500)this.width=500'>  puts result500)this.width=500'>end500)this.width=500'>translate 


阅读全文(2767) | 回复(1) | 编辑 | 精华
 


回复:利用google在线翻译制作自己的翻译程序之ruby版
软件技术

a(游客)发表评论于2008/2/17 0:06:53

Activity and Intent - Verb and Data The GUI toolkit is generally referred to as the VIEW system. Like DALVIK, the VIEW system was specially designed and optimized by Google for running in embedded environments. Mike indicated that coding should be friendly and familiar to anyone who has worked with user interface toolkits before. (This section covers my understanding of some of the newest and most technical aspects of the platform. My understanding is based on a phone conversation with Mike. A clearer picture will quickly develop as we all get a chance to work with the SDK.) Android takes the idea of an application and breaks it down into bite-sized components—each called an ACTIVITY. As an example, mail is broken down into main components like the following: show a list of email, show email message, create an outgoing message. This componentization should do well in an open source environment where developers can share smaller blocks of code and assemble them into more powerful applications from what is already available. Application-level components or services could be shared for common tasks, such as creating a mail message. It remains to be seen how sharing and distribution of these components evolve, but it's possible that a packaging process similar to Debian and Linux distributions might quickly take hold. Developers use a general purpose data structure, called an INTENT to describe the object (DATA) the component is working on. A VERB, such as "show," and DATA described by an INTENT carry out the user's wishes and display what is requested. The overall application environment is object oriented, e.g., a VIEW is defined to inherit from a master VIEW class. Messages are passed between the objects to control behaviors. For example, when a user clicks on the HOME button, it doesn't launch software, but passes a message into the Android system which allows the developer an opportunity to change the location and behavior of HOME if you have a legitimate reason for doing so. Any time you switch between screens displayed on the phone, your INTENTs are processed like URLs, allowing you to easily navigate from point A in an application to point B. This is a new way of programming for many developers. Google realizes it will take some time for people to see and solve problems as components rather than monolithic programs.


个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


» 1 »

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.344 second(s), page refreshed 144777558 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号