语言云

 

语言云运用例子

# -*- coding:utf8 -*-

# This example shows how to use Python to access the LTP API to perform full
# stack Chinese text analysis including word segmentation, POS tagging, dep-
# endency parsing, name entity recognization and semantic role labeling and
# get the result in specified format.
import urllib2, urllib
import sys
if __name__ == '__main__':
    #if len(sys.argv) < 2 or sys.argv[1] not in ["xml", "json", "conll"]:
    #    print >> sys.stderr, "usage: %s [xml/json/conll]" % sys.argv[0]
    #    sys.exit(1)

    uri_base = "http://ltpapi.voicecloud.cn/analysis/?"
    api_key  = "Z4Z9l7D7vkLNHwcMOkdbvdSlgkLltWIYEYObAfxh"
    text     = "我爱北京天安门"
    # Note that if your text contain special characters such as linefeed or ‘&‘,
    # you need to use urlencode to encode your data
    text     = urllib.quote(text)
    format   = "xml"
    pattern  = "all"

    url= (uri_base
                + "api_key=" + api_key + "&"
                + "text="    + text    + "&"
                + "format="  + format  + "&"
                + "pattern=" + "all")

    try:
        response = urllib2.urlopen(url)
        content  = response.read().strip()
        print content.decode('utf-8').encode('gbk')
    except urllib2.HTTPError, e:
        print >> sys.stderr, e.reason

 

转载于:https://www.cnblogs.com/XDJjy/p/4942317.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值