| 1 |
#!/usr/bin/perl -s |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
our ($shape,$h,$r,$of,$t); |
| 7 |
my %par=(); |
| 8 |
my %nodepar=(); |
| 9 |
my %grel=(NT=>1); ## graph relations |
| 10 |
$par{rankdir}=1 if $h; |
| 11 |
$nodepar{shape}=$shape if $shape; |
| 12 |
if($r){for(split(/,/,$r)){$grel{$_}=1}} |
| 13 |
|
| 14 |
$of||="png"; |
| 15 |
|
| 16 |
use Biblio::Thesaurus; |
| 17 |
use GraphViz; |
| 18 |
|
| 19 |
my $filename = shift; |
| 20 |
my $the = thesaurusLoad($filename); |
| 21 |
|
| 22 |
my $TERMS; |
| 23 |
my $NTS; |
| 24 |
|
| 25 |
$the->downtr( { -default => sub { ## term rel @terms |
| 26 |
return if $rel eq "SN"; |
| 27 |
$TERMS->{$term}++; |
| 28 |
if (defined $grel{$rel}) { |
| 29 |
for (@terms) { |
| 30 |
my $ttt = $_ || "??"; |
| 31 |
next if (defined $t and $t ne $term or $t ne $ttt); |
| 32 |
push @$NTS, [$term, $ttt]; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
}); |
| 37 |
|
| 38 |
my $g = GraphViz->new(%par); |
| 39 |
my $i = 0; |
| 40 |
|
| 41 |
for (keys %$TERMS) { |
| 42 |
$i++; |
| 43 |
$g->add_node("ID$i", label => $_,%nodepar); |
| 44 |
$TERMS->{$_} = "ID$i"; |
| 45 |
} |
| 46 |
|
| 47 |
for my $ramo (@$NTS) { |
| 48 |
$g->add_edge($TERMS->{$ramo->[0]}, |
| 49 |
$TERMS->{$ramo->[1]}); |
| 50 |
} |
| 51 |
|
| 52 |
print $g->as_png if $of eq "png"; |
| 53 |
print $g->as_svg if $of eq "svg"; |
| 54 |
print $g->as_text if $of eq "text"; |
| 55 |
print $g->as_ps if $of eq "ps"; |
| 56 |
print $g->as_imap if $of eq "imap"; |
| 57 |
|
| 58 |
|
| 59 |
__END__ |
| 60 |
|
| 61 |
=head1 NAME |
| 62 |
|
| 63 |
thesaurus2graphviz - draw a biblio::thesaurus graph |
| 64 |
|
| 65 |
=head1 SYNOPSIS |
| 66 |
|
| 67 |
thesaurus2graphviz [-shape=... -h] file.the > _.png |
| 68 |
|
| 69 |
=head1 DESCRIPTION |
| 70 |
|
| 71 |
=head2 Option |
| 72 |
|
| 73 |
-h Horizontal mode (-rankdir=1 from graphviz) |
| 74 |
|
| 75 |
-shape=circle ('record', 'plaintext', 'ellipse', 'circle', 'egg', |
| 76 |
'triangle', 'box', 'diamond', 'trapezium', 'parallelogram', 'house', |
| 77 |
'hexagon', 'octagon') |
| 78 |
|
| 79 |
-r=INST,PART graph relation = {NT, INST, PART } |
| 80 |
default graph relation = {NT} |
| 81 |
|
| 82 |
-of=svg output format (def:png) |
| 83 |
|
| 84 |
-t=term show only "term" and his neighbours |
| 85 |
|
| 86 |
=head1 AUTHOR |
| 87 |
|
| 88 |
Albero Simoes |
| 89 |
|
| 90 |
J.Joao Almeida, [email protected] |
| 91 |
|
| 92 |
=head1 SEE ALSO |
| 93 |
|
| 94 |
perl(1). |
| 95 |
|
| 96 |
=cut |
| 97 |
|