自然语言处理 NLP-文档翻译状态查询:请求示例

时间:2024-01-17 15:35:04

请求示例

  • 请求示例(查询文档翻译状态)
    GET https://{endpoint}/v1/{project_id}/machine-translation/file-translation/567e6536-****-****-****-826321939656 
    
    Request Header:  
        Content-Type:application/json
        X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
  • Python3语言请求代码示例(查询文档翻译状态)
    # -*- coding: utf-8 -*-
    # 此demo仅供测试使用,建议使用sdk。需提前安装requests,执行pip install requests
    import requests
    
    def nlp_demo():
        # endpoint和project_id需替换,job_id需要替换成[文档翻译任务创建]API返回的job_id信息。
        url = 'https://{endpoint}/v1/{project_id}/machine-translation/file-translation/jobs/{job_id}'
        token = '用户对应region的token'
        header = {
            'Content-Type': 'application/json',
            'X-Auth-Token': token
        }
        resp = requests.get(url, headers=header, verify=False)
        print(resp.json())
    
    if __name__ == '__main__':
        nlp_demo()
  • Java语言请求代码示例(查询文档翻译状态)
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    /**
     * 此demo仅供测试使用,建议使用sdk
     */
    public class NLPDemo {
        public void nlpDemo() {
            try {
                //endpoint和projectId需要替换成实际信息。
                //job_id需要替换成[文档翻译任务创建]API返回的job_id信息。
                URL url = new URL("https://{endpoint}/v1/{project_id}/machine-translation/file-translation/jobs/{job_id}");
                String token = "对应region的token";
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("GET");
                connection.setDoInput(true);
                connection.setDoOutput(true);
                connection.addRequestProperty("Content-Type", "application/json");
                connection.addRequestProperty("X-Auth-Token", token);
    
                InputStream is = connection.getInputStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                while (br.ready()) {
                    System.out.println(br.readLine());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static void main(String[] args) {
            NLPDemo nlpDemo = new NLPDemo();
            nlpDemo.nlpDemo();
        }
    }
support.huaweicloud.com/api-nlp/nlp_03_0074.html