An error occurred while loading the file. Please try again.
-
Fize Jacques authored
Create server script oriented to run Geomatching
c9669cc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# coding = utf-8
import glob
from gmatch4py.bag_of_cliques import BagOfCliques
from gmatch4py.base import Base
from gmatch4py.ged.graph_edit_dist import GraphEditDistance
from gmatch4py.ged.bipartite_graph_matching_2 import BP_2
from gmatch4py.ged.greedy_edit_distance import GreedyEditDistance
from gmatch4py.ged.hausdorff_edit_distance import HED
from gmatch4py.jaccard import Jaccard
from gmatch4py.kernels.weisfeiler_lehman import *
from gmatch4py.mcs import MCS
from gmatch4py.vertex_edge_overlap import VertexEdgeOverlap
import argparse, os, sys, re, json
parser = argparse.ArgumentParser()
parser.add_argument("graphs_input_dir")
parser.add_argument("matrix_output_dir")
parser.add_argument("-d", action="store_true", help="Return distance matrix")
args = parser.parse_args()
if not os.path.exists(args.graphs_input_dir):
print("Input graph directory doesn't exist!")
sys.exit(1)
if not os.path.exists(args.matrix_output_dir):
print("Output matrix directory doesn't exist!")
print("Creating directory")
os.makedirs(args.matrix_output_dir)
print("Directory created")
graphs = []
mapping_files_to_graphs = {}
# Loading graphs
fns = glob.glob(args.graphs_input_dir.rstrip("/") + "/*.gexf")
if not fns:
print("Input dir empty! Not .gexf file found!")
i = 0
for fn in fns:
graphs.append(nx.read_gexf(fn))
mapping_files_to_graphs[i] = fn
#print(graphs)
# Compute matrices
for class_ in [BagOfCliques, GraphEditDistance, BP_2, GreedyEditDistance, HED, Jaccard, WeisfeleirLehmanKernel, MCS,
VertexEdgeOverlap]:
print("Computing the Similarity Matrix for {0}".format(class_.__name__))
if class_ in (GraphEditDistance, BP_2, GreedyEditDistance, HED):
comparator = class_(1, 1, 1, 1)
elif class_ == WeisfeleirLehmanKernel:
comparator = class_(h=2)
else:
comparator=class_()
matrix = comparator.compare(graphs, None)
if not args.d:
matrix = comparator.similarity(matrix)
else:
matrix= comparator.distance(matrix)
print("Matrix ready. Saving ...")
output_fn="{0}/{1}_{2}.npy".format(
args.matrix_output_dir.rstrip("/"),
class_.__name__,
os.path.dirname(args.graphs_input_dir).replace("/","_")
)
np.save(output_fn,matrix)
print("Matrix Saved")
json.dump(mapping_files_to_graphs,open("{0}/{1}".format(args.matrix_output_dir.rstrip("/"),"metadata.json")))
print("Done")