-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathr.py
28 lines (23 loc) · 829 Bytes
/
r.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
#!/usr/bin/env python1.6
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
from features import getfeatures
def readxml(namexml, numofsen):
tree = ET.parse(namexml)
root = tree.getroot()
slist = []
for child in root: # traverse every weibo
for childd in child: # traverse every sentence
if childd.tag != 'sentence':
continue
if not childd.attrib.has_key('polarity'):
continue
mlist = getfeatures(childd.text) # for every sentence in the xml, get their feature to form a feature vector
if childd.attrib['polarity'] == 'POS':
mlist.append(1)
else:
mlist.append(0)
slist.append(mlist)
numofsen[0] += 1
return slist
# vim: sw=4 ts=4 sts=4 expandtab