Difference between revisions of "Python3 Interactive Client"

From Textserver wiki
Jump to: navigation, search
 
Line 5: Line 5:
  
 
# set query elements
 
# set query elements
text = raw_input('Text to analyze: ')
+
text = input('Text to analyze: ')
lang = raw_input('Language: ')
+
lang = input('Language: ')
out = raw_input('Output format (xml,json,conll,naf): ')
+
out = input('Output format (xml,json,conll,naf): ')
user = raw_input('TextServer Username: ')
+
user = input('TextServer Username: ')
pwd = raw_input('TextServer Password: ')
+
pwd = input('TextServer Password: ')
 
   
 
   
 
# Create request
 
# Create request
request_data = {'username':user
+
request_data = {'username':user,
 
                 'password':pwd,
 
                 'password':pwd,
 
                 'text_input':text,
 
                 'text_input':text,
 
                 'language':lang,
 
                 'language':lang,
                 'output':'xml',
+
                 'output':out,
 
                 'interactive':'1' }
 
                 'interactive':'1' }
  

Latest revision as of 16:39, 3 April 2019

 1 #!/usr/bin/env python3
 2 
 3 import requests
 4 
 5 # set query elements
 6 text = input('Text to analyze: ')
 7 lang = input('Language: ')
 8 out = input('Output format (xml,json,conll,naf): ')
 9 user = input('TextServer Username: ')
10 pwd = input('TextServer Password: ')
11  
12 # Create request
13 request_data = {'username':user,
14                 'password':pwd,
15                 'text_input':text,
16                 'language':lang,
17                 'output':out,
18                 'interactive':'1' }
19 
20 # service URL
21 service = "SERVICENAME"
22 url = "http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws/processQuery/"+service
23 
24 # Send request and get response    
25 resp = requests.post(url, files=request_data)
26 
27 # HTTP error, raise exception
28 if resp.status_code != requests.codes.ok : 
29    resp.raise_for_status()
30 
31 # No error, appropriately process response
32 # (e.g. parsing XML or JSON, and doing clever stuff with the content)
33 print(resp.text)