-
Notifications
You must be signed in to change notification settings - Fork 0
/
POSTagger.py
executable file
·50 lines (42 loc) · 1.72 KB
/
POSTagger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import requests,sys
from html.parser import HTMLParser
class POSTagger:
def analyze(self):
pass
#session = requests.Session()
class PalavraPOSTagger(POSTagger):
def __init__(self,argv):
cookies = {'VISLSessionID':'434001961b9d41df08406bb455784ff2', 'VISLLastLanguage':'pt', 'VISLUniqueID':'e698acd58e6bd5fd383f0a2096a399495c185618'}
url = 'http://visl.sdu.dk/visl/pt/parsing/automatic/parse.php'
headers = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36'}
data = {'text':' '.join(argv), 'parser':'morphdis', 'visual':'niceline'}
p = requests.post(url, cookies=cookies, headers=headers, data=data)
self.parser = PalavraParser()
self.parser.feed(p.text)
def analyze(self):
return self.parser.response[1:-1]
class PalavraParser(HTMLParser):
def __init__(self):
super(PalavraParser, self).__init__()
self.startResponse = False
self.response=[[]]
def handle_starttag(self, tag, attrs):
if self.startResponse == False:
if tag == 'dl':
self.startResponse=True
elif tag == 'dt':
# self.response[-1] = self.response[-1].split()
self.response.append([])
def handle_endtag(self, tag):
if self.startResponse == True and tag == 'dl':
self.startResponse = False
def handle_data(self, data):
if self.startResponse and data and self.response:
data = data.strip()
if data:
self.response[-1].append(data)
def main(argv):
print(PalavraPOSTagger(argv).analyze())
if __name__ == "__main__":
main(sys.argv[1:])