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

Suggest class names if class name not found #4473

Closed
wants to merge 2 commits into from

Conversation

gf712
Copy link
Member

@gf712 gf712 commented Jan 18, 2019

I found that it can be a bit annoying finding the correct spelling of a class name using factories. This PR adds an exception that suggests alternatives when using the Python API.

Example:

In [1]: import shogun as sg

In [2]: sg.kernel("GaussianKernels", log_width=1)
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
~/shogun/build/src/interfaces/python/shogun.py in wrapper(*args, **kwargs)
    151         try:
--> 152             return func(*args, **kwargs)
    153         except SystemError as e:

~/shogun/build/src/interfaces/python/shogun.py in _internal_factory(name, **kwargs)
    174     def _internal_factory(name, **kwargs):
--> 175         new_obj = _obj(name)
    176         for k,v in kwargs.items():

SystemError: [ERROR] In file /home/gil/shogun/src/shogun/base/class_list.h line 51: Class GaussianKernels with primitive type SGOBJECT does not exist.


During handling of the above exception, another exception occurred:

SystemError                               Traceback (most recent call last)
<ipython-input-2-dd78094495dc> in <module>()
----> 1 sg.kernel("GaussianKernels", log_width=1)

~/shogun/build/src/interfaces/python/shogun.py in wrapper(*args, **kwargs)
    160             dists = [_internal_iterative_levenshtein(wrong_class_name, x) for x in all_objects]
    161             did_you_mean_class_name = all_objects[dists.index(min(dists))]
--> 162             raise SystemError("{} Did you mean {}?".format(match.group(), did_you_mean_class_name))
    163     return wrapper
    164 

SystemError: Class GaussianKernels with primitive type SGOBJECT does not exist. Did you mean GaussianKernel?

This increases the size of the SWIG source file, but in the long term could implement something like this in C++, and then have it available in all languages? Just need to implement Levenshtein in C++.

@karlnapf
Copy link
Member

I like this, but indeed it should work for all langs rather than just Python or?

@gf712
Copy link
Member Author

gf712 commented May 16, 2019

yup, someone just has to write the Levenshtein algo :D

@stale
Copy link

stale bot commented Feb 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 26, 2020
@gf712
Copy link
Member Author

gf712 commented Feb 26, 2020

closing this because it is only PoC, but should be implemented one day

@stale stale bot removed the stale label Feb 26, 2020
@gf712 gf712 closed this Feb 26, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants