import json
from island.matches import Matches


matches = Matches.from_profile_expr(lambda r:True)

neighbors = {}

for i in range(len(matches.data)):
    m = matches.data[i]
    n = {}
    for r in m.query('neighbor', 'create').raw_data:
        if r['a'] in n:
            n[r['a']].append(r['b'])
        else:
            n[r['a']] = [r['b']]

        if r['b'] in n:
            n[r['b']].append(r['a'])
        else:
            n[r['b']] = [r['a']]    
    neighbors[matches.names[i]] = n

with open('outputs/neighborhood.json', 'w') as f:
    json.dump(neighbors, f)