Skip to content
Snippets Groups Projects
Commit f0a737a7 authored by vincent  lorrain's avatar vincent lorrain
Browse files

make graphRegex simpler

parent e522b130
No related branches found
No related tags found
No related merge requests found
......@@ -117,6 +117,8 @@ std::set<std::shared_ptr<MatchSolution>> GraphRegex::match(std::shared_ptr<Graph
std::vector<std::shared_ptr<MatchSolution>> solution = fsm->test(combination);
solutions.insert(solutions.end(), solution.begin(), solution.end());
}
}
return _findLargestCompatibleSet(solutions);
}
......@@ -142,7 +144,12 @@ void GraphRegex::setNodeKey(const std::string key,std::function<bool(NodePtr)> f
throw std::runtime_error(key + " is define");
}
mAllLambda[key] = f;
_majConditionalInterpreterLambda();
//we add the lambda as key by default
std::ostringstream oss;
oss << key << "($)==true";
setNodeKey(key, oss.str());
}
void GraphRegex::_majConditionalInterpreterLambda(){
......
......@@ -120,7 +120,7 @@ std::shared_ptr<ParsingToken<ConditionalTokenTypes>> ConditionalLexer::getNextTo
}
if (std::regex_match(currentChars,std::regex("(true|false)"))){
if (std::regex_match(currentChars,std::regex("(true|false|True|False)"))){
return std::make_shared<ParsingToken<ConditionalTokenTypes>>(ConditionalTokenTypes::BOOL,currentChars);
} else if (isLambda){
......
......@@ -18,6 +18,32 @@ using namespace Aidge;
TEST_CASE("GraphRegexUser") {
SECTION("Match using custom lambda") {
std::shared_ptr<GraphView> g1 = std::make_shared<GraphView>("TestGraph");
std::shared_ptr<Node> conv = GenericOperator("Conv", 1, 0, 1, "c");
std::shared_ptr<Node> fc = GenericOperator("FC", 1, 0, 1, "c1");
std::shared_ptr<Node> conv2 = GenericOperator("Conv", 1, 0, 1, "c2");
std::shared_ptr<Node> fc2 = GenericOperator("FC", 1, 0, 1, "c3");
g1->add(conv);
g1->addChild(fc, "c");
g1->addChild(conv2, "c1");
g1->addChild(fc2, "c2");
///
std::shared_ptr<GraphRegex> sut = std::make_shared<GraphRegex>();
sut->setNodeKey("C",+[](NodePtr NodeOp){return NodeOp->type() == "FC";});
sut->setNodeKey("A","C($)==True");
sut->addQuery("A");
auto match = sut->match(g1);
REQUIRE(match.size() == 2);
}
SECTION("INIT") {
const std::string query = "Conv->FC";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment