From 4f8e694b8066c2ec867957ca8fcef3955cedde4e Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Fri, 12 Jan 2024 13:07:37 +0000 Subject: [PATCH] [Add] python binding for new graph matching system --- .../graphRegex/pybind_GraphRegex.cpp | 9 +++-- .../graphRegex/pybind_MatchSolution.cpp | 40 +++++++++++++++++++ python_binding/pybind_core.cpp | 3 ++ 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 python_binding/graphRegex/pybind_MatchSolution.cpp diff --git a/python_binding/graphRegex/pybind_GraphRegex.cpp b/python_binding/graphRegex/pybind_GraphRegex.cpp index be3cd9e91..921f204d0 100644 --- a/python_binding/graphRegex/pybind_GraphRegex.cpp +++ b/python_binding/graphRegex/pybind_GraphRegex.cpp @@ -10,6 +10,7 @@ ********************************************************************************/ #include <pybind11/pybind11.h> +#include <pybind11/functional.h> #include "aidge/graphRegex/GraphRegex.hpp" namespace py = pybind11; @@ -20,7 +21,7 @@ void init_GraphRegex(py::module& m){ py::class_<GraphRegex, std::shared_ptr<GraphRegex>>(m, "GraphRegex", "GraphRegex class describes a regex to test a graph.") .def(py::init<>()) - .def("add_query", &GraphRegex::addQuery, R"mydelimiter( + .def("add_query", &GraphRegex::addQuery, py::arg("query"), py::arg("f") = nullptr, R"mydelimiter( :rtype: str )mydelimiter") @@ -47,10 +48,10 @@ void init_GraphRegex(py::module& m){ Add a node test :param key: the key of the node test to use in the query. :param conditionalExpressions: the test to do . - + )mydelimiter") - + .def("set_node_key", (void (GraphRegex::*)(const std::string, std::function<bool(NodePtr)>)) & GraphRegex::setNodeKey, @@ -59,7 +60,7 @@ void init_GraphRegex(py::module& m){ Add a node test :param key: the key of the lambda test to use in the conditional expressions. :param f: bool lambda (nodePtr) . - + )mydelimiter") diff --git a/python_binding/graphRegex/pybind_MatchSolution.cpp b/python_binding/graphRegex/pybind_MatchSolution.cpp new file mode 100644 index 000000000..81d39f86e --- /dev/null +++ b/python_binding/graphRegex/pybind_MatchSolution.cpp @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> +#include "aidge/graphRegex/matchFsm/MatchResult.hpp" + +namespace py = pybind11; +namespace Aidge { +void init_MatchSolution(py::module& m){ + + + py::class_<MatchSolution, std::shared_ptr<MatchSolution>>(m, "MatchSolution", "MatchSolution class contains the result of one match and the associated key, the query and the start node.") + .def("at", &MatchSolution::at, py::arg("key"), + R"mydelimiter( + :rtype: str + )mydelimiter") + + .def("get_all", &MatchSolution::getAll, + R"mydelimiter( + )mydelimiter") + + .def("get_query", &MatchSolution::getQuery, + R"mydelimiter( + )mydelimiter") + + .def("get_start_node", &MatchSolution::getStartNode, + R"mydelimiter( + )mydelimiter") + ; +} +} // namespace Aidge diff --git a/python_binding/pybind_core.cpp b/python_binding/pybind_core.cpp index 0353953fd..be0d357b7 100644 --- a/python_binding/pybind_core.cpp +++ b/python_binding/pybind_core.cpp @@ -56,6 +56,7 @@ void init_OpArgs(py::module&); void init_Connector(py::module&); void init_GraphRegex(py::module&); +void init_MatchSolution(py::module&); void init_Recipies(py::module&); @@ -106,7 +107,9 @@ void init_Aidge(py::module& m){ init_Identity(m); init_Producer(m); + init_GraphRegex(m); + init_MatchSolution(m); init_Recipies(m); init_Scheduler(m); -- GitLab