Mercurial > hg > webaudioevaluationtool
comparison scripts/comment_parser.py @ 873:11e6243fafa9
SMC paper: added boxplot graph, input XML, decreased itemize spacing (also changed index.html page title)
author | Brecht De Man <BrechtDeMan@users.noreply.github.com> |
---|---|
date | Thu, 18 Jun 2015 17:34:27 +0100 |
parents | |
children | 302926cdf3c4 a049c6cf7eb3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 873:11e6243fafa9 |
---|---|
1 import xml.etree.ElementTree as ET | |
2 import os | |
3 import csv | |
4 | |
5 # get every XML file in folder | |
6 for file in os.listdir("."): # You have to put this script in folder where output XML files are. | |
7 if file.endswith(".xml"): | |
8 tree = ET.parse(file) | |
9 root = tree.getroot() | |
10 | |
11 # get list of all page names | |
12 for audioholder in root.findall("./audioholder"): # iterate over pages | |
13 page_name = audioholder.get('id') # get page name | |
14 | |
15 if page_name is None: # ignore 'empty' audio_holders | |
16 break | |
17 | |
18 # create folder [page_name] if not yet created | |
19 if not os.path.exists(page_name): | |
20 os.makedirs(page_name) | |
21 | |
22 # for page [page_name], print comments related to fragment [id] | |
23 for audioelement in root.findall("*/[@id='"+page_name+"']/audioelement"): | |
24 if audioelement is not None: # Check it exists | |
25 audio_id = str(audioelement.get('id')) | |
26 | |
27 # append to file [page_name]/[page_name]-comments-[id].csv | |
28 with open(page_name+'/'+page_name+'-comments-'+audio_id+'.csv', 'a') as csvfile: | |
29 writer = csv.writer(csvfile, delimiter=',') | |
30 commentstr = root.find("*/[@id='" | |
31 + page_name | |
32 + "']/audioelement/[@id='" | |
33 + audio_id | |
34 + "']/comment/response").text | |
35 if commentstr is None: | |
36 writer.writerow(['']) | |
37 else: | |
38 writer.writerow([commentstr.encode("utf-8")]) | |
39 #TODO Comma doesn't act as delimiter now! | |
40 # (when adding more than just a comment per line): | |
41 # writer.writerow([file + ',' + commentstr.encode("utf-8")]) | |
42 | |
43 #TODO Replace 'new line' with something else? | |
44 | |
45 #TODO 'Append' means duplicate entries if run several times... | |
46 |