source: app/src/dgp/gph @ 0214596

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

Dodalismy do pakietu utt komponent dgp (brak configow i innych bajerow).

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@24 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
11
12my @process;
13my $help=0;
14my $reset;
15my $interactive=1;
16
17GetOptions("process|p=s" => \@process,
18           "help|h" => \$help,
19           "reset|r=s" => \$reset,
20           "interactive|i" => \$interactive);
21
22if($help)
23{
24    print <<'END'
25Usage: gph [OPTIONS]
26
27Options:
28   -p tag               Process segments with this tag as nodes.
29   -r tag               Start new graph at this tag.
30   -f filename          Input file (NIE DZIALA).
31   -o filename          Output file (NIE DZIALA).
32   -i                   Toggle interactive mode (default=on).
33END
34;
35    exit 0;
36}
37
38
39$|=1 if $interactive;
40
41my @prev;
42my $gph;
43
44my $n=0;
45
46while(<>)
47{
48    chomp;
49    my $do=0;
50
51    my @line = split /\s+/;
52
53    if($line[2] eq $reset)
54    {
55        $n=0;
56        @prev = ();
57    }
58
59    for my $p (@process)
60    {
61        $do=1 if $line[2] eq $p;
62    }
63
64    if($do)
65    {
66        my @preds = ();
67        shift @prev while @prev+0 && $prev[0]->[1] + $prev[0]->[2] < $line[0];
68        for my $p (@prev)
69        {
70            push(@preds, $p->[0]) if $p->[1] + $p->[2] == $line[0];
71        }
72        push @prev, [$n, $line[0], $line[1]];
73       
74        $gph=' gph:'.$n.':'.join(',',@preds);
75
76        $n++;
77    }
78    else
79    {
80        for my $p (@prev)
81        {
82            if($p->[1]+$p->[2] == $line[0])
83            {
84                $p->[2] += $line[1];
85            }
86        }
87
88        $gph='';
89
90    }
91
92    print $_.$gph."\n";   
93}
Note: See TracBrowser for help on using the repository browser.