Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Corentin Ribeyre
liblinguisticgraph
Commits
8b1c5c06
Commit
8b1c5c06
authored
11 years ago
by
Cocophotos
Browse files
Options
Download
Plain Diff
Merge branch 'release/1.5.5'
parents
52f4a97f
1746e9a8
master
1.5.6.2
1.5.6.1
1.5.6
1.5.5
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/linguisticgraph/graph.h
+89
-63
include/linguisticgraph/graph.h
test/test_projectivity.cpp
+16
-0
test/test_projectivity.cpp
with
105 additions
and
63 deletions
+105
-63
include/linguisticgraph/graph.h
+
89
-
63
View file @
8b1c5c06
...
...
@@ -585,7 +585,6 @@ public:
}
}
bool
isProjective
()
{
//If the graph is not planar or is not a graph, it always means that
...
...
@@ -594,9 +593,86 @@ public:
return
false
;
}
//First is projective_edges and second non_projectives_edges
std
::
pair
<
unsigned
,
unsigned
>
projectivity_count
=
testProjectivity
(
true
);
//There is at least one non projective edges
if
(
projectivity_count
.
second
>
0
)
return
false
;
else
return
true
;
}
std
::
pair
<
unsigned
,
unsigned
>
testProjectivity
()
{
return
testProjectivity
(
false
);
}
////////////////////////////////////////
//-------------------
// Helper functions
//-------------------
bool
existsNode
(
unsigned
id
)
const
{
if
(
nodesMap
.
find
(
id
)
!=
nodesMap
.
end
())
return
true
;
else
return
false
;
}
bool
existsEdge
(
unsigned
id
)
const
{
if
(
edgesMap
.
find
(
id
)
!=
edgesMap
.
end
())
return
true
;
else
return
false
;
}
////////////////////////////////////////
protected:
const
Node
&
nodeById
(
unsigned
id
)
const
{
typename
map
<
unsigned
,
Node
>::
const_iterator
node_it
=
nodesMap
.
find
(
id
);
if
(
node_it
!=
nodesMap
.
end
())
return
node_it
->
second
;
throw
out_of_range
(
"The requested node does not exist"
);
}
const
Edge
&
edgeById
(
unsigned
id
)
const
{
typename
map
<
unsigned
,
Edge
>::
const_iterator
edge_it
=
edgesMap
.
find
(
id
);
if
(
edge_it
!=
edgesMap
.
end
())
return
edge_it
->
second
;
throw
out_of_range
(
"The requested edge does not exist"
);
}
Node
&
nodeById
(
unsigned
id
)
{
typename
map
<
unsigned
,
Node
>::
iterator
node_it
=
nodesMap
.
find
(
id
);
if
(
node_it
!=
nodesMap
.
end
())
return
node_it
->
second
;
throw
out_of_range
(
"The requested node does not exist"
);
}
Edge
&
edgeById
(
unsigned
id
)
{
typename
map
<
unsigned
,
Edge
>::
iterator
edge_it
=
edgesMap
.
find
(
id
);
if
(
edge_it
!=
edgesMap
.
end
())
return
edge_it
->
second
;
throw
out_of_range
(
"The requested edge does not exist"
);
}
std
::
pair
<
unsigned
,
unsigned
>
testProjectivity
(
bool
stopWhenSure
)
{
std
::
set
<
unsigned
>
needAVisit
;
std
::
set
<
unsigned
>
visited
;
unsigned
non_projective_edges
=
0
,
projective_edges
=
0
;
const_ordered_node_iter
begin
,
end
;
for
(
boost
::
tie
(
begin
,
end
)
=
constOrderedNodes
();
begin
!=
end
;
++
begin
){
...
...
@@ -639,8 +715,8 @@ public:
//Nodes are adjacent, and will not give any hint of projectivity.
//We spare time by not doing the DFS.
if
(
needAVisit
.
size
()
==
2
)
continue
;
//
if(needAVisit.size() == 2)
//
continue;
//We are doing a DFS from the sourceId to see if the yield of
...
...
@@ -656,69 +732,19 @@ public:
//It's not the case, so we are sure that the tree is not projective
if
(
diff
.
size
()
>
0
)
return
false
;
//Otherwise we continue to check the tree.
{
non_projective_edges
+=
1
;
if
(
stopWhenSure
)
{
return
std
::
make_pair
(
projective_edges
,
non_projective_edges
);
}
}
else
projective_edges
+=
1
;
}
}
return
true
;
}
////////////////////////////////////////
//-------------------
// Helper functions
//-------------------
bool
existsNode
(
unsigned
id
)
const
{
if
(
nodesMap
.
find
(
id
)
!=
nodesMap
.
end
())
return
true
;
else
return
false
;
}
bool
existsEdge
(
unsigned
id
)
const
{
if
(
edgesMap
.
find
(
id
)
!=
edgesMap
.
end
())
return
true
;
else
return
false
;
}
////////////////////////////////////////
protected:
const
Node
&
nodeById
(
unsigned
id
)
const
{
typename
map
<
unsigned
,
Node
>::
const_iterator
node_it
=
nodesMap
.
find
(
id
);
if
(
node_it
!=
nodesMap
.
end
())
return
node_it
->
second
;
throw
out_of_range
(
"The requested node does not exist"
);
}
const
Edge
&
edgeById
(
unsigned
id
)
const
{
typename
map
<
unsigned
,
Edge
>::
const_iterator
edge_it
=
edgesMap
.
find
(
id
);
if
(
edge_it
!=
edgesMap
.
end
())
return
edge_it
->
second
;
throw
out_of_range
(
"The requested edge does not exist"
);
}
Node
&
nodeById
(
unsigned
id
)
{
typename
map
<
unsigned
,
Node
>::
iterator
node_it
=
nodesMap
.
find
(
id
);
if
(
node_it
!=
nodesMap
.
end
())
return
node_it
->
second
;
throw
out_of_range
(
"The requested node does not exist"
);
}
Edge
&
edgeById
(
unsigned
id
)
{
typename
map
<
unsigned
,
Edge
>::
iterator
edge_it
=
edgesMap
.
find
(
id
);
if
(
edge_it
!=
edgesMap
.
end
())
return
edge_it
->
second
;
throw
out_of_range
(
"The requested edge does not exist"
);
return
std
::
make_pair
(
projective_edges
,
non_projective_edges
);
}
protected:
...
...
This diff is collapsed.
Click to expand it.
test/test_projectivity.cpp
+
16
-
0
View file @
8b1c5c06
...
...
@@ -60,6 +60,10 @@ BOOST_AUTO_TEST_CASE(ProjectiveTreeTest){
BOOST_CHECK_EQUAL
(
ProjectiveTree
.
nodesSize
(),
7
);
BOOST_CHECK_EQUAL
(
ProjectiveTree
.
edgesSize
(),
6
);
BOOST_CHECK_EQUAL
(
ProjectiveTree
.
isProjective
(),
true
);
P
p
=
ProjectiveTree
.
testProjectivity
();
BOOST_CHECK_EQUAL
(
p
.
first
,
6
);
BOOST_CHECK_EQUAL
(
p
.
second
,
0
);
}
BOOST_AUTO_TEST_CASE
(
NonProjectiveTreeTest
){
...
...
@@ -78,6 +82,10 @@ BOOST_AUTO_TEST_CASE(NonProjectiveTreeTest){
BOOST_CHECK_EQUAL
(
NonProjectiveTree
.
nodesSize
(),
9
);
BOOST_CHECK_EQUAL
(
NonProjectiveTree
.
edgesSize
(),
8
);
BOOST_CHECK_EQUAL
(
NonProjectiveTree
.
isProjective
(),
false
);
P
p
=
NonProjectiveTree
.
testProjectivity
();
BOOST_CHECK_EQUAL
(
p
.
first
,
6
);
BOOST_CHECK_EQUAL
(
p
.
second
,
2
);
}
BOOST_AUTO_TEST_CASE
(
ProjectiveTreeWithRootTest
){
...
...
@@ -96,6 +104,10 @@ BOOST_AUTO_TEST_CASE(ProjectiveTreeWithRootTest){
BOOST_CHECK_EQUAL
(
ProjectiveTree
.
nodesSize
(),
8
);
BOOST_CHECK_EQUAL
(
ProjectiveTree
.
edgesSize
(),
7
);
BOOST_CHECK_EQUAL
(
ProjectiveTree
.
isProjective
(),
true
);
P
p
=
ProjectiveTree
.
testProjectivity
();
BOOST_CHECK_EQUAL
(
p
.
first
,
7
);
BOOST_CHECK_EQUAL
(
p
.
second
,
0
);
}
BOOST_AUTO_TEST_CASE
(
NonProjectiveTreeWithRootTest
){
...
...
@@ -115,6 +127,10 @@ BOOST_AUTO_TEST_CASE(NonProjectiveTreeWithRootTest){
BOOST_CHECK_EQUAL
(
NonProjectiveTree
.
nodesSize
(),
10
);
BOOST_CHECK_EQUAL
(
NonProjectiveTree
.
edgesSize
(),
9
);
BOOST_CHECK_EQUAL
(
NonProjectiveTree
.
isProjective
(),
false
);
P
p
=
NonProjectiveTree
.
testProjectivity
();
BOOST_CHECK_EQUAL
(
p
.
first
,
7
);
BOOST_CHECK_EQUAL
(
p
.
second
,
2
);
}
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help