labels = list(labels) labels.sort() dimension = len(labels) distance_matrix = np.zeros( (dimension, dimension), 'f') for pair in pairs: i = labels.index(pair[0]) j = labels.index(pair[1]) distance_matrix[i][j] = -1*float(pair[2]) ## negating for affinity return distance_matrix, labels fname = sys.argv[1] pairs = [] categories, topLevelCategories = dynamic.loadCategories("categories-500.txt") ## Load categories from cat file resfile = csv.reader(open(fname, 'r'), delimiter=" ") for row in resfile: pairs.append(row) distance_matrix, orig_labels = matrix_from_pairs(pairs) hlabels = orig_labels[:] hlabels.insert(0,0) writer = csv.writer(open("matrix.csv",'w'),delimiter = ',') writer.writerow(hlabels) temp = [] counter = 0 for row in distance_matrix: if counter <= max: temp = list(row) temp.insert(0,orig_labels[counter])
# return threshDict ################################################################ ## MAIN STARTS HERE ## ######################### fname = sys.argv[1] ## the file name output = "output/" ## the output folder #thres = sys.argv[2] threshDict = {} infile = open(output+fname, 'r') ## open input file in read mode rows = infile.readlines() ## read lines from file infile.close() #print "Threshold is: ",thres #threshold = float(thres) categories, topLevelCategories = dynamic.loadCategories("categories-500.txt") loadModel("mymodel.txt",categories) ## load the threshold file and build a dictionary #print "Threshdict:",threshDict bios = [] links = [] sig = [] for r in rows: row = r.split() # print row # print "Row[2]=",row[2] part1, part2, value = r.split() # Split the three parts of the line part1Class, part1Details = part1.split("-") # split the first and second headers at the "-" to extract class part2Class, part2Details = part2.split("-") category1 = dynamic.categorisePayload(part1Class, categories) # Classify the header -> return 14 for 14.1, 14.1.1, 14.1.2 category2 = dynamic.categorisePayload(part2Class, categories)