Problems traversing graph with gv_perl

I ran into couple problems trying to manipulate a graph using Perl bindings supplied with GraphViz.

1. gv::ok() always returns 1 unless the node, edge etc. handle passed to it isn't defined.

2. I want to get a list of nodes reachable from the given one (the source). When gv::nexthead() is called with handles to the source node and the one returned by gv::firstnode, it returns handle to the second out-node as expected, but then if called using handles to the source and the second node it returns a new handle to the first out-node. Then to the second and to the first again, endlessly.

My Perl code is here:
sub head_nodes {
my @node;
my $i = 1;
$node[0] = $_[0];
$node[1] = gv::firsthead($node[0]);
while (gv::ok($node[0])) {
$i++;
$node[$i] = gv::nexthead($node[0], $node[$i - 1]);
}
return @node;
}

A dot file can be as simple as this (see attachement):
digraph LEXC {
Root -> Adjective;
Root -> Noun;
Root -> Numeral;
Root -> ProperNoun;
Root -> Pronoun;
Root -> Verb;
Noun -> Tag_N;
Adjective -> Tag_A;
Tag_N -> N_StemBoundary;
Tag_A -> A_StemBoundary;
N_StemBoundary -> Derivation;
N_StemBoundary -> N_Slot1;
N_Slot1 -> N_Slot2;
}

Using e.g. Root as the source node I expect to get Root, Adjective, Noun, Numeral, ProperNoun, Pronoun and Verb.

The very staightforward test
$node[0] = gv::findnode($g, "Root");
print 0, "\t", gv::nameof($node[0]), "\n";
$node[1] = gv::firsthead($node[0]);
print 1, "\t", gv::nameof($node[1]), "\n";
$node[2] = gv::nexthead($node[0], $node[1]);
print 2, "\t", gv::nameof($node[2]), "\n";
$node[3] = gv::nexthead($node[0], $node[2]);
print 3, "\t", gv::nameof($node[3]), "\n";
$node[4] = gv::nexthead($node[0], $node[3]);
print 4, "\t", gv::nameof($node[4]), "\n";
$node[5] = gv::nexthead($node[0], $node[4]);
print 5, "\t", gv::nameof($node[5]), "\n";
$node[6] = gv::nexthead($node[0], $node[5]);
print 6, "\t", gv::nameof($node[6]), "\n";

results in the following output:
0 Root
1 Adjective
2 Noun
3 Adjective
4 Noun
5 Adjective
6 Noun

Am I reading the docs the wrong way or there is actually a flaw in gv_perl?

AttachmentSize
dot.png64 KB

There was a flaw in the

There was a flaw in the nexthead and nexttail functions. This has now been fixed. If you build from source, in tclpkg/gv/gv.cpp, change e = agnxtout(g, e); in nexthead to e = agnxtout(g, AGMKOUT(e)); and change e = agnxtin(g, e); in nexttail to e = agnxtin(g, AGMKIN(e));

 

 

Thank you for the fix.

Thank you for the fix.

Recent comments