source: app/src/gph/gph @ 2fe08ac

help
Last change on this file since 2fe08ac was 20b4e44, checked in by pawelk <pawelk@…>, 16 years ago

Wersja niestabilna, zawiera wstepne poprawki.

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@13 e293616e-ec6a-49c2-aa92-f4a8b91c5d16

  • Property mode set to 100755
File size: 1.3 KB
Line 
1#!/usr/bin/perl
2
3#package:       UAM Text Tools
4#component:     gph
5#version:       1.0
6#author:        Tomasz Obrebski
7
8use strict;
9use Getopt::Long;
10
11my @process;
12my $help=0;
13my $reset;
14my $interactive=1;
15
16GetOptions("process|p=s" => \@process,
17           "help|h" => \$help,
18           "reset|r=s" => \$reset,
19           "interactive|i" => \$interactive);
20
21if($help)
22{
23    print <<'END'
24Usage: gph [OPTIONS]
25
26Options:
27   -p tag               Process segments with this tag as nodes.
28   -r tag               Start new graph at this tag.
29   -f filename          Input file (NIE DZIALA).
30   -o filename          Output file (NIE DZIALA).
31   -i                   Toggle interactive mode (default=on).
32END
33;
34    exit 0;
35}
36
37
38$|=1 if $interactive;
39
40my @prev;
41
42my $n=0;
43
44while(<>)
45{
46    chomp;
47    my $do=0;
48
49    my @line = split /\s+/;
50
51    if($line[2] eq $reset)
52    {
53        $n=0;
54        @prev = ();
55    }
56
57    for my $p (@process)
58    {
59        $do=1 if $line[2] eq $p;
60    }
61
62    if($do)
63    {
64        @preds = ();
65        shift @prev while @prev+0 && $prev[0]->[1] + $prev[0]->[2] < $line[0];
66        for my $p (@prev)
67        {
68            push(@preds, $p->[0]) if $p->[1] + $p->[2] == $line[0];
69        }
70        push @prev, [$n, $line[0], $line[1]];
71       
72        $gph=' gph:'.$n.':'.join(',',@preds);
73
74        $n++;
75    }
76    else
77    {
78        for my $p (@prev)
79        {
80            if($p->[1]+$p->[2] == $line[0])
81            {
82                $p->[2] += $line[1];
83            }
84        }
85
86        $gph='';
87
88    }
89
90    print $_.$gph."\n";   
91}
Note: See TracBrowser for help on using the repository browser.