機械翻訳APIの翻訳結果が異なる

68 views
Skip to first unread message

タキ

unread,
Nov 21, 2018, 11:24:50 PM11/21/18
to 多言語音声翻訳サンドボックスサーバー技術フォーラム
curlで「こんにちわ」を英語に翻訳すると「Hello.」と翻訳されますが、
iOS Swiftでは「Good afternoon.」と翻訳されてしまいます。これは何が原因だと思いますか?

実際のコードは下記の通りです。

curlの場合
-H "Authorization: Bearer xxxxx-xxxx-xxxxxx-xxxxx" \
-d text=こんにちは \
-d source_lang=ja \
-d target_lang=en
>> ["Hello."]


iOS Swiftの場合

let accessToken = "xxxxx-xxxx-xxxxxx-xxxxx"
var req = URLRequest(url: url!, cachePolicy: URLRequest.CachePolicy.useProtocolCachePolicy, timeoutInterval: 5)
req.httpMethod = "POST"
req.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
req.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")
req.httpBody = "text=こんにちわ&source_lang=ja&target_lang=en".data(using: utf8)

let task = URLSession.shared.dataTask(with: req) { (data, response, error) in
    print(String(data: data!, encoding: .utf8)!) // ["Good afternoon."]が出力される["Good afternoon."]
}
task.resume()

吉川哲史

unread,
Nov 22, 2018, 12:24:29 AM11/22/18
to 多言語音声翻訳サンドボックスサーバー技術フォーラム, ddq...@gmail.com
ご質問の差異ですが、実行環境の差ではなく入力文の差異に因るものです。

・こんにちわ → Good afternoon.

・こんにちは → Hello.


ご確認ください。



2018年11月22日木曜日 13時24分50秒 UTC+9 タキ:

タキ

unread,
Nov 22, 2018, 12:42:24 AM11/22/18
to 多言語音声翻訳サンドボックスサーバー技術フォーラム, ddq...@gmail.com
気付きませんでした。。とても助かりました。ありがとうございました。

2018年11月22日木曜日 14時24分29秒 UTC+9 吉川哲史:
Reply all
Reply to author
Forward
0 new messages