Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/thread-self/root/usr/share/doc/perl-GraphViz/examples/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/usr/share/doc/perl-GraphViz/examples/text.pl
#!/usr/bin/perl -w
#
# A example which takes in text file and represents each word as a
# node and places edges where the nodes are used together.

use strict;
use lib '../lib';
use GraphViz;

my $graph = GraphViz->new(layout => 'neato', directed => 0, concentrate => 1, epsilon => 0.001, random_start => 1, no_overlap => 1m);

open(IN, shift || '../README');

my @words;
while (<IN>) {
  tr/[^A-Za-z]+/ /cs;
  push @words, split(/\s+/, lc);
}
@words = grep { ! /^\s*$/ } @words;

my %words;
my $lastword = shift @words;
foreach my $word (@words) {
  $words{$lastword}{$word}++;
  $lastword = $word;
}

foreach my $left (keys %words) {
  foreach my $right (keys %{$words{$left}}) {
    if ($words{$left}{$right} == 1) {
      $graph->add_edge($left => $right, weight => $words{$left}{$right} - 1);
    } else {
      $graph->add_edge($left => $right);
    }
  }
}

#warn $graph->_as_debug;
$graph->as_png("text.png");
#print $graph->as_text;



Hry