All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tbrugz.sqldiff.util.SimilarityCalculator Maven / Gradle / Ivy

There is a newer version: 0.9.17
Show newest version
package tbrugz.sqldiff.util;

import tbrugz.sqldump.dbmodel.Column;
import tbrugz.sqldump.dbmodel.Table;

public class SimilarityCalculator {
	
	private SimilarityCalculator() {}
	
	static SimilarityCalculator instance = new SimilarityCalculator();
	
	public static SimilarityCalculator instance() {
		return instance;
	}

	public double similarity(Table t1, Table t2) {
		final double NAME_WEIGTH = 0.1; 
		final double SCHEMANAME_WEIGTH = 0.05;
		final double COLUMNS_WEIGTH = 0.7;
		
		final double ALL_WEIGTH = NAME_WEIGTH+SCHEMANAME_WEIGTH+COLUMNS_WEIGTH;
		
		double ret = 0;
		
		//name similarity
		if(t1.getSchemaName()==null && t2.getSchemaName()==null) {
			ret += SCHEMANAME_WEIGTH;
		}
		else if(t1.getSchemaName()!=null && t1.getSchemaName().equals(t2.getSchemaName())) {
			ret += SCHEMANAME_WEIGTH;
		}
		if(t1.getName().equals(t2.getName())) {
			ret += NAME_WEIGTH;
		}
		//columns similarity
		int t1cols = t1.getColumns().size();
		int t2cols = t2.getColumns().size();
		int sumSize = t1cols+t2cols;
		for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy