0

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?

grethcool
  • 1
  • 2
  • You could this package: https://cran.r-project.org/web/packages/translateR/index.html – deschen Mar 30 '22 at 09:00
  • I did try to do it. ``` 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') ``` That was the error code: ```In mclapply(to.translate, function(x) microsoftTranslate(x, microsoft.api.key, : all scheduled cores encountered errors in user code``` – grethcool Mar 30 '22 at 10:29
  • Does this help? https://stackoverflow.com/a/49079935/2725773 – deschen Mar 30 '22 at 13:26
  • Unfortunately not :( – grethcool Mar 30 '22 at 18:47
  • Then we probably can't help you unless you share an example of your data and your code. https://stackoverflow.com/help/minimal-reproducible-example – deschen Mar 30 '22 at 19:23
  • I updated the problem. Is hope this is better understandable now. – grethcool Mar 31 '22 at 08:09
  • Did you actually check the help function? I.e. the `translate` function doesn't have a parameter microsoft.api.key. Instead, it needs a cleitn id and client secret. https://www.rdocumentation.org/packages/translateR/versions/1.0/topics/translate – deschen Mar 31 '22 at 08:59
  • It has been updated https://stackoverflow.com/questions/53803383/r-package-translater-and-microsoft-api – grethcool Mar 31 '22 at 09:03
  • I see. But just mkaing sure: you've installed the github version, not the Cran version? I.e. ###Install devtools### install.packages("devtools") ###Install development version of translateR### devtools::install_github("ChristopherLucas/translateR") – deschen Mar 31 '22 at 09:12
  • Also did you try to set the microsoft.token parameter to TRUE as suggested in the documentation? – deschen Mar 31 '22 at 09:12
  • I did install the github version. I seemed to work then, when I set the microsoft.token parameter to TRUE. However, after a while, I got this output ``` Error in curl::curl_fetch_memory(url, handle = handle) : LibreSSL SSL_read: Connection reset by peer, errno 54``` – grethcool Apr 01 '22 at 18:33
  • https://stackoverflow.com/questions/55732972/curl-56-libressl-ssl-read-ssl-error-syscall-errno-54 – deschen Apr 01 '22 at 21:40
  • It seems to be working now! Thanks a lot :-) – grethcool Apr 04 '22 at 05:31

0 Answers0