import os import sys inputPredFileName = sys.argv[1] #name of the combined sda prediction file to convert into features inputFeatFileName = sys.argv[2] #name of the feature file that the sda predictions were performed on predF = open(inputPredFileName, 'r') featF = open(inputFeatFileName, 'r') outFName = inputPredFileName + '.sdaConvertedFeat' outF = None if not os.path.isfile(outFName): outF = open(outFName, 'w') else: print 'output file already exists: exit' exit(0) predLines = predF.readlines() lineCount = 0 for line in featF: items = line.split() tarVal = items[0] #get the target value (1 or -1 from the begining of the feature line) comLine = line[line.find('#'):] #get just the comment from the end of the line predItems = predLines[lineCount].split() predLine = tarVal + ' ' featNum = 1 for pred in predItems: predLine += (str(featNum) + ':' + pred + ' ') featNum += 1 predLine += comLine outF.write(predLine) lineCount += 1