From f447dde1c11dc2d402e2253ba3266f7039926062 Mon Sep 17 00:00:00 2001 From: Alexey Shlyonskikh Date: Mon, 4 Dec 2023 13:18:23 +0300 Subject: [PATCH] Add GetDescription --- src/core/algorithms/algorithm.cpp | 9 +++++++++ src/core/algorithms/algorithm.h | 1 + src/core/config/ioption.h | 1 + src/python_bindings/bindings.cpp | 2 ++ src/python_bindings/py_algorithm.cpp | 4 ++++ src/python_bindings/py_algorithm.h | 1 + 6 files changed, 18 insertions(+) diff --git a/src/core/algorithms/algorithm.cpp b/src/core/algorithms/algorithm.cpp index e608b46d2b..f7978376d6 100644 --- a/src/core/algorithms/algorithm.cpp +++ b/src/core/algorithms/algorithm.cpp @@ -137,5 +137,14 @@ std::unordered_set Algorithm::GetPossibleOptions() const { return possible_options; } +std::string_view Algorithm::GetDescription(std::string_view option_name) const { + auto it = possible_options_.find(option_name); + if (it == possible_options_.end()) { + return ""; + } else { + return it->second->GetDescription(); + } +} + } // namespace algos diff --git a/src/core/algorithms/algorithm.h b/src/core/algorithms/algorithm.h index 6976771be6..7a7d18dd16 100644 --- a/src/core/algorithms/algorithm.h +++ b/src/core/algorithms/algorithm.h @@ -104,6 +104,7 @@ class Algorithm { std::type_index GetTypeIndex(std::string_view option_name) const; [[nodiscard]] std::unordered_set GetPossibleOptions() const; + [[nodiscard]] std::string_view GetDescription(std::string_view option_name) const; }; } // namespace algos diff --git a/src/core/config/ioption.h b/src/core/config/ioption.h index a914fac7ae..42412df629 100644 --- a/src/core/config/ioption.h +++ b/src/core/config/ioption.h @@ -14,6 +14,7 @@ class IOption { virtual void Unset() = 0; [[nodiscard]] virtual bool IsSet() const = 0; [[nodiscard]] virtual std::string_view GetName() const = 0; + [[nodiscard]] virtual std::string_view GetDescription() const = 0; [[nodiscard]] virtual std::type_index GetTypeIndex() const = 0; virtual ~IOption() = default; }; diff --git a/src/python_bindings/bindings.cpp b/src/python_bindings/bindings.cpp index 141d935447..91d4d47d1e 100644 --- a/src/python_bindings/bindings.cpp +++ b/src/python_bindings/bindings.cpp @@ -145,6 +145,8 @@ PYBIND11_MODULE(desbordante, module) { "Get names of options the algorithm may request") .def("set_option", &PyAlgorithmBase::SetOption, "option_name"_a, "option_value"_a = pybind11::none(), "Set option value") + .def("get_description", &PyAlgorithmBase::GetDescription, "option_name"_a, + "Get description of an option") .def("get_option_type", &PyAlgorithmBase::GetOptionType, "option_name"_a, "Get info about the option's type") .def("execute", &PyAlgorithmBase::Execute, "Process data"); diff --git a/src/python_bindings/py_algorithm.cpp b/src/python_bindings/py_algorithm.cpp index 5be0c9b0df..c1137af20a 100644 --- a/src/python_bindings/py_algorithm.cpp +++ b/src/python_bindings/py_algorithm.cpp @@ -68,6 +68,10 @@ py::tuple PyAlgorithmBase::GetOptionType(std::string_view option_name) const { return GetPyType(type_index); } +std::string_view PyAlgorithmBase::GetDescription(std::string_view option_name) const { + return algorithm_->GetDescription(option_name); +} + void PyAlgorithmBase::LoadProvidedData(pybind11::kwargs const& kwargs, InputTable table) { algorithm_->UnsetOption(kTable); Configure(kwargs, std::move(table)); diff --git a/src/python_bindings/py_algorithm.h b/src/python_bindings/py_algorithm.h index 11e7d0652b..4e0a93e3a6 100644 --- a/src/python_bindings/py_algorithm.h +++ b/src/python_bindings/py_algorithm.h @@ -30,6 +30,7 @@ class PyAlgorithmBase { [[nodiscard]] std::unordered_set GetPossibleOptions() const; + [[nodiscard]] std::string_view GetDescription(std::string_view option_name) const; [[nodiscard]] pybind11::tuple GetOptionType(std::string_view option_name) const; // For pandas dataframes