List of usage examples for org.apache.commons.lang StringUtils getLevenshteinDistance
public static int getLevenshteinDistance(String s, String t)
Find the Levenshtein distance between two Strings.
From source file:uk.ac.ebi.metabolomes.webservices.util.EntryDecider.java
public List<CandidateEntry> getOrderedCandidates(String query, Map<String, String> candidates) { List<CandidateEntry> orderedCand = new ArrayList<CandidateEntry>(); for (String identifier : candidates.keySet()) { CandidateEntry candidateT = new CandidateEntry(); candidateT.setId(identifier);//from ww w .j a va2 s . c o m candidateT.setDesc(candidates.get(identifier)); String prefix = this.identiferPrefix(identifier); if (prefix != null && candidateT.getDesc().contains(prefix)) { candidateT.setDesc(candidateT.getDesc().replace(prefix, "")); } candidateT.setDistance(StringUtils.getLevenshteinDistance(query.toLowerCase().trim(), candidateT.getDesc().toLowerCase().trim())); orderedCand.add(candidateT); } Collections.sort(orderedCand); return orderedCand; }
From source file:uk.ac.ebi.metabolomes.webservices.util.EntryDecider.java
/** * * @param query// www .ja va 2 s. co m * @param candidates * @return * @deprecated {@see getOrderedCandidates(String, Collection<String>)} This uses a list and thus does not colapse entries with duplicate */ @Deprecated public Set<CandidateEntry> decideBestCandidate(String query, Collection<String> candidates) { Set<CandidateEntry> orderedCand = new TreeSet<CandidateEntry>(); for (String candidate : candidates) { CandidateEntry candidateT = new CandidateEntry(); //candidateT.setId(candidate); candidateT.setDesc(candidate); String prefix = this.identiferPrefix(candidate); if (prefix != null && candidateT.getDesc().contains(prefix)) { candidateT.setDesc(candidateT.getDesc().replace(prefix, "")); } candidateT.setDistance(StringUtils.getLevenshteinDistance(query.toLowerCase().trim(), candidateT.getDesc().toLowerCase().trim())); orderedCand.add(candidateT); } return orderedCand; }
From source file:uk.ac.ebi.metabolomes.webservices.util.EntryDecider.java
public List<CandidateEntry> getOrderedCandidates(String query, Collection<String> candidates) { String formatedQuery = query.toLowerCase(Locale.ENGLISH).trim(); List<CandidateEntry> orderedCand = new ArrayList<CandidateEntry>(); for (String candidate : candidates) { String description = removePrefix(candidate); Integer distance = StringUtils.getLevenshteinDistance(formatedQuery, description.toLowerCase(Locale.ENGLISH).trim()); orderedCand.add(new CandidateEntry("", description, distance, "")); }// w ww.j a va 2 s . co m Collections.sort(orderedCand); return orderedCand; }