zoukankan      html  css  js  c++  java
  • 有道翻译API

    有道翻译API使用起来非常简单。给定参数,发送请求,即可拿到结果。

    # -*- coding: utf-8 -*-
    # author: huihui
    # date: 2020/2/21 5:19 下午 
    import requests
    
    url = "http://fanyi.youdao.com/translate"
    
    
    def get_trans(line):
        data = {
            'doctype': 'json',
            'type': 'AUTO',
            'i': line
        }
        r = requests.get(url, params=data)
        result = r.json()
        print(result)
    
    
    line = '安徽省亳州市漆园街道花园村,排列有序的光伏成为乡村一道靓丽的风景。近年来,安徽省亳州市蒙城县漆园街道通过与光伏发电企业及农业企业合作,建成运行40MW光伏发电项目,并建设290栋农业设施大棚,将太阳能发电与设施农业有机结合,实现棚顶光伏发电、棚内设施种植蔬菜、中药材等,最大限度发挥光伏电站的效益,不仅为当地农民增加收入,壮大村级集体经济,助力乡村振兴。'
    get_trans(line)
    

    返回结果:

    {'type': 'ZH_CN2EN', 'errorCode': 0, 'elapsedTime': 116, 'translateResult': [
            [
                {'src': '安徽省亳州市漆园街道花园村,排列有序的光伏成为乡村一道靓丽的风景。', 'tgt': 'Anhui province bozhou city paint garden street garden village, an orderly photovoltaic become village a beautiful beautiful scenery.'
                },
                {'src': '近年来,安徽省亳州市蒙城县漆园街道通过与光伏发电企业及农业企业合作,建成运行40MW光伏发电项目,并建设290栋农业设施大棚,将太阳能发电与设施农业有机结合,实现棚顶光伏发电、棚内设施种植蔬菜、中药材等,最大限度发挥光伏电站的效益,不仅为当地农民增加收入,壮大村级集体经济,助力乡村振兴。', 'tgt': 'In recent years, the anhui province bozhou city mengcheng paint garden street through cooperation with photovoltaic power generation enterprises and agricultural enterprises, the running 40 mw photovoltaic power generation project, and to build 290 greenhouses of agricultural facilities, the organic combination of solar and facility agriculture, the roof photovoltaic, relative facility cultivation of vegetables, medicinal herbs, etc., the maximum play to the benefit of the photovoltaic power station, not only for the local farmers to increase income, strengthen the village-level collective economy, boost rural revitalization.'
                }
            ]
        ]
    }
    

    可以看到,API内部会进行分句。所以,如果是多个句子的话,需要重新join一下结果中的tgt。

    本文仅供学习使用

  • 相关阅读:
    行列式学习笔记
    二项式反演学习笔记
    【AtCoder】ARC096(C
    【LOJ】#2127. 「HAOI2015」按位或
    [ACM] POJ 1218 THE DRUNK JAILER (关灯问题)
    lua的弱弱引用表
    西班牙式软件团队
    【DRP】採用dom4j完毕XML文件导入数据库
    基于Linux平台病毒Wirenet.c解析
    【剑指offer】异或去重
  • 原文地址:https://www.cnblogs.com/xuehuiping/p/15185897.html
Copyright © 2011-2022 走看看