script/bratStatistics.pl untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 83 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use utf8;
5 use open qw(:utf8 :std);
6  
7 use Getopt::Long;
8 use Pod::Usage;
9  
10 use File::Basename;
11 use Brat::Handler;
12  
13 binmode(STDIN, ':utf8');
14 binmode(STDOUT, ':utf8');
15 binmode(STDERR, ':utf8');
16  
17 my $verbose;
18 my $help;
19 my $man;
20 my $inputDir;
21 my @inputDirs;
22 my $inputFile;
23 my @inputFiles;
24 my $outputFile = "-";
25 my $fileList;
26 my $bratElt;
27  
28 if (scalar(@ARGV) ==0) {
29 $help = 1;
30 }
31  
32 Getopt::Long::Configure ("bundling");
33  
34 GetOptions('help|?' => \$help,
35 'man' => \$man,
36 'verbose|v' => \$verbose,
37 'input-dir|d=s' => \@inputDirs,
38 'input-file|i=s' => \@inputFiles,
39 # 'output-file|o=s' => \$outputFile,
40 'file-list|l=s' => \$fileList,
41 );
42  
43 pod2usage(1) if $help;
44 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
45  
46 my $brat = Brat::Handler->new();
47  
48 foreach $inputFile (@inputFiles) {
49 $brat->_bratAnnotations($brat->loadFile($inputFile));
50 }
51  
52 foreach $inputDir (@inputDirs) {
53 # $brat->_inputDir($inputDir);
54 $brat->loadDir($inputDir);
55 }
56  
57 if (defined $fileList) {
58 $brat->loadList($fileList);
59 }
60  
61 # my $concatAnn = $brat->concat();
62  
63 if (!defined $outputFile) {
64 $outputFile = "-";
65 }
66  
67 # $brat->printTermList($outputFile);
68  
69 my $nbFiles = 0;
70 my $nbTerms = 0;
71 my $nbRels = 0;
72 my $sumTextSize = 0;
73 my $minTerms = 0;
74 my $maxTerms = 0;
75 my $minRels = 0;
76 my $maxRels = 0;
77  
78  
79 # $concatAnn->printTermList($outputFile, "1");
80 foreach $bratElt (@{$brat->_bratAnnotations}) {
81 print "\n";
82 $nbFiles++;
83 print "Filename ($nbFiles): " . basename(join(":", @{$bratElt->_textFilename})) . "\n";
84 $bratElt->printStats('-',0);
85 }
86  
87 print "\n";
88 print $brat->getStats . "\n";
89  
90 ########################################################################
91  
92 =head1 NAME
93  
94 bratStatistics.pl - Perl script for printing the statistics of the brat file
95  
96  
97 =head1 SYNOPSIS
98  
99 bratStatistics.pl [options]
100  
101 where option can be --help --man --verbose
102  
103 =head1 OPTIONS AND ARGUMENTS
104  
105 =over 4
106  
107 =item --input-dir <filename>, -d <filename>
108  
109 Specification of the name of the directory containing the input files.
110 Several directories can be specified.
111  
112 =item --input-file <filename>, -i <filename>
113  
114 Specification of the name of an input file (either the text or
115 annotation file). Several input files can be specified.
116  
117 =item --file-list <filename>, -l <filename>
118  
119 <Specification of the list of files for which the statistics are needed. Each line contains
120 one file name.
121  
122 =item --help
123  
124 print help message for using bratStatistics.pl
125  
126 =item --man
127  
128 print man page of bratStatistics.pl
129  
130 =item --verbose
131  
132 Go into the verbose mode
133  
134 =back
135  
136 =head1 DESCRIPTION
137  
138 This script computes the statistics of the brat annotation files
139 (<http://brat.nlplab.org/>). For each file, statistics are: the number
140 of words, the number of terms, the number of relations, the number of
141 terms and relations per type The minimal and the maximal of each
142 statistics, except the types, are also provided.
143  
144 If no output files are specified, the statistics are printed on the
145 standard output.
146  
147  
148 =head1 EXAMPLES
149  
150 Print and compute the statistics for all the files in the directory C<examples>.
151  
152 bratStatistics.pl -d examples
153  
154 Print and compute the statistics of all the three files.
155  
156 bratStatistics.pl -i examples/taln-2012-long-001-resume.txt -i examples/taln-2012-long-002-resume.ann -i examples/taln-2012-long-003-resume.txt
157  
158  
159 Print and compute all the files indicated in C<examples/list.txt>.
160  
161 bratStatistics.pl -l examples/list.txt
162  
163  
164 =head1 SEE ALSO
165  
166 http://brat.nlplab.org/
167  
168 =head1 AUTHOR
169  
170 Thierry Hamon, E<lt>hamon@limsi.frE<gt>
171  
172 =head1 COPYRIGHT AND LICENSE
173  
174 Copyright (C) 2015 Thierry Hamon
175  
176 This is free software; you can redistribute it and/or modify it under
177 the same terms as Perl itself, either Perl version 5.8.4 or, at your
178 option, any later version of Perl 5 you may have available.
179  
180 =cut
181