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

debug

parent b96d2e72
No related tags found
No related merge requests found
......@@ -58,9 +58,9 @@ std::shared_ptr<GraphView> GraphGraphViewInterpreter::keyF(std::shared_ptr<AstNo
std::regex pattern("([A-Za-z_0-9]+)#[0-9]*");
std::smatch match;
if(std::regex_match(lexeme, match, pattern)){
nodeOp = GenericOperator(match[1].str().c_str(), 1, 1, 1);
nodeOp = GenericOperator(match[1].str().c_str(), 5, 5, 5,lexeme.c_str());
}else{
throw std::logic_error("BAD CKEY" );
throw std::logic_error("BAD CKEY");
}
mCommonNodes[lexeme] = nodeOp;
......@@ -71,7 +71,7 @@ std::shared_ptr<GraphView> GraphGraphViewInterpreter::keyF(std::shared_ptr<AstNo
}else if (AstNode->getType() == gRegexTokenTypes::KEY)
{
nodeOp = GenericOperator(lexeme.c_str(), 1, 1, 1);
nodeOp = GenericOperator(lexeme.c_str(), 1, 1, 1,lexeme.c_str());
}else{
throw std::logic_error("keyF Bad in AST" );
......@@ -113,22 +113,43 @@ std::shared_ptr<GraphView> GraphGraphViewInterpreter::qomF(std::shared_ptr<Graph
if(loopIdx == 0){
return graph;
}else{
//duplicate the graph but not the common nodes
bool haveCommonNode = false;
std::shared_ptr<GraphView> gCopy = std::make_shared<GraphView>("GenerateGraph");
std::map<NodePtr, NodePtr> oldToNewNodes;
for (const auto& nodeToCheck :graph->getNodes()){
for (const auto& pair : mCommonNodes) {
if (pair.second == nodeToCheck) {
//use the same node because is a unique node
oldToNewNodes[nodeToCheck]=nodeToCheck;
gCopy->add(nodeToCheck);
haveCommonNode = true;
}else{
//deep copy of the node , because is a unique node
NodePtr newNode = nodeToCheck->clone();
oldToNewNodes[nodeToCheck]=newNode;
gCopy->add(newNode);
}
}
}
//reconnection
for (const auto& pair : oldToNewNodes) {
auto children = pair.first->getChildren();
for (const auto& child :children){
auto newChild = oldToNewNodes[child];
if(children.find(newChild) == children.end() && newChild != nullptr){
pair.second->addChild(newChild);
}
// if(pair.second != pair.first){ //wtf
// pair.second->addChild(oldToNewNodes[child]);
// }
}
}
//to type of quantifier if there are common node it's a // quantifier
......@@ -151,22 +172,41 @@ std::shared_ptr<GraphView> GraphGraphViewInterpreter::qzmF(std::shared_ptr<Graph
}if(loopIdx == 1){
return graph;
}else{
//duplicate the graph but not the common nodes
bool haveCommonNode = false;
std::shared_ptr<GraphView> gCopy = std::make_shared<GraphView>("GenerateGraph");
std::map<NodePtr, NodePtr> oldToNewNodes;
for (const auto& nodeToCheck :graph->getNodes()){
for (const auto& pair : mCommonNodes) {
if (pair.second == nodeToCheck) {
//use the same node because is a unique node
oldToNewNodes[nodeToCheck]=nodeToCheck;
gCopy->add(nodeToCheck);
haveCommonNode = true;
}else{
//deep copy of the node , because is a unique node
NodePtr newNode = nodeToCheck->clone();
oldToNewNodes[nodeToCheck]=newNode;
gCopy->add(newNode);
}
}
}
//reconnection
for (const auto& pair : oldToNewNodes) {
auto children = pair.first->getChildren();
for (const auto& child :children){
auto newChild = oldToNewNodes[child];
if(children.find(newChild) == children.end() && newChild != nullptr){
pair.second->addChild(newChild);
}
// if(pair.second != pair.first){ //wtf
// pair.second->addChild(oldToNewNodes[child]);
// }
}
}
//to type of quantifier if there are common node it's a // quantifier
//else is a sequential one
......
......@@ -8,26 +8,78 @@ using namespace Aidge;
TEST_CASE("GraphGraphViewInterpreter", "GraphGraphViewInterpreter") {
const std::string query = "Conv->FC";
auto test = GraphGraphViewInterpreter(query);
auto graphOp = test.interpret();
REQUIRE(graphOp->getNodes().size() == 2);
const std::string query = "(C->B#->D)+";
auto test = GraphGraphViewInterpreter(query);
auto graphOp = test.interpret();
//REQUIRE(graphOp->getNodes().size() == 3);
graphOp->save("toto");
std::shared_ptr<GraphRegex> sut = std::make_shared<GraphRegex>();
sut->setKeyFromGraph(graphOp);
sut->addQuery(query);
for (const auto& solution : sut->match(graphOp)) {
REQUIRE(solution->getAll() == graphOp->getNodes());
}
std::shared_ptr<GraphRegex> sut = std::make_shared<GraphRegex>();
sut->setKeyFromGraph(graphOp);
sut->addQuery(query);
for (const auto& solution : sut->match(graphOp)) {
REQUIRE(solution->getAll() == graphOp->getNodes());
}
}
\ No newline at end of file
/*
TEST_CASE("GraphGraphViewInterpreter2") {
std::vector<std::string> expressions = {
"(C->B#->D)+",
"A",
"A->B",
"A->B->C",
"A#",
"A#->B",
"A#->B#",
"A#->B#->C",
"A#->B#->C#",
"A->B#->C",
"A+",
"A+->B+",
"A->B+->C",
"A*",
"A*->B*",
"A->B*->C",
"A*",
"A*->B+",
"A+->B*->C",
"(A#->B->C#)+",
"(A#->B)+;A#->B->C",
"B+->B->B",
"B#->R*",
"(B#->R)*",
"A->C->B#->B;B#->R",
"B#->R",
"A->C#;A->C#;A->C#;A->C#;A->C#;A->C#",
"B#->R;B#->R",
"A# -> C -> B#; B#->A#"
};
// Iterate over the vector using a for loop
for (const std::string& query : expressions) {
auto test = GraphGraphViewInterpreter(query);
auto graphOp = test.interpret();
std::shared_ptr<GraphRegex> sut = std::make_shared<GraphRegex>();
sut->setKeyFromGraph(graphOp);
sut->addQuery(query);
bool oneSolutionIsAll = false;
for (const auto& solution : sut->match(graphOp)) {
if (solution->getAll() == graphOp->getNodes())
{
oneSolutionIsAll = true;
break;
}
}
INFO("Checking the " << query );
REQUIRE(oneSolutionIsAll);
}
}
*/
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