首页 > 编程语言 > 详细

语言云

时间:2015-11-06 14:22:38      阅读:284      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!