From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
Git Mailing List <git@vger.kernel.org>,
Alex Riesen <raa.lkml@gmail.com>
Subject: Re: [PATCH] help.autocorrect: do not run a command if the command given is junk
Date: Mon, 14 Dec 2009 13:47:28 -0800 [thread overview]
Message-ID: <7vocm1grdb.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <alpine.DEB.1.00.0912142146590.4985@pacific.mpi-cbg.de> (Johannes Schindelin's message of "Mon\, 14 Dec 2009 22\:09\:11 +0100 \(CET\)")
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> Satisfied?
Very much.
FWIW almost the same procedure led to the weights 0, 2, 1 and 4 that you
see in help.c. The weights are basically factors with which mistakes are
punished: if you just confuse two adjacent letters, such as "psuh" instead
of "push" (which can be quite common if you use two hands, one on the left
side, and one on the right side of the keyboard, with an en-US layout so
many of us use, myself included) it costs 0.
If you write a different character than what you intended, the cost is 2.
The idea behind it is that you're more likely to miss a key than to hit
the wrong key. With the laptop I am typing this email on, it is
particularly likely that I miss a key, because there are certain
key combinations where only the first key triggers an input event, but the
second only triggers an input event when it is _released_ after the first
one. So when I type "er" real fast and happen to release the "e" key
after the "r" key, no "r" appears on my screen.
Okay, so the weight for adding a character must be smaller than
substituting a character, but why is the cost for deletion so high?
Well, I really rarely type unnecessary characters (except when writing to
the Git mailing list, arguably) so those costs must be substantially
higher than for typing the wrong character.
These are actually very good justifications in the sense that people who
might want to tweak the heuristics can see the reason behind the current
choice and agree or disagree with it.
I somehow suspect that a good mathematician can come up with a rationale
for 6 after the fact that sounds convincing, along the lines of "the
average length of commands being N, and levenshtein penalties being
<0,2,1,4>, you can insert X mistaken keystroke and/or omit Y mistaken
keystroke per every correct keystroke without exceeding this value 6, and
the percentage X and/or Y represents is not too low to be practical but low
enough to reject false positives".
In any case, I'll further squash in the following. Thanks for an amusing
explanation ;-).
diff --git a/help.c b/help.c
index fbf80d9..de1e2ea 100644
--- a/help.c
+++ b/help.c
@@ -297,7 +297,7 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
old->names = NULL;
}
-/* how did we decide this is a good cutoff??? */
+/* An empirically derived magic number */
#define SIMILAR_ENOUGH(x) ((x) < 6)
const char *help_unknown_cmd(const char *cmd)
next prev parent reply other threads:[~2009-12-14 21:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-14 13:03 [PATCH] help.autocorrect: do not run a command if the command given is junk Johannes Sixt
2009-12-14 13:29 ` Alex Riesen
2009-12-14 14:17 ` Johannes Schindelin
2009-12-14 14:16 ` Johannes Schindelin
2009-12-14 20:08 ` Junio C Hamano
2009-12-14 21:09 ` Johannes Schindelin
2009-12-14 21:47 ` Junio C Hamano [this message]
2009-12-14 22:04 ` Johannes Schindelin
2009-12-14 21:55 ` Johannes Sixt
2009-12-14 23:39 ` Junio C Hamano
2009-12-15 7:57 ` Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vocm1grdb.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=j.sixt@viscovery.net \
--cc=raa.lkml@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.