~jtv/corpusfiltergraph/cross-python

« back to all changes in this revision

Viewing changes to trunk/lib/corpusfg/graphs/sa-champollion/bin/len_match.pl

  • 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
 
 
3
#while(<>){
 
4
#    chomp;
 
5
#    if (/^(\d+) (\d+)$/) {
 
6
#       print match_sentences_len($1,$2,0.522,1.77),"\n";
 
7
#    }
 
8
#}
 
9
$| = 1; # disable Perl output buffering
 
10
 
 
11
 
 
12
sub pnorm {
 
13
    my ($z) = @_;
 
14
 
 
15
    my $t = 1/(1+0.2316419*$z);
 
16
    my $pd = 1-0.3989423*exp(-$z*$z/2)*
 
17
        ((((1.330274429*$t-1.821255978)*$t
 
18
           +1.781477937)*$t-0.356563782)*$t+0.319381530)*$t;
 
19
 
 
20
    return $pd;
 
21
}
 
22
 
 
23
sub match_sentences_len {
 
24
    my ($len1,$len2, $y_chars_per_x_char, $var_per_x_char) = @_;
 
25
 
 
26
    if ($len1==0 && $len2==0) {
 
27
        return 0;
 
28
    }
 
29
 
 
30
    $mean = ($len1+$len2/$y_chars_per_x_char)/2;
 
31
    $z = ($y_chars_per_x_char*$len1-$len2)/sqrt($var_per_x_char*$mean);
 
32
 
 
33
    if ($z<0) {$z = -$z}
 
34
 
 
35
    $pd = 2*(1-pnorm($z));
 
36
    return $pd;
 
37
    #return 0.5+1-pnorm($z);
 
38
}
 
39
 
 
40
1;