shogun-toolbox / shogun

Shōgun
http://shogun-toolbox.org
BSD 3-Clause "New" or "Revised" License
3.03k stars 1.04k forks source link

Suggest class name if class name not found #5110

Closed LiuYuHui closed 3 years ago

LiuYuHui commented 4 years ago

fixes #4475

gf712 commented 4 years ago

Nice! Can you show a python code snippet that uses this?

LiuYuHui commented 4 years ago

for example sg.create_machine("liblinear"), such exception will be thrown.

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-2-a1dac361590b> in <module>
----> 1 sg.create_machine("liblinear")

~/shogun/build/src/interfaces/python/shogun.py in _internal_factory(name, *args, **kwargs)
    107     def _internal_factory(name, *args, **kwargs):
    108 
--> 109         new_obj = _obj(name, *args)
    110         for k,v in kwargs.items():
    111             new_obj.put(k, v)

SystemError: Class liblinear does not exist. Did you mean LibLinear ?
gf712 commented 4 years ago

for example sg.create_machine("liblinear"), such exception will be thrown.

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-2-a1dac361590b> in <module>
----> 1 sg.create_machine("liblinear")

~/shogun/build/src/interfaces/python/shogun.py in _internal_factory(name, *args, **kwargs)
    107     def _internal_factory(name, *args, **kwargs):
    108 
--> 109         new_obj = _obj(name, *args)
    110         for k,v in kwargs.items():
    111             new_obj.put(k, v)

SystemError: Class liblinear does not exist. Did you mean LibLinear ?

Nice! @karlnapf could you check if that error message is sufficient, please?

karlnapf commented 4 years ago

for example sg.create_machine("liblinear"), such exception will be thrown.

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-2-a1dac361590b> in <module>
----> 1 sg.create_machine("liblinear")

~/shogun/build/src/interfaces/python/shogun.py in _internal_factory(name, *args, **kwargs)
    107     def _internal_factory(name, *args, **kwargs):
    108 
--> 109         new_obj = _obj(name, *args)
    110         for k,v in kwargs.items():
    111             new_obj.put(k, v)

SystemError: Class liblinear does not exist. Did you mean LibLinear ?

Nice! @karlnapf could you check if that error message is sufficient, please?

Love it. I think it is decent. I guess doing something like `"Machine \"liblinear\ does not exist. Did you mean \"LibLinear\""? is hard (adding the type?).

gf712 commented 4 years ago

Love it. I think it is decent. I guess doing something like "Machine "liblinear\ does not exist. Did you mean "LibLinear""? is hard (adding the type?). Yes, that should be possible, we just need to overload a struct with astring_viewmember for the name and increate_objectuseT` to lookup the name. Unfortunately I cannot think of a way to automate that part.


template <typename T>
struct name_lookup {
static constexpr std::string_view name = "SGObject";
};

template <> struct name_lookup { static constexpr std::string_view name = "Machine"; };

// get the name name_lookup::name;

gf712 commented 3 years ago

@LiuYuHui can I merge this?

LiuYuHui commented 3 years ago

@LiuYuHui can I merge this?

yes :D

gf712 commented 3 years ago

Thanks, this is great :)