ZH cheese: Natural language processing Tool LTP language cloud how to call?

Source: Internet
Author: User
Tags urlencode

Objective

LTP Language Cloud Platform

Support Word segmentation, part-of-speech tagging, named entity recognition, dependency parsing, semantic role labeling ;

Support Custom Word segmentation (you provide the data after the word segmentation, it will help you to annotate), but does not support the custom vocabulary , Support C #, Go, Java, JavaScript, Nodejs, PHP, Python, R, Ruby and other language calls, and some error response, Frequency limits, important notes (which I have not used so far); text

Official website: http://www.ltp-cloud.com/

Working with Documents: http://www.ltp-cloud.com/document/

Online Demo: http://www.ltp-cloud.com/demo/

Various language invocation instances can be downloaded to GitHub: https://github.com/HIT-SCIR/ltp-cloud-api-tutorial

For example, Python version of: Https://github.com/HIT-SCIR/ltp-cloud-api-tutorial/tree/master/Python

STEP1: Register

Apply for an API key at this URL, which will be used later;

STEP2: A simple example (Python version)

(1) Copy code: Copy a piece of code from GitHub (depending on the language you use and the features you need)

(2) Modify the code:

<1> api_key = " yourapikey" in "Yourapikey" Modify the API Key for your STEP1 application;

<2> change the text = " I love Beijing tian ' an door" to the one you want to process;

<3> set different parameters according to the requirements (in fact, only need to Api_key,text,pattern,format Four parameters is enough, carefully look at the pattern):

   

#-*-coding:utf-8-*-#!/usr/bin/env python#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.ImportUrllib2, UrllibImportSYSif __name__=='__main__':    ifLen (SYS.ARGV) < 2orSYS.ARGV[1] not inch["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="Yourapikey"text="I love Beijing Tian ' an gate"    #Note that if your text contain special characters such as linefeed or ' & ',    #You need to use UrlEncode to encode your dataText =urllib.quote (text) format= Sys.argv[1] Pattern=" All"URL=(Uri_base+"api_key="+ Api_key +"&"+"text="+ text +"&"+"format="+ Format +"&"+"pattern="+" All")    Try: Response=urllib2.urlopen (URL) content=Response.read (). Strip ()PrintcontentexceptUrllib2. Httperror, E:Print>> Sys.stderr, E.reason

STEP3: Run

If you want to batch process txt or XML files, you need to write a batch of code, below is the one I used in the Project batch processing a directory TXT file code ( that is, add a layer of loops and set an output ):

1 #-*-coding:utf-8-*-2 #!/usr/bin/env python3 4 #This example shows how to use Python to access the LTP API to perform full5 #stack Chinese text analysis including word segmentation, POS tagging, dep-6 #endency parsing, name entity recognization and semantic role labeling and7 #get the result in specified format.8 9 ImportUrllib2, UrllibTen ImportSYS One  A if __name__=='__main__': -Uri_base ="http://ltpapi.voicecloud.cn/analysis/?" -Api_key ="7132g4z1he3s********dsxtncma1jscse5xumai" the  -f = open ("E:\\pyproj\\others\\rite_sentence.txt") -FW = Open ("E:\\pyproj\\others\\rite_pos.txt",'W') -  +line =F.readline () -      while(line): +Text = Line A         #Note that if your text contain special characters such as linefeed or ' & ', at         #You need to use UrlEncode to encode your data -Text =urllib.quote (text) -Format ="Plain" -Pattern ="POS" -  -URL =(Uri_base in+"api_key="+ Api_key +"&" -+"text="+ text +"&" to+"format="+ Format +"&" ++"pattern="+pattern) -  the         Try: *Response =urllib2.urlopen (URL) $Content =Response.read (). Strip ()Panax Notoginseng             Printcontent -Fw.write (line+content+'\ n') the         exceptUrllib2. Httperror, E: +             Print>>Sys.stderr, E.reason Aline =F.readline () the fw.close () +F.close ()

ZH cheese: Natural language processing Tool LTP language cloud how to call?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.