Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Szczepanski
aidge_core
Commits
907b1a3c
Commit
907b1a3c
authored
1 year ago
by
vincent lorrain
Browse files
Options
Downloads
Patches
Plain Diff
debug
parent
b96d2e72
Branches
feat/GraphInterpreter
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/graphRegex/GraphGraphViewInterpreter.cpp
+44
-4
44 additions, 4 deletions
src/graphRegex/GraphGraphViewInterpreter.cpp
unit_tests/graphRegex/Test_GraphGraphViewInterpreter.cpp
+69
-17
69 additions, 17 deletions
unit_tests/graphRegex/Test_GraphGraphViewInterpreter.cpp
with
113 additions
and
21 deletions
src/graphRegex/GraphGraphViewInterpreter.cpp
+
44
−
4
View file @
907b1a3c
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
unit_tests/graphRegex/Test_GraphGraphViewInterpreter.cpp
+
69
−
17
View file @
907b1a3c
...
...
@@ -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);
}
}
*/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment