LoginSignup
10
9

More than 5 years have passed since last update.

Microsoftの翻訳API をRから使う

Last updated at Posted at 2016-02-09

translateR というパッケージからMicrosoft翻訳を使って、Rでテキストを翻訳する。対応言語はこのサイトを参照。

library(translateR)
txt <- c("Hello", "How are you?", "What's your name?")
translate(content.vec = txt,
          microsoft.client.id = "<Client ID>",
          microsoft.client.secret = "<Client Secret>",
          source.lang = "en", target.lang = "ja")
[1] "こんにちは"      "お元気ですか。"     "あなたの名前は何ですか。"

Microsoft Translatorにサインアップ(参考


  • 「無料で2百万字プラン」を選択 img.PNG

  • マイクロソフトアカウントがない場合は作ってサインイン。 img2.PNG

  • Microsoft Translatorにサインアップ Screenshot from 2016-02-09 21:59:03.png

開発者ページへ行き、アプリケーションを登録

Screenshot from 2016-02-09 22:03:57.png


  • クライアントID は既存のものとかぶらないものを、リダイレクトURIは無効なURLを指定する(例:https://localhost/)
  • クライアントIDと顧客の秘密はあとで使うのでメモしておく。 Screenshot from 2016-02-09 22:07:18.png

Rから利用する。

translateRはインストールしておく(install.packages("translateR"))。

library(translateR)
txt <- c("Hello", "How are you?", "What's your name?")
translate(
  content.vec = txt,
  microsoft.client.id = "<クライアントID>",
  microsoft.client.secret = "<顧客の秘密>",
  source.lang = "en", target.lang = "ja")
#[1] "こんにちは"               "お元気ですか。"          
#[3] "あなたの名前は何ですか。"
#Warning message:
#The content appears to be in BRETON. However, the
#language code you provided suggests that the text is in
#ENGLISH. If you entered the wrong language code, stop
#the process. Otherwise, translateR will treat the text
#as ENGLISH. 

警告メッセージは不思議だが(どうしてブルトン語に見えるのか)、きちんと翻訳できている。
対応言語も豊富(一覧)なので、使い道は多そう。

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9