Created
September 19, 2013 10:44
-
-
Save andilabs/6621741 to your computer and use it in GitHub Desktop.
Reshape golds for MACE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
from sets import Set | |
import sys | |
golds = {} | |
items = Set() | |
def loadData(path): | |
with open(path,'rU') as F: | |
csvdr = csv.DictReader(F,delimiter='\t') | |
for p in csvdr: | |
items.add(int(p['item'])) | |
# | |
def loadGolds(path): | |
with open(path,'rU') as F: | |
csvdr = csv.DictReader(F,delimiter=' ') | |
for p in csvdr: | |
golds[int(p['item'])]=p['label'] | |
def writeGolds(path): | |
with open(path,'w') as F: | |
for i in sorted(items): | |
print i | |
if i in golds: | |
print "i in golds" | |
F.write(golds[i]) | |
F.write('\n') | |
else: | |
F.write('\n') | |
def main(): | |
loadData('/Users/andi/Desktop/quality_platforms/obrobka_danych/big.in') | |
print "ile itemow:",len(items) | |
print items | |
loadGolds('/Users/andi/Desktop/quality_platforms/obrobka_danych/golds.csv') | |
print "ile goldow:",len(golds.items()) | |
print golds | |
print sorted(golds.keys()) | |
writeGolds('/Users/andi/Desktop/quality_platforms/obrobka_danych/golds.out') | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment