Translating parts of datasets with R

匆匆过客 提交于 2019-12-08 03:36:42

问题


I am intending on translating simple text in string variables in datasets with R. I have looked at the translateR package but following the example in the help file I stumbled across the need for a Google API access.

This is not a free service as I have become aware. There are other APIS (Bing for example) but I guess there is no way in R to get to it?

Any ideas on how to mass translate certain string data in a data frame? Or what I could look into?


回答1:


It's all in the manual: ?translateR::translate:

To use the Microsoft API, a client id and a client secret value must be provided. For more information on getting these, see http://msdn.microsoft.com/en-us/library/hh454950.aspx. NOTE: you do not need to obtain an access token. translateR will retrieve a token internally.

library(translateR)
res <- translate(content.vec = c("Hello world.", "This is a test."), 
                  microsoft.client.id = "foo_id", 
                  microsoft.client.secret = "fdsg54345_bar_secret_560985lkfdasd", 
                  source.lang = "en", 
                  target.lang = "de")
res
# [1] "Hallo Welt."        "Dies ist ein Test."


来源:https://stackoverflow.com/questions/36598241/translating-parts-of-datasets-with-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!