Package: valentine
Valentine: (Schema-) Matching DataFrames Made EasyA python package for capturing potential relationships among columns of different tabular datasets, which are given in the form of pandas DataFrames. Valentine is based onValentine: Evaluating Matching Techniques for Dataset DiscoveryYou can find more information about the research supporting Valentinehere.Experimental suite versionThe original experimental suite version of Valentine, as first published for the needs of the research paper, can be still foundhere.Installation instructionsRequirementsPython>=3.8,<3.13Java: For the Coma matcher it is required to have java (jre) installedTo install Valentine simply run:pipinstallvalentineUsageValentine can be used to find matches among columns of a given pair of pandas DataFrames.Matching methodsIn order to do so, the user can choose one of the following 5 matching methods:Coma(int: max_n, bool: use_instances, str: java_xmx)is a python wrapper aroundCOMA 3.0 Comunity editionParameters:max_n(int) - Accept similarity threshold, (default: 0).use_instances(bool) - Wheather Coma will make use of the data instances or just the schema information, (default: False).java_xmx(str) - The amount of RAM that Coma is allowed to use, (default: "1024m") .Cupid(float: w_struct, float: leaf_w_struct, float: th_accept)is the python implementation of the paperGeneric Schema Matching with CupidParameters:w_struct(float) - Structural similarity threshold, default is 0.2.leaf_w_struct(float) - Structural similarity threshold, leaf level, default is 0.2.th_accept(float) - Accept similarity threshold, default is 0.7.DistributionBased(float: threshold1, float: threshold2)is the python implementation of the paperAutomatic Discovery of Attributes in Relational DatabasesParameters:threshold1(float) - The threshold for phase 1 of the method, default is 0.15.threshold2(float) - The threshold for phase 2 of the method, default is 0.15.JaccardDistanceMatcher(float: threshold_dist)is a baseline method that uses Jaccard Similarity between columns to assess their correspondence score, optionally enhanced by a string similarity measure of choice.Parameters:threshold_dist(float) - Acceptance threshold for assessing two strings as equal, default is 0.8.distance_fun(StringDistanceFunction) - String similarity function used to assess whether two strings are equal. The enumeration class typeStringDistanceFunctioncan be imported fromvalentine.algorithms.jaccard_distance. Functions currently supported are:StringDistanceFunction.Levenshtein:Levenshtein distanceStringDistanceFunction.DamerauLevenshtein:Damerau-Levenshtein distanceStringDistanceFunction.Hamming:Hamming distanceStringDistanceFunction.Jaro:Jaro distanceStringDistanceFunction.JaroWinkler:Jaro-Winkler distance*StringDistanceFunction.Exact: String equality==SimilarityFlooding(str: coeff_policy, str: formula)is the python implementation of the paperSimilarity Flooding: A Versatile Graph Matching Algorithmand its Application to Schema MatchingParameters:coeff_policy(str) - Policy for deciding the weight coefficients of the propagation graph. Choice of "inverse_product" or "inverse_average" (default).formula(str) - Formula on which iterative fixpoint computation is based. Choice of "basic", "formula_a", "formula_b" and "formula_c" (default).Matching DataFrame PairAfter selecting one of the 5 matching methods, the user can initiate the pairwise matching process in the following way:matches=valentine_match(df1,df2,matcher,df1_name,df2_name)where df1 and df2 are the two pandas DataFrames for which we want to find matches and matcher is one of Coma, Cupid, DistributionBased, JaccardLevenMatcher or SimilarityFlooding. The user can also input a name for each DataFrame (defaults are "table_1" and "table_2"). Functionvalentine_matchreturns a MatcherResults object, which is a dictionary with additional convenience methods, such asone_to_one,take_top_percent,get_metricsand more. It stores as keys column pairs from the two DataFrames and as values the corresponding similarity scores.Matching DataFrame BatchAfter selecting one of the 5 matching methods, the user can initiate the batch matching process in the following way:matches=valentine_match_batch(df_iter_1,df_iter_2,matcher,df_iter_1_names,df_iter_2_names)where df_iter_1 and df_iter_2 are the two iterable structures containing pandas DataFrames for which we want to find matches and matcher is one of Coma, Cupid, DistributionBased, JaccardLevenMatcher or SimilarityFlooding. The user can also input an iterable with names for each DataFrame. Functionvalentine_match_batchreturns a MatcherResults object, which is a dictionary with additional convenience methods, such asone_to_one,take_top_percent,get_metricsand more. It stores as keys column pairs from the two DataFrames and as values the corresponding similarity scores.MatcherResults instanceTheMatcherResultsinstance has some convenience methods that the user can use to either obtain a subset of the data or to transform the data. This instance is a dictionary and is sorted upon instantiation, from high similarity to low similarity.top_n_matches=matches.take_top_n(5)top_n_percent_matches=matches.take_top_percent(25)one_to_one_matches=matches.one_to_one()Measuring effectivenessThe MatcherResults instance that is returned byvalentine_matchorvalentine_match_batchalso has aget_metricsmethod that the user can usemetrics=matches.get_metrics(ground_truth)in order to get all effectiveness metrics, such as Precision, Recall, F1-score and others as described in the original Valentine paper. In order to do so, the user needs to also input the ground truth of matches based on which the metrics will be calculated. The ground truth can be given as a list of tuples representing column matches that should hold (see example below).By default, all the core metrics will be used for this with default parameters, but the user can also customize which metrics to run with what parameters, and implement own custom metrics by extending from theMetricbase class. Some sets of metrics are available as well.fromvalentine.metricsimportF1Score,PrecisionTopNPercent,METRICS_PRECISION_INCREASING_Nmetrics_custom=matches.get_metrics(ground_truth,metrics={F1Score(one_to_one=False),PrecisionTopNPercent(n=70)})metrics_prefefined_set=matches.get_metrics(ground_truth,metrics=METRICS_PRECISION_INCREASING_N)ExampleThe following block of code shows: 1) how to run a matcher from Valentine on two DataFrames storing information about authors and their publications, and then 2) how to assess its effectiveness based on a given ground truth (a more extensive example is shown invalentine_example.py):importosimportpandasaspdfromvalentineimportvalentine_matchfromvalentine.algorithmsimportComa# Load data using pandasd1_path=os.path.join('data','authors1.csv')d2_path=os.path.join('data','authors2.csv')df1=pd.read_csv(d1_path)df2=pd.read_csv(d2_path)# Instantiate matcher and runmatcher=Coma(use_instances=True)matches=valentine_match(df1,df2,matcher)print(matches)# If ground truth available valentine could calculate the metricsground_truth=[('Cited by','Cited by'),('Authors','Authors'),('EID','EID')]metrics=matches.get_metrics(ground_truth)print(metrics)The output of the above code block is:{
     (('table_1', 'Cited by'), ('table_2', 'Cited by')): 0.86994505, 
     (('table_1', 'Authors'), ('table_2', 'Authors')): 0.8679843, 
     (('table_1', 'EID'), ('table_2', 'EID')): 0.8571245
}
{
     'Recall': 1.0, 
     'F1Score': 1.0, 
     'RecallAtSizeofGroundTruth': 1.0, 
     'Precision': 1.0, 
     'PrecisionTop10Percent': 1.0
}Cite ValentineOriginal Valentine paper:
@inproceedings{koutras2021valentine,
  title={Valentine: Evaluating Matching Techniques for Dataset Discovery},
  author={Koutras, Christos and Siachamis, George and Ionescu, Andra and Psarakis, Kyriakos and Brons, Jerry and Fragkoulis, Marios and Lofi, Christoph and Bonifati, Angela and Katsifodimos, Asterios},
  booktitle={2021 IEEE 37th International Conference on Data Engineering (ICDE)},
  pages={468--479},
  year={2021},
  organization={IEEE}
}
Demo Paper:
@article{koutras2021demo,
  title={Valentine in Action: Matching Tabular Data at Scale},
  author={Koutras, Christos and Psarakis, Kyriakos and Siachamis, George and Ionescu, Andra and Fragkoulis, Marios and Bonifati, Angela and Katsifodimos, Asterios},
  journal={VLDB},
  volume={14},
  number={12},
  pages={2871--2874},
  year={2021},
  publisher={VLDB Endowment}
}