码迷,mamicode.com
首页 > 编程语言 > 详细

语言云

时间:2015-11-06 14:24:26      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

 

语言云运用例子

# -*- 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

 

语言云

标签:

原文地址:http://www.cnblogs.com/XDJjy/p/4942317.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!