如何在Matlab中使用Google翻译? [英] How to use Google Translate in Matlab?

查看:234
本文介绍了如何在Matlab中使用Google翻译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,以使用Matlab列出电影字幕文件中的所有唯一单词.现在,我有一个独特的单词列表,我想翻译成我的语言并在看电影之前学习其含义.

I am writing a program to list all unique words in a movie subtitle file using Matlab. Now I have a unique word list that I want to translate to my language and learn the meaning before watching the movie.

有人知道如何在Matlab中使用Google翻译,以便完成脚本吗?是否有任何Web服务,如何在Matlab中使用它?

Does anyone know how can I use Google Translate in Matlab so that I can complete my script? Is there any web service or so, and how can I use it in Matlab?

谢谢

附录1: 我发现此代码很有用:

Appendix 1: I have found this code useful:

%build url and send to google
url = 'http://ajax.googleapis.com/ajax/services/language/translate';
page = urlread(url, 'get', {'v', '1.0','q', inputString,'langpair', [sourceLanguage '|' destLanguage]});

,但是我不知道为什么每次运行它都会返回错误(例如403400).我知道测试时我的互联网连接可以.

but I don't know why it returns error each time I run it (e.g. 403 or 400). I know that my internet connection is okay when testing.

推荐答案

对于一个简单的翻译人员(我不了解质量),也许可以尝试一下.我没有理会解析输出:

For a simple translator (I have no idea about quality), maybe try this. I didn't bother parsing the output:

langCodes = urlread('http://www.transltr.org/api/getlanguagesfortranslate'); % find your language code

textToTranslate = 'rabbit'; %change

langCodeOfOrigText ='en';
langCodeOfTranslation ='es';

translateURL = 'http://www.transltr.org/api/translate';
translateResults = urlread(translateURL, 'get', {'text',textToTranslate,'to',langCodeOfTranslation,'from',langCodeOfOrigText});

请仅在输出的translationText旁边查看结果.就像我说的,您可以解析它,只需在google上找到一个json即可将matlab结构解析器解析.

Just see next to translationText of the output for the result. Like I said, you can parse it, just google for a json to matlab struct parser.

这篇关于如何在Matlab中使用Google翻译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆