Difference between revisions of "Python3 Interactive Client"
From Textserver wiki
(Created page with "<syntaxhighlight lang="python" line="1" > #!/usr/bin/env python3 import requests # necesari per a la conexio al textserver import requests from xml.dom.minidom import parseS...") |
|||
Line 2: | Line 2: | ||
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||
− | |||
− | |||
− | |||
import requests | import requests | ||
from xml.dom.minidom import parseString | from xml.dom.minidom import parseString | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | # set query elements | |
− | + | text = raw_input('Text to analyze: ') | |
− | + | lang = raw_input('Language: ') | |
− | + | out = raw_input('Output format (xml,json,conll,naf): ') | |
− | + | user = raw_input('TextServer Username: ') | |
− | + | pwd = raw_input('TextServer Password: ') | |
− | + | ||
− | + | # Create request | |
− | + | request_data = {'username':user | |
+ | 'password':pwd, | ||
+ | 'text_input':text, | ||
+ | 'language':lang, | ||
+ | 'output':'xml', | ||
+ | 'interactive':'1' } | ||
+ | |||
+ | # service URL | ||
+ | service = "SERVICENAME" | ||
+ | url = "http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws/processQuery/"+service | ||
+ | |||
+ | # Send request and get response | ||
+ | resp = requests.post(url, files=request_data) | ||
+ | |||
+ | # No error, appropriately process response | ||
+ | # (e.g. parsing XML or JSON, and doing clever stuff with the content) | ||
+ | print(resp.text) |
Revision as of 10:12, 24 August 2018
1 #!/usr/bin/env python3
2
3 import requests
4 from xml.dom.minidom import parseString
5
6 # set query elements
7 text = raw_input('Text to analyze: ')
8 lang = raw_input('Language: ')
9 out = raw_input('Output format (xml,json,conll,naf): ')
10 user = raw_input('TextServer Username: ')
11 pwd = raw_input('TextServer Password: ')
12
13 # Create request
14 request_data = {'username':user
15 'password':pwd,
16 'text_input':text,
17 'language':lang,
18 'output':'xml',
19 'interactive':'1' }
20
21 # service URL
22 service = "SERVICENAME"
23 url = "http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws/processQuery/"+service
24
25 # Send request and get response
26 resp = requests.post(url, files=request_data)
27
28 # No error, appropriately process response
29 # (e.g. parsing XML or JSON, and doing clever stuff with the content)
30 print(resp.text)