-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract-verbs.py
37 lines (26 loc) · 984 Bytes
/
extract-verbs.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
import xml.etree.ElementTree as ET
import codecs, urllib2, json
xmlSource = "wikipedia_sentences_SRL.xml"
lang = "en"
resultFile = codecs.open("wikipedia-verbs-"+lang, "w", "utf-8")
dump = ET.parse(xmlSource)
root = dump.getroot()
# filter all token entries
tokens = root.findall(".//token")
# filter the verb tokens and get their lemma
lemmata = {}
for token in tokens:
# if token is some kind of verb (VB, VBZ etc)
if token.attrib.get('pos').startswith("VB"):
lemma = token.attrib.get('lemma')
if lemmata.has_key(lemma):
lemmata.update({lemma:lemmata.get(lemma)+1})
else:
lemmata.update({lemma:1})
#print lemmata
json.dump(lemmata, resultFile)
"""
sample SRL request via curl:
-----------------------------
curl -H 'Content-type:text/xml' -d '<analyze><text>Cave Story is a freeware platform-adventure video game released in 2004 for the PC.</text><target>relations</target></analyze>' 'http://141.52.218.56:9090/axis2/services/analysis_en/analyze'
"""