Tencent_机器翻译_文本翻译
生活随笔
收集整理的這篇文章主要介紹了
Tencent_机器翻译_文本翻译
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
這里是引用
# import json import cv2 import requests import uuid from tencentcloud.common import credential from tencentcloud.common.profile.client_profile import ClientProfile from tencentcloud.common.profile.http_profile import HttpProfile from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKExceptionfrom tencentcloud.tmt.v20180321 import tmt_client from tencentcloud.tmt.v20180321 import models as tmt_modelsimport numpy as np import base64 import matplotlib.pyplot as plt %matplotlib inline import warnings warnings.filterwarnings("ignore") SecretId="xxxxxxxxxxxxxxxxxxxxxx" SecretKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxx" """ 文本翻譯 https://console.cloud.tencent.com/api /explorer?Product=tmt&Version=2018-03-21&Action=TextTranslate&SignVersion= """ try: cred = credential.Credential(SecretId, SecretKey) httpProfile = HttpProfile()httpProfile.endpoint = "tmt.tencentcloudapi.com"clientProfile = ClientProfile()clientProfile.httpProfile = httpProfileclient = tmt_client.TmtClient(cred, "ap-beijing", clientProfile) SourceText="""Long a focal point of science fiction, AI is no longer a curious theme to ponder for thedistant future – it's here. The best artificial intelligence stocks to buy already use processes like machine learning and neural networks on a daily basis. In fact, if you tookaway AI capabilities from the following companies, their profitability would instantlyplummet – and five of them are trillion-dollar businesses, underscoring the new technology's importance to 2021's economy. The growth of artificial intelligence is also enviable. Leading market intelligence firm IDC projects the AI industry to surge 16.4% in 2021, reaching a size of $554 billion by 2024."""req = tmt_models.TextTranslateRequest()params = {"SourceText": SourceText,"Source": "auto","Target": "zh","ProjectId": 0}req.from_json_string(json.dumps(params))resp = client.TextTranslate(req).to_json_string() resp=json.loads(resp)print(resp) except TencentCloudSDKException as err: print(err) {'TargetText': '\n\n長期以來,人工智能一直是科幻小說的焦點,不再是一個值得思考的奇怪主題\n遙遠的未來-就在這里。值得買入的最好的人工智能股票已經(jīng)在使用\n像機器學習和神經(jīng)網(wǎng)絡這樣的日常過程。事實上,如果你把\n離開以下公司的人工智能能力,他們的盈利能力將立即\n暴跌-其中五項是萬億美元的業(yè)務,突顯了這項新技術(shù)的\n對2021年經(jīng)濟的重要性。人工智能的增長也令人羨慕。\n領(lǐng)先的市場情報公司IDC預計,人工智能行業(yè)在2021年將激增16.4%,\n到2024年達到5540億美元的規(guī)模。\n', 'Source': 'en', 'Target': 'zh', 'RequestId': '3724fa34-a46b-4cad-9fb5-9d266759747a'} """ Action 是 String 公共參數(shù),本接口取值:TextTranslate。 Version 是 String 公共參數(shù),本接口取值:2018-03-21。 Region 是 String 公共參數(shù),詳見產(chǎn)品支持的 地域列表。 SourceText 是 String 待翻譯的文本,文本統(tǒng)一使用utf-8格式編碼, 非utf-8格式編碼字符會翻譯失敗,請傳入有效文本,html標記等非常規(guī)翻譯文本可能會翻譯失敗 。單次請求的文本長度需要低于2000。 Source 是 String 源語言,支持: auto:自動識別(識別為一種語言) zh:簡體中文 zh-TW:繁體中文 en:英語 ja:日語 ko:韓語 fr:法語 es:西班牙語 it:意大利語 de:德語 tr:土耳其語 ru:俄語 pt:葡萄牙語 vi:越南語 id:印尼語 th:泰語 ms:馬來西亞語 ar:阿拉伯語 hi:印地語 Target 是 String 目標語言,各源語言的目標語言支持列表如下zh(簡體中文):en(英語)、ja(日語)、ko(韓語)、fr(法語)、es(西班牙語)、it(意大利語)、de(德語)、tr(土耳其語)、ru(俄語)、pt(葡萄牙語)、vi(越南語)、id(印尼語)、th(泰語)、ms(馬來語) zh-TW(繁體中文):en(英語)、ja(日語)、ko(韓語)、fr(法語)、es(西班牙語)、it(意大利語)、de(德語)、tr(土耳其語)、ru(俄語)、pt(葡萄牙語)、vi(越南語)、id(印尼語)、th(泰語)、ms(馬來語) en(英語):zh(中文)、ja(日語)、ko(韓語)、fr(法語)、es(西班牙語)、it(意大利語)、de(德語)、tr(土耳其語)、ru(俄語)、pt(葡萄牙語)、vi(越南語)、id(印尼語)、th(泰語)、ms(馬來語)、ar(阿拉伯語)、hi(印地語) ja(日語):zh(中文)、en(英語)、ko(韓語) ko(韓語):zh(中文)、en(英語)、ja(日語) fr(法語):zh(中文)、en(英語)、es(西班牙語)、it(意大利語)、de(德語)、tr(土耳其語)、ru(俄語)、pt(葡萄牙語) es(西班牙語):zh(中文)、en(英語)、fr(法語)、it(意大利語)、de(德語)、tr(土耳其語)、ru(俄語)、pt(葡萄牙語) it(意大利語):zh(中文)、en(英語)、fr(法語)、es(西班牙語)、de(德語)、tr(土耳其語)、ru(俄語)、pt(葡萄牙語) de(德語):zh(中文)、en(英語)、fr(法語)、es(西班牙語)、it(意大利語)、tr(土耳其語)、ru(俄語)、pt(葡萄牙語) tr(土耳其語):zh(中文)、en(英語)、fr(法語)、es(西班牙語)、it(意大利語)、de(德語)、ru(俄語)、pt(葡萄牙語) ru(俄語):zh(中文)、en(英語)、fr(法語)、es(西班牙語)、it(意大利語)、de(德語)、tr(土耳其語)、pt(葡萄牙語) pt(葡萄牙語):zh(中文)、en(英語)、fr(法語)、es(西班牙語)、it(意大利語)、de(德語)、tr(土耳其語)、ru(俄語) vi(越南語):zh(中文)、en(英語) id(印尼語):zh(中文)、en(英語) th(泰語):zh(中文)、en(英語) ms(馬來語):zh(中文)、en(英語) ar(阿拉伯語):en(英語) hi(印地語):en(英語) ProjectId 是 Integer 項目ID,可以根據(jù)控制臺-賬號中心-項目管理中的配置填寫,如無配置請?zhí)顚懩J項目ID:0 UntranslatedText 否 String 用來標記不希望被翻譯的文本內(nèi)容,如句子中的特殊符號、人名、地名等;每次請求只支持配置一個 不被翻譯的單詞;僅支持配置人名、地名等名詞,不要配置動詞或短語,否則會影響翻譯結(jié)果。 """ """ https://console.cloud.tencent.com/api /explorer?Product=tmt&Version=2018-03-21&Action=TextTranslateBatch&SignVersion= 批量文本翻譯 """try: cred = credential.Credential(SecretId, SecretKey) httpProfile = HttpProfile()httpProfile.endpoint = "tmt.tencentcloudapi.com"clientProfile = ClientProfile()clientProfile.httpProfile = httpProfileclient = tmt_client.TmtClient(cred, "ap-beijing", clientProfile) req = tmt_models.TextTranslateBatchRequest()SourceTextList=["""Long a focal point of science fiction, AI is no longer a curious theme to ponder for thedistant future – it's here. The best artificial intelligence stocks to buy already use processes like machine learning and neural networks on a daily basis. In fact, if you tookaway AI capabilities from the following companies, their profitability would instantlyplummet – and five of them are trillion-dollar businesses, underscoring the new technology's importance to 2021's economy. The growth of artificial intelligence is also enviable. Leading market intelligence firm IDC projects the AI industry to surge 16.4% in 2021, reaching a size of $554 billion by 2024.""",""""It is in writing that, unless they give themselves in, the Taliban will arrest and prosecute, interrogate and punish family members on behalf of those individuals."He warned that anyone on the Taliban's blacklist was in severe danger, and that there could be mass executions.Foreign powers are continuing efforts to get their nationals out of Afghanistan. A Nato official said on Friday that more than 18,000 people have been evacuated in the last five days from Kabul airport.Some 6,000 more, among them former interpreters for foreign armed forces, are on standby to be flown out late on Thursday or early Friday."""]params = {"Source": "auto","Target": "zh","ProjectId": 0,"SourceTextList": SourceTextList}req.from_json_string(json.dumps(params))resp = client.TextTranslateBatch(req).to_json_string() resp=json.loads(resp)print(resp) except TencentCloudSDKException as err: print(err) {'Source': 'en', 'Target': 'zh', 'TargetTextList': ['\n\n長期以來,人工智能一直是科幻小說的焦點,不再是一個值得思考的奇怪主題\n遙遠的未來-就在這里。值得買入的最好的人工智能股票已經(jīng)在使用\n像機器學習和神經(jīng)網(wǎng)絡這樣的日常過程。事實上,如果你把\n離開以下公司的人工智能能力,他們的盈利能力將立即\n暴跌-其中五項是萬億美元的業(yè)務,突顯了這項新技術(shù)的\n對2021年經(jīng)濟的重要性。人工智能的增長也令人羨慕。\n領(lǐng)先的市場情報公司IDC預計,人工智能行業(yè)在2021年將激增16.4%,\n到2024年達到5540億美元的規(guī)模。\n', '\n“書面規(guī)定,除非他們投降,否則塔利班將逮捕并起訴,\n代表這些人審問和懲罰家庭成員。“\n他警告說,塔利班黑名單上的任何人都處于嚴重危險之中,\n可能會有大規(guī)模的處決。\n外國勢力正在繼續(xù)努力讓他們的國民離開阿富汗。\n一名北約官員周五表示,在過去的五天里,已有超過1.8萬人從喀布爾機場撤離。\n大約6000多人,其中包括前外國武裝部隊的翻譯,\n都處于待命狀態(tài),將在周四晚些時候或周五早些時候起飛。\n\n'], 'RequestId': '94bf5898-d370-431b-b601-a666295496aa'}總結(jié)
以上是生活随笔為你收集整理的Tencent_机器翻译_文本翻译的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Springboot 源码分析 —— @
- 下一篇: 苏州新导化工厂与二道门人员定位解决方案-