访问R中的Microsoft Translation API

发布于 2025-01-18 04:14:26 字数 1342 浏览 3 评论 0原文

我有很多不同语言的推文,我想将其翻译成Englisch。这些推文是在数据框架中组织的,其中一列是实际文本。

每行都有17列,其中包含不同的信息,例如User_ID,status_id,语言和文本。 看起来这样:

A tibble: 642,581 × 17
   user_id  status_id  created_at screen_name text    source  favorite_count retweet_count quote_count reply_count hashtags
   <chr>    <chr>      <chr>      <chr>       <chr>   <chr>   <chr>          <chr>         <chr>       <chr>       <chr>   
 1 1235580… 138959693… 2021-05-0… China_Lyon  "la bo… "Twitt… 0              15            NA          NA          "c(\"Ch…
 2 NA       135549494… 2021-01-30 Ambassador… "rt : … "<a hr… 0              0             0           0            NA     

由于我的大学,我有一个Azure帐户,所以我有Microsoft API密钥。我已经在Github上看到了有关如何使用Microsoft Translation API的帖子。但是,我在访问API时遇到了问题。关于如何在Phyton或C上进行操作有很多解释,但是没有

R。 API是这样:

data(Tweets_df) 
translation_example <- translateR::translate(dataset = Tweets_df,
content.field = 'text', 
microsoft.api.key = 'my.api.key', 
source.lang = 'de', 
target.lang = 'en') 

但是每当我尝试运行代码时,这是我的错误代码:

In mclapply(to.translate, function(x) microsoftTranslate(x, microsoft.api.key,  :   all scheduled cores encountered errors in user code

所以我想知道,如果此问题是由于无法正确访问API吗?如果是这样,我该如何解决?

I have a large set of Tweets in different languages which I would like to translate to Englisch. The Tweets are organized in a dataframe, where one column is the actual text.

Each row has 17 columns with different information, such as user_id, status_id, language and text.
Looking like this:

A tibble: 642,581 × 17
   user_id  status_id  created_at screen_name text    source  favorite_count retweet_count quote_count reply_count hashtags
   <chr>    <chr>      <chr>      <chr>       <chr>   <chr>   <chr>          <chr>         <chr>       <chr>       <chr>   
 1 1235580… 138959693… 2021-05-0… China_Lyon  "la bo… "Twitt… 0              15            NA          NA          "c(\"Ch…
 2 NA       135549494… 2021-01-30 Ambassador… "rt : … "<a hr… 0              0             0           0            NA     

I have an Azure Account due to my university, so I have the Microsoft API key. I saw already a post here on Github on how to use the Microsoft Translation API. However, I have problems accessing the API. There are a lot of explanations on how to do it on Phyton or C, but none for R. I was wondering, if anyone could help me accessing the Microsoft API in R.

The code example for translating the actual text column, using the Microsoft API is this one:

data(Tweets_df) 
translation_example <- translateR::translate(dataset = Tweets_df,
content.field = 'text', 
microsoft.api.key = 'my.api.key', 
source.lang = 'de', 
target.lang = 'en') 

But whenever I try to run the code, this is my error code:

In mclapply(to.translate, function(x) microsoftTranslate(x, microsoft.api.key,  :   all scheduled cores encountered errors in user code

So I was wondering, if this problem is due to not accessing the API correctly? And if so, how can I solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文