-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_matches.py
36 lines (28 loc) · 998 Bytes
/
generate_matches.py
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
import sys
from os import path
from pyspark.ml.classification import LinearSVCModel
from datasets import *
from blocking import *
from similarity import with_encodings, compute_similarities
from graphframes import GraphFrame
instance_file = sys.argv[1]
label_file = instance_file.replace("X", "Y")
dataset_name = path.splitext(path.basename(instance_file))[0]
dataset = read_dataset(instance_file)
df = dataset.df
df = blocking_keys(df, dataset.blocking_columns)
df = with_encodings(df, dataset.encoding_columns)
pairs = candidate_pairs(df)
g = GraphFrame(df, pairs)
df = compute_similarities(g, dataset.sim_columns)
df = df.select(
f.col("src.id").alias("left_instance_id"),
f.col("dst.id").alias("right_instance_id"),
"features",
)
model = LinearSVCModel.load("model-" + dataset.name)
output = model.transform(df)
output = output.filter(output.prediction == 1).select(
"left_instance_id", "right_instance_id"
)
output.write.mode("overwrite").csv(dataset_name + ".output")