Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Did you mean" in git

I want to write a "Did you mean" algorithm.
I have a set of words (Just like git commands such as pull, push, clone).
I need to give suggestions whenever users are entering a word out of the set of words.
All above details are background of my question :)

"Do you mean" in git

I want to copy ;) the code used in the git to implement 'Did you mean' algorithm to accomplish my task.
Do you know the location of the git-source-file containing the 'Did you mean' algorithm ?

like image 757
Mohammed H Avatar asked Mar 17 '12 14:03

Mohammed H


2 Answers

The relevant code is in levenshtein.c (edit distance computation) and help.c (cutoff).

like image 69
Fred Foo Avatar answered Sep 27 '22 19:09

Fred Foo


Iarsmans already gave you a link to the implementation of the algorithm in git, but if you wish to read something about the theory you may want to read the edit distance and Levenshtein distance pages on wikipedia.

To put it simply, for an edit distance algorithm, the aim is to calculate -- given a set of basic edit operations on the data type you're working on (strings in your case) -- the minimum number of edits to make one value (string) identical to the other one.

like image 21
Riccardo T. Avatar answered Sep 27 '22 19:09

Riccardo T.