Hi Kohsuke,
This is a great idea, perhaps you could blog about it?
I think it applies to lots of different cases and needs wider
awareness. You didn't mention what package it was in. Could it return
a String[ ] of possible candidates ranked by nearness to the subject
String? Then you could offer the user a choice, e.g.
"Your command "foo" was not recognized. Perhaps you meant 'go-foo',
'foo-bar', or 'foo-lish'?"
Sweet.
Craig
On Aug 11, 2006, at 10:45 AM, Kohsuke Kawaguchi wrote:
> Cheng Fang wrote:
>> We can have some simple pattern match to map wrong subcommands to
>> a list of valid commands. Any interest?
>
> A better approach is to compute the string edit distance to the
> nearest available command. This works pretty well for simple typos,
> and I've been using it successfully in the JAXB RI to diagnose
> user's typos:
>
> public static String findNearest( String key, String[] group ) {
> ...
> }
>
> It finds the string in "group" that's closest to the given key.
>
> The code is under CDDL, and if Glassfish developers would like to
> copy it, I'd be very happy.
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
Craig Russell
Architect, Sun Java Enterprise System
http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell_at_sun.com
P.S. A good JDO? O, Gasp!
- application/pkcs7-signature attachment: smime.p7s