/** * Finds the string in the <code>group</code> closest to * <code>key</code> and returns it. * * @return null if group.length==0. */ public static String findNearest( String key, Collection<String> group ) { int c = Integer.MAX_VALUE; String r = null; for (String s : group) { int ed = editDistance(key,s); if( c>ed ) { c = ed; r = s; } } return r; }
/** * Finds a type name that this context recognizes which is * "closest" to the given type name. * * <p> * This method is used for error recovery. */ public String getNearestTypeName(QName name) { String[] all = new String[typeMap.size()]; int i=0; for (QName qn : typeMap.keySet()) { if(qn.getLocalPart().equals(name.getLocalPart())) return qn.toString(); // probably a match, as people often gets confused about namespace. all[i++] = qn.toString(); } String nearest = EditDistance.findNearest(name.toString(), all); if(EditDistance.editDistance(nearest,name.toString())>10) return null; // too far apart. return nearest; }
/** * Finds the string in the <code>group</code> closest to * <code>key</code> and returns it. * * @return null if group.length==0. */ public static String findNearest( String key, Collection<String> group ) { int c = Integer.MAX_VALUE; String r = null; for (String s : group) { int ed = editDistance(key,s); if( c>ed ) { c = ed; r = s; } } return r; }
/** * Finds a type name that this context recognizes which is * "closest" to the given type name. * * <p> * This method is used for error recovery. */ public String getNearestTypeName(QName name) { String[] all = new String[typeMap.size()]; int i=0; for (QName qn : typeMap.keySet()) { if(qn.getLocalPart().equals(name.getLocalPart())) return qn.toString(); // probably a match, as people often gets confused about namespace. all[i++] = qn.toString(); } String nearest = EditDistance.findNearest(name.toString(), all); if(EditDistance.editDistance(nearest,name.toString())>10) return null; // too far apart. return nearest; }
/** * Finds the string in the <code>group</code> closest to * <code>key</code> and returns it. * * @return null if group.length==0. */ public static String findNearest( String key, Collection<String> group ) { int c = Integer.MAX_VALUE; String r = null; for (String s : group) { int ed = editDistance(key,s); if( c>ed ) { c = ed; r = s; } } return r; }
/** * Finds the string in the <code>group</code> closest to * <code>key</code> and returns it. * * @return null if group.length==0. */ public static String findNearest( String key, Collection<String> group ) { int c = Integer.MAX_VALUE; String r = null; for (String s : group) { int ed = editDistance(key,s); if( c>ed ) { c = ed; r = s; } } return r; }
/** * Finds the string in the <code>group</code> closest to * <code>key</code> and returns it. * * @return null if group.length==0. */ public static String findNearest( String key, Collection<String> group ) { int c = Integer.MAX_VALUE; String r = null; for (String s : group) { int ed = editDistance(key,s); if( c>ed ) { c = ed; r = s; } } return r; }
/** * Finds the string in the <code>group</code> closest to * <code>key</code> and returns it. * * @return null if group.length==0. */ public static String findNearest( String key, Collection<String> group ) { int c = Integer.MAX_VALUE; String r = null; for (String s : group) { int ed = editDistance(key,s); if( c>ed ) { c = ed; r = s; } } return r; }
/** * Finds a type name that this context recognizes which is * "closest" to the given type name. * * <p> * This method is used for error recovery. */ public String getNearestTypeName(QName name) { String[] all = new String[typeMap.size()]; int i=0; for (QName qn : typeMap.keySet()) { if(qn.getLocalPart().equals(name.getLocalPart())) return qn.toString(); // probably a match, as people often gets confused about namespace. all[i++] = qn.toString(); } String nearest = EditDistance.findNearest(name.toString(), all); if(EditDistance.editDistance(nearest,name.toString())>10) return null; // too far apart. return nearest; }
/** * Finds a type name that this context recognizes which is * "closest" to the given type name. * * <p> * This method is used for error recovery. */ public String getNearestTypeName(QName name) { String[] all = new String[typeMap.size()]; int i=0; for (QName qn : typeMap.keySet()) { if(qn.getLocalPart().equals(name.getLocalPart())) return qn.toString(); // probably a match, as people often gets confused about namespace. all[i++] = qn.toString(); } String nearest = EditDistance.findNearest(name.toString(), all); if(EditDistance.editDistance(nearest,name.toString())>10) return null; // too far apart. return nearest; }