diff --git a/include/aidge/graphRegex/matchFsm/FsmEdge.hpp b/include/aidge/graphRegex/matchFsm/FsmEdge.hpp index 3e63f92337f6394382f6d92ef9f6dd7b5098a454..a6cc3e59247d4be98caa9881182bfba1c44e0178 100644 --- a/include/aidge/graphRegex/matchFsm/FsmEdge.hpp +++ b/include/aidge/graphRegex/matchFsm/FsmEdge.hpp @@ -116,7 +116,7 @@ namespace Aidge{ }; /** - * @brief class spesialisation for not commun node (node that must be match one Unique) transition + * @brief class specialization for not commun node (node that must be match one Unique) transition */ class FsmEdgeUnique:public FsmEdge { @@ -127,7 +127,7 @@ namespace Aidge{ }; /** - * @brief class spesialisation for commun node transition + * @brief class specialization for commun node transition * @see FsmEdge */ class FsmEdgeCommon:public FsmEdge @@ -181,7 +181,7 @@ namespace Aidge{ }; /** - * @brief class spesialisation for ref empty transition + * @brief class specialization for ref empty transition * @see FsmEdge */ class FsmEdgeEmpty:public FsmEdge @@ -195,6 +195,20 @@ namespace Aidge{ }; + /** + * @brief class specialization for ref empty transition + * @see FsmEdge + */ + class FsmEdgeNone:public FsmEdge + { + + public: + FsmEdgeNone(std::shared_ptr<FsmNode> source,std::shared_ptr<FsmNode> dest); + const EdgeTestResult test(const std::shared_ptr<FsmRunTimeContext> /*stmContext*/) override; + + }; + + //////////////////////// // FACTORY diff --git a/src/graphRegex/GraphFsmInterpreter.cpp b/src/graphRegex/GraphFsmInterpreter.cpp index 03e86487513065af47d91fc5265335bba456e64e..18b768c6567e64caf6841ed4a339f13fd16f69d6 100644 --- a/src/graphRegex/GraphFsmInterpreter.cpp +++ b/src/graphRegex/GraphFsmInterpreter.cpp @@ -128,7 +128,7 @@ std::shared_ptr<FsmGraph> GraphFsmInterpreter::qomF(std::shared_ptr<FsmGraph> fs for(auto valid : allValid){ if(haveCommon){ /* - the // quantif case + the // quantify case get the go back and make a lexeme id(number) we need to go back to the ref delta min #TODO */ @@ -145,7 +145,7 @@ std::shared_ptr<FsmGraph> GraphFsmInterpreter::qomF(std::shared_ptr<FsmGraph> fs edge = FsmEdgeFactory::make(valid,start,FsmEdgeTypes::REF,mNodesCondition, lexem.str()); }else{ /* - the sequensial quantif case + the sequencial quantify case no reference to common */ edge = FsmEdgeFactory::make(valid,start,FsmEdgeTypes::EMPTY,mNodesCondition,""); diff --git a/src/graphRegex/matchFsm/FsmEdge.cpp b/src/graphRegex/matchFsm/FsmEdge.cpp index ab307e023209ab770fc63f0550811279bd42eb46..d16dcf9505f5c3324fa621df2895065b7b019e19 100644 --- a/src/graphRegex/matchFsm/FsmEdge.cpp +++ b/src/graphRegex/matchFsm/FsmEdge.cpp @@ -226,6 +226,14 @@ const EdgeTestResult FsmEdgeEmpty::test(const std::shared_ptr<FsmRunTimeContext> } return {true,std::set<NodePtr>({opNode})};//none } +////////////// + +FsmEdgeNone::FsmEdgeNone(std::shared_ptr<FsmNode> source,std::shared_ptr<FsmNode> dest) +:FsmEdge(source,dest,nullptr) +{} + const EdgeTestResult FsmEdgeNone::test(const std::shared_ptr<FsmRunTimeContext> /*stmContext*/){ + return {false,std::set<NodePtr>()}; + } /// factory std::shared_ptr<FsmEdge> FsmEdgeFactory::make( @@ -260,7 +268,10 @@ const std::string lexeme) std::string commonKey = edgeType + std::to_string(commonIdx); if(allTest.find(edgeType) == allTest.end()){ - throw std::invalid_argument("Bad Node Test " + edgeType ); + //if the key is not linked to a condition + //by default, it is initialized by a edge that is always false + return std::make_shared<FsmEdgeNone>(source, dest); + //throw std::invalid_argument("Bad Node Test " + edgeType ); } return std::make_shared<FsmEdgeCommon> (source, dest, allTest.at(edgeType), commonKey); @@ -274,7 +285,11 @@ const std::string lexeme) std::string edgeType = m[1]; if(allTest.find(edgeType) == allTest.end()){ - throw std::invalid_argument("Bad Node Test " + edgeType ); + + //if the key is not linked to a condition + //by default, it is initialized by a edge that is always false + return std::make_shared<FsmEdgeNone>(source, dest); + //throw std::invalid_argument("Bad Node Test " + edgeType ); } return std::make_shared<FsmEdgeUnique>(source, dest, allTest.at(edgeType)); diff --git a/unit_tests/graphRegex/Test_GraphRegex.cpp b/unit_tests/graphRegex/Test_GraphRegex.cpp index c9feded0b39410815a49cccb2d5746491c2f8cb1..19859fd16345ff7f8d85b24e43d23c02f9ec22ee 100644 --- a/unit_tests/graphRegex/Test_GraphRegex.cpp +++ b/unit_tests/graphRegex/Test_GraphRegex.cpp @@ -55,7 +55,7 @@ TEST_CASE("GraphRegexUser") { } - SECTION("CC") { + SECTION("2 query") { std::shared_ptr<GraphRegex> sut = std::make_shared<GraphRegex>(); std::shared_ptr<GraphView> g1 = std::make_shared<GraphView>("TestGraph"); @@ -88,6 +88,41 @@ TEST_CASE("GraphRegexUser") { } + SECTION("Not define node Test") { + + //test if the FC is not define only match query not query2 + std::shared_ptr<GraphRegex> sut = std::make_shared<GraphRegex>(); + + std::shared_ptr<GraphView> g1 = std::make_shared<GraphView>("TestGraph"); + std::shared_ptr<Node> conv = GenericOperator("Conv", 1, 1, 1, "c"); + std::shared_ptr<Node> conv1 = GenericOperator("Conv", 1, 1, 1, "c1"); + std::shared_ptr<Node> conv2 = GenericOperator("Conv", 1, 1, 1, "c2"); + std::shared_ptr<Node> conv3 = GenericOperator("FC", 1, 1, 1, "c3"); + + g1->add(conv); + g1->addChild(conv1, "c"); + g1->addChild(conv2, "c1"); + g1->addChild(conv3, "c2"); + + + //sut->setKeyFromGraph(g1); + + const std::string query = "Conv->Conv"; + const std::string query2 = "Conv->FC"; + + sut->setNodeKey("Conv","getType($) =='Conv'"); + + sut->addQuery(query); + sut->addQuery(query2); + + + for (const auto& solution : sut->match(g1)) { + REQUIRE(solution->getQuery() == query); + } + + } + + SECTION("Applied Recipes"){ // generate the original GraphView