Python3 Interactive Client

From Textserver wiki
Revision as of 09:55, 24 August 2018 by Padro (Talk | contribs) (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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
 1 #!/usr/bin/env python3
 2 
 3 import requests
 4 
 5 # necesari per a la conexio al textserver
 6 import requests
 7 from xml.dom.minidom import parseString
 8   # Create request
 9     request_data = {'username':'jofre',
10                     'password':'jofre.123',
11                     'text_input':text,
12                     'language':lang,
13                     'output':'xml',
14                     'interactive':'1' }
15     url = "http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws/processQuery/tagger"
16     # Send request and get response    
17     resp = requests.post(url, files=request_data)
18 
19     # process response (posar-la en el format adqueat pel RegexpParser)
20     xml = parseString(resp.text)
21     result = []
22     for s in xml.getElementsByTagName("sentence"):
23         tks = []
24         for t in s.getElementsByTagName("token") :
25             tks.append((t.attributes["form"].value, t.attributes["tag"].value))
26             
27         result.append(tks)