forked from UniversalDependencies/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconllu-dependency-stats.pl
More file actions
34 lines (32 loc) · 944 Bytes
/
conllu-dependency-stats.pl
File metadata and controls
34 lines (32 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env perl
# Computes statistics for Alessio. Expects CoNLL-U input.
# Copyright © 2019 Dan Zeman <zeman@ufal.mff.cuni.cz>
# License: GNU GPL
use utf8;
use open ':utf8';
binmode(STDIN, ':utf8');
binmode(STDOUT, ':utf8');
binmode(STDERR, ':utf8');
while(<>)
{
if(m/^\d+\t/)
{
my @f = split(/\t/, $_);
unless($f[6]==0)
{
my $deplength = abs($f[6]-$f[0]);
$total_deplength += $deplength;
$n_nonroot_deps++;
}
$total{$f[7]}++;
$rtl{$f[7]}++ if($f[6] > $f[0]);
}
}
my $average_deplength = $total_deplength / $n_nonroot_deps;
print("Average non-root dependency length = $average_deplength\n");
foreach my $deprel (sort(keys(%total)))
{
$rtl{$deprel} = 0 if(!defined($rtl{$deprel}));
my $percent = $rtl{$deprel} / $total{$deprel} * 100;
print("$deprel\ttotal $total{$deprel}\tright-to-left $rtl{$deprel}, i.e.,\t$percent \%\n");
}