~jtv/corpusfiltergraph/cross-python

« back to all changes in this revision

Viewing changes to trunk/lib/corpusfg/graphs/sa-champollion/bin/load_axis

  • Committer: tahoar
  • Date: 2012-05-02 15:46:23 UTC
  • Revision ID: svn-v4:bc069b21-dff4-4e29-a776-06a4e04bad4e::266
new layout. need to update code to use the new layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
$| = 1; # disable Perl output buffering
 
3
 
 
4
sub load_axis {
 
5
    my ($axis_fn, $st_aref, $len_aref, $token_stat_href, $tkn2snt_href) = @_;
 
6
    my $token, %new_st, %tkn2snt;
 
7
    my $segid, $seg, $expected_segid;
 
8
    
 
9
    open A, "<$axis_fn" || die "$0: Can not open $axis_fn\n";
 
10
    
 
11
    print STDERR "Loading axis...";
 
12
    $segid = 1;
 
13
    while (<A>){
 
14
        chomp;
 
15
        
 
16
        $seg = $_;
 
17
        $seg =~ s/\s+/ /g;
 
18
 
 
19
        if ($seg =~ /^\s*$/) {
 
20
            die "segment $segid is empty!\n";
 
21
        }
 
22
 
 
23
        push @$st_aref, $seg;
 
24
        @tokens = split ' ',$seg;
 
25
 
 
26
        $snt = $seg;
 
27
        $snt =~ s/ //g;
 
28
        $$len_aref[$segid-1] = length $snt;
 
29
        
 
30
        foreach (@tokens) {
 
31
            # the following line is needed when doing an exact match
 
32
            # and the Y axis is not segmented
 
33
            #s/\W/\\$&/g;
 
34
            next if defined $xstop{$_};
 
35
            $$token_stat_href{$_}++;
 
36
            $$token_stat_href{TTAALL}++;
 
37
            $$tkn2snt_href{$_}{$segid-1} = 1;
 
38
        }
 
39
        $segid++;
 
40
    }
 
41
 
 
42
 
 
43
    close A;
 
44
    print STDERR "done.\n";
 
45
    print STDERR "Number of sentences: $segid\n";
 
46
}
 
47
 
 
48
sub load_axis_cn {
 
49
    my ($axis_fn, $st_aref, $len_aref, $token_stat_href, $tkn2snt_href) = @_;
 
50
    my $token, %new_st, %tkn2snt;
 
51
    my $stno = 0;
 
52
    
 
53
    open A, "<$axis_fn" || die "$0: Can not open $axis_fn\n";
 
54
    
 
55
    print STDERR "Loading axis...";
 
56
    while (<A>){
 
57
        chomp;
 
58
        s/\s+/ /g;
 
59
        $$len_aref[$stno] = length $_;
 
60
        s/\s//g;
 
61
        @_ = split //,$_;
 
62
        #print STDERR join '', @_, "\n";
 
63
        foreach (@_) {
 
64
            $$tkn2snt_href{$_}{$stno} = 1;
 
65
        }
 
66
        push @$st_aref, $_;
 
67
        $stno++;
 
68
    }
 
69
    close A;
 
70
    print STDERR "done.\n";
 
71
    print STDERR "Number of sentences: $stno\n";
 
72
}
 
73
 
 
74
1;