SimilarScanResult.Match<Label> mt;
String pt = null;
int dst;
// normalize & split passed name
MatchUtilsResult in = MatchUtils.getPartsNormalize(name);
// brute force 4 labels 2 get max match propability ;-)
LabelHibernateImpl l;
for (Label ll : labels) {
l = (LabelHibernateImpl) ll;
// get distance of the normed names 2 each other
dst = StringUtils.getLevenshteinDistance(in.getNormalized(), l.getNormalizedName());
if (dst == 0) {
LOGGER.info("Found exact match for label " + name);
mt = new SimilarScanResult.Match<Label>(SimilarScanResult.MatchType.EXACT, ll.getName(), ll);
if (ssr == null) { ssr = new SimilarScanResult<Label>(mt); } else { ssr.add(mt); }
return ssr; // => we got an exact match => cancel search
} else if (dst <= LDISTANCE_LABEL) {
LOGGER.info("Found similar match:" + name);
mt = new SimilarScanResult.Match<Label>(dst, ll.getName(), ll);
if (ssr == null) { ssr = new SimilarScanResult<Label>(mt); } else { ssr.add(mt); }
} else { // no relevant distance => check part match
if (in.getParts() != null) { // we got multiple parts in the passed string => try part find
pt = l.matchParts(in.getParts()); // match the current label against the words of this label name
if (pt != null) { // part match found
LOGGER.info("Found part match '" + pt + "' for label " + l.getName());
mt = new SimilarScanResult.Match<Label>(SimilarScanResult.MatchType.PART, pt, ll);
if (ssr == null) { ssr = new SimilarScanResult<Label>(mt); } else { ssr.add(mt); }
}