view src/de/mpiwg/anteater/ml/SimilarityHelper.java @ 4:dcc35f89dce3

include linneaus findings
author jdamerow
date Thu, 25 Oct 2012 15:25:08 -0700
parents 036535fcd179
children
line wrap: on
line source

package de.mpiwg.anteater.ml;


public class SimilarityHelper {

	/**
	 * Following method is based on
	 * http://diggintojava.blogspot.com/2009/12/longest-matching-substring-in-java.html
	 * @param s1
	 * @param s2
	 * @return biggest substring contained in both strings
	 */
	public static String getBiggestSubstring(String s1, String s2) {
		String sub = s1;
		int j = s1.length();
		
		if (s1 == null || s2 == null)
			return "";

		String subString = "";
		String comparingString = s2;
		while (j >= 0) {
			for (int i = 0; i < j; i++) {
				sub = s1.substring(i, j);
				if (comparingString.contains(sub)) {
					if (sub.length() > subString.length())
						subString = sub;
				}
			}
			j--;
		}
		return subString;
	}
}