import os
path = "C:/Users/Henry/Desktop/Source Code/android_malware_analyze_training/train_file"
tran_or_test_f = open("tran_or_test_file.txt",'w')
c_name = []
vector = []
matrix = {}

if __name__ == '__main__':
    files = os.listdir(path)
    #  确定name
    for file in files:
        f = open(path + "/" + file)
        iter_f = iter(f)
        for line in iter_f:
            name = line.split(" ")[0]
            if name not in c_name:
                c_name.append(name)
    for file in files:
        f = open(path + "/" + file)
        iter_f = iter(f)
        vec = [0]*len(c_name)
        for line in iter_f:
            l = line.split(" ")
            name = l[0]
            value = int(l[2].strip('\n'))
            index = c_name.index(name)
            vec[index] = value
        vector.append(vec)
        matrix[file.strip(".txt")] = vec
        tran_or_test_f.write(file + " ")
        ii = 1
        for v in vec:
            tran_or_test_f.write("%d:" % ii)
            tran_or_test_f.write(str(v))
            if ii != len(vec):
                tran_or_test_f.write(" ")
            ii+=1
        tran_or_test_f.write("\n")
    print("success")




