swdata/gen_neighborhood.py
2018-09-23 23:27:01 +08:00

25 lines
575 B
Python

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)