'''
Find occurance of attribute pairs
'''

attNames = ['cpuspeed', 'freecpu', 'memsize', 'freemem', 'gbfree', 'oneminload', 'txrate']
fdIn = open('QueryAttributes.txt', 'r')
fdOut = open('Occurances.txt', 'w')

results = {}
for line in fdIn:
    for i in attNames:
        if i in line:
            for j in attNames:
                if j in line:
                    if i in results:
                        if j in results[i]:
                            results[i][j] += 1
                        else: results[i][j] = 1
                    else: results[i] = {j: 1}
fdIn.close()
for i in results:
    for j in results[i]:
        fdOut.write(i + '\t' + j + '\t' + str(results[i][j]) + '\n')
fdOut.close()
