-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes for undefined names #12
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
668be7f
Experimenting with string similarity
PaulKlint b5806da
First experiment to add CodeActions to typepal
PaulKlint d142d91
Added configuration options for error fixes
PaulKlint e138af4
Added parameters to @memo; use configuration parameters
PaulKlint fa9a53b
Error fixes now depend configuration settings
PaulKlint d6c21a2
Adapted to new configuration settings
PaulKlint 0a07fe6
Added a similarNames field to TypePalConfig
PaulKlint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module analysis::typepal::StringSimilarity | ||
|
||
import List; | ||
import String; | ||
import analysis::typepal::TModel; | ||
|
||
@synopsis{Tryadic minimum function on integers} | ||
int min(int a, int b, int c) | ||
= a < b ? (a < c ? a : c) : (b < c ? b : c); | ||
|
||
@synopsis{Calculate the Levenshtein distance of 2 strings} | ||
int lev(str a, str b){ | ||
int sizea = size(a); | ||
int sizeb = size(b); | ||
|
||
@memo | ||
int lev(int ia, int ib){ | ||
if(ib == sizeb) return sizea - ia; | ||
if(ia == sizea) return sizeb - ib; | ||
if(a[ia] == b[ib]) return lev(ia+1, ib+1); | ||
|
||
return 1 + min(lev(ia+1, ib), | ||
lev(ia, ib+1), | ||
lev(ia+1, ib+1)); | ||
} | ||
|
||
return lev(0, 0); | ||
} | ||
|
||
// Tests for `lev` | ||
|
||
test bool levCommutative(str a, str b) = lev(a, b) == lev(b, a); | ||
|
||
test bool levLeftAdditive(str a, str b, str c) = lev(a, b) == lev(c + a, c + b); | ||
|
||
test bool lev1() = lev("kitten", "sitting") == 3; | ||
test bool lev2() = lev("kelm", "hello") == 3; | ||
test bool lev3() = lev("hello", "hella") == 1; | ||
test bool lev4() = lev("hello", "") == 5; | ||
test bool lev5() = lev("", "hello") == 5; | ||
test bool lev6() = lev("aap", "noot") == 4; | ||
test bool lev7() = lev("page", "pope") == 2; | ||
test bool lev8() = lev("december", "january") == 8; | ||
test bool lev9() = lev("march", "may") == 3; | ||
|
||
// Similarity functions to be used by TypePal | ||
|
||
@synopsis{WordSim represents one word from the vocabulary and its similariy to the original word} | ||
alias WordSim = tuple[str word, int sim]; | ||
|
||
@synopsis{Compute list of words from vocabulary, that are similar to give word w with at most maxDistance edits} | ||
list[str] similarWords(str w, list[str] vocabulary, int maxDistance) | ||
= sort([ <v, d> | str v <- vocabulary, d := lev(w, v), d <= maxDistance ], bool (WordSim x, WordSim y){ return x.sim < y.sim;}).word; | ||
|
||
@synopsis{Find in TModel tm, names similar to w, in gives roles, with at most maxDistance edits} | ||
list[str] similarNames(str w, set[IdRole] idRoles, TModel tm, int maxDistance){ | ||
vocabulary = [ d.orgId | d <- tm.defines, d.idRole in idRoles ]; | ||
return similarWords(w, vocabulary, maxDistance); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we configure the memo to timeout after a few minutes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes will do