Skip to content
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

Feature Request: Fuzzy matching for teleports and subdirectories #23

Open
CatEars opened this issue Apr 23, 2019 · 6 comments
Open

Feature Request: Fuzzy matching for teleports and subdirectories #23

CatEars opened this issue Apr 23, 2019 · 6 comments

Comments

@CatEars
Copy link
Owner

CatEars commented Apr 23, 2019

Assuming I have ~/Documents and the teleport home:~ then goto hom/Diocuemants should take me there. Perhaps hide it behind some configuration?

For example

$ goto --config set AllowFuzzyMatch True
$ goto --config set AllowFuzzySubdirectoryTraversal True
$ goto --config set FuzzinessLevel 5 # Allow hamming distance/text difference of 5 characters
@CatEars
Copy link
Owner Author

CatEars commented Oct 4, 2019

I think this one can go in several directions. The inspiration originally comes from Sublime Texts excellent "Goto Anywhere" where you just haphazardly type something that is close to correct and gets you there. That is the inspiration at least, but ideas are welcome.

I believe it would be smart to start with something simple, where the actual fuzzy matching is pluggable (for example just matching prefixes of subdirectories so "aaa/bbb/ccc" would shorten to "a/b/c").

@CatEars CatEars added hacktoberfest help wanted Extra attention is needed labels Oct 4, 2019
@CatEars
Copy link
Owner Author

CatEars commented Oct 8, 2019

Perhaps start even more simple where the "normal" fuzzy matching is just straight up:

def fuzzy_matching_normal(teleport: str):
    return teleport

and make sure that fuzzy_matching_normal is used in a pluggable way with regards to --config set FuzzyMatchingAlgorithm XYZ.

@CatEars
Copy link
Owner Author

CatEars commented Oct 8, 2019

Here I am just listing a few ideas I have for different fuzzy matchers:

  • PrefixMatching
    Match the longest prefix to a teleport, remove that prefix from the input string, do a prefix match from the teleport directory where all the subdirectories are compared to the remaining teleport string
  • HammingDistance
    Use Hamming Distance as a measure of how similar the input string and the actual teleport is.
  • A combination of the two above
    The PrefixMatch algorithm is a recursive algorithm, because once you reach a similar state you use the same algorithm to solve that problem (from these input strings, which can be teleport names or subdirectories, match as much in the user input as possible). At any point you choose the PrefixMatch algorithm you can also choose the HammingDistance algorithm and so you can combine them.

@CatEars
Copy link
Owner Author

CatEars commented Oct 9, 2019

So the different PRs for this should be something like this:

  1. Implement fuzzy matching configuration. The default fuzzy matching should be turned off but there should be an available debug fuzzy matching that simply returns the same string as input.
  2. Implement an algorithm described above and add configuration options for it. I believe the easiest one to implement is the prefix matching one

@CatEars
Copy link
Owner Author

CatEars commented Oct 9, 2019

Essentially we are trying to solve the Approximate String Matching problem.

@CatEars
Copy link
Owner Author

CatEars commented Oct 9, 2019

The Jaro-Winkler algorithm looks quite suitable. It seems that a lot of these Edit Distance algorithms have a threshold of some sort and the Jaro-Winkler will normalize the value of the match between 0 and 1, so this makes the configuration more intuitive. For example goto --config set JaroWinklerSimlarityThreshold 0.5 means that the Jaro-winkler algorithm would match to at least 50%, else throw an exception.

@CatEars CatEars removed help wanted Extra attention is needed hacktoberfest labels Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant