diff --git a/python_binding/graph/pybind_Matching.cpp b/python_binding/graph/pybind_Matching.cpp new file mode 100644 index 0000000000000000000000000000000000000000..94f2471c3f234c1e401484c099a3815dd26d3c30 --- /dev/null +++ b/python_binding/graph/pybind_Matching.cpp @@ -0,0 +1,51 @@ +/******************************************************************************** + * 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 <memory> +#include <string> +#include "aidge/graph/Matching.hpp" +#include "aidge/graph/GraphView.hpp" +#include "aidge/graph/Node.hpp" +#include "aidge/utils/Types.h" +//#include "aidge/data/Data.hpp" + +namespace py = pybind11; +namespace Aidge { +void init_SinglePassGraphMatching(py::module& m) { + py::class_<Aidge::SinglePassGraphMatching::MatchingResult>(m,"MatchingResult") + .def(py::init<>()) + .def_readwrite("graph", &Aidge::SinglePassGraphMatching::MatchingResult::graph) + .def_readwrite("anchors", &Aidge::SinglePassGraphMatching::MatchingResult::anchors) + .def_readwrite("startNode", &Aidge::SinglePassGraphMatching::MatchingResult::startNode); + + py::class_<Aidge::SinglePassGraphMatching>(m, "SinglePassGraphMatching") + .def(py::init<std::shared_ptr<GraphView>>(), py::arg("graph")) + .def("match", + [](Aidge::SinglePassGraphMatching& self, const std::string& query, bool disjoint){ + // Note: Need to convert set to vector has MatchingResult is not hashable and + // set<MatchingResult> cannot be binded + std::set<Aidge::SinglePassGraphMatching::MatchingResult> set_res = self.match(query, disjoint); + std::vector<Aidge::SinglePassGraphMatching::MatchingResult> vec_res(set_res.begin(), set_res.end()); + return vec_res; + }, + py::arg("query"), py::arg("disjoint") = false, + R"mydelimiter( Matches a query by direct, single-pass parse and match. + :param query: The query string to search. + :param disjoint: If true, only keep the longest disjoint matches. + :return: A set of MatchingResult instances. + )mydelimiter"); + + + +} +} // namespace Aidge diff --git a/python_binding/pybind_core.cpp b/python_binding/pybind_core.cpp index 53e5ec0fecb31c9bc5067ead2c5e5bd1666f34f6..2730f8e0b2ebb048c88bf8af6a80f906dcea499e 100644 --- a/python_binding/pybind_core.cpp +++ b/python_binding/pybind_core.cpp @@ -82,6 +82,7 @@ void init_Node(py::module&); void init_GraphView(py::module&); void init_OpArgs(py::module&); void init_Connector(py::module&); +void init_SinglePassGraphMatching(py::module&); void init_GraphRegex(py::module&); void init_MatchSolution(py::module&); @@ -109,6 +110,7 @@ void init_Aidge(py::module& m) { init_GraphView(m); init_OpArgs(m); init_Connector(m); + init_SinglePassGraphMatching(m); init_OperatorImpl(m); init_Log(m);