From aa48d6c15a8c6bd48a4252f1e2b16ff40adfd5ff Mon Sep 17 00:00:00 2001
From: vl241552 <vincent.lorrain@cea.fr>
Date: Mon, 20 Nov 2023 14:44:20 +0000
Subject: [PATCH] ignored inconue node types by creating a spesific branch of
 the FSM that cancels the transition

---
 include/aidge/graphRegex/matchFsm/FsmEdge.hpp | 20 ++++++++--
 src/graphRegex/GraphFsmInterpreter.cpp        |  4 +-
 src/graphRegex/matchFsm/FsmEdge.cpp           | 19 +++++++++-
 unit_tests/graphRegex/Test_GraphRegex.cpp     | 37 ++++++++++++++++++-
 4 files changed, 72 insertions(+), 8 deletions(-)

diff --git a/include/aidge/graphRegex/matchFsm/FsmEdge.hpp b/include/aidge/graphRegex/matchFsm/FsmEdge.hpp
index 3e63f9233..a6cc3e592 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 03e864875..18b768c65 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 ab307e023..d16dcf950 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 c9feded0b..19859fd16 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
-- 
GitLab