script/brat2termlist.pl untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 63 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 Brat::Handler;
11  
12 binmode(STDIN, ':utf8');
13 binmode(STDOUT, ':utf8');
14 binmode(STDERR, ':utf8');
15  
16 my $verbose;
17 my $help;
18 my $man;
19 my $inputDir;
20 my @inputDirs;
21 my $inputFile;
22 my @inputFiles;
23 my $outputFile = "-";
24 my $fileList;
25 my $bratElt;
26  
27 if (scalar(@ARGV) ==0) {
28 $help = 1;
29 }
30  
31 Getopt::Long::Configure ("bundling");
32  
33 GetOptions('help|?' => \$help,
34 'man' => \$man,
35 'verbose|v' => \$verbose,
36 'input-dir|d=s' => \@inputDirs,
37 'input-file|i=s' => \@inputFiles,
38 'output-file|o=s' => \$outputFile,
39 'file-list|l=s' => \$fileList,
40 );
41  
42 pod2usage(1) if $help;
43 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
44  
45 my $brat = Brat::Handler->new();
46  
47 foreach $inputFile (@inputFiles) {
48 $brat->_bratAnnotations($brat->loadFile($inputFile));
49 }
50  
51 foreach $inputDir (@inputDirs) {
52 # $brat->_inputDir($inputDir);
53 $brat->loadDir($inputDir);
54 }
55  
56 if (defined $fileList) {
57 $brat->loadList($fileList);
58 }
59  
60 #my $concatAnn = $brat->concat();
61  
62  
63 if (!defined $outputFile) {
64 $outputFile = "-";
65 }
66  
67 $brat->printTermList($outputFile);
68 #$concatAnn->printTermList($outputFile, "1");
69 # foreach $bratElt (@{$brat->_bratAnnotations}) {
70 # $bratElt->printTermList($outputFile, "1");
71 # }
72  
73  
74 ########################################################################
75  
76 =head1 NAME
77  
78 brat2termlist.pl - Perl script for printing the list of terms in the brat file
79  
80  
81 =head1 SYNOPSIS
82  
83 brat2termlist.pl [options]
84  
85 where option can be --help --man --verbose
86  
87 =head1 OPTIONS AND ARGUMENTS
88  
89 =over 4
90  
91 =item --input-dir <filename>, -d <filename>
92  
93 Specification of the name of the directory containing the input files.
94 Several directories can be specified.
95  
96 =item --input-file <filename>, -i <filename>
97  
98 Specification of the name of an input file (either the text or
99 annotation file). Several input files can be specified.
100  
101 =item --output-file <filename>, -o <filename>
102  
103 Specification of the name of the output file. The filename can be C<->
104 to print the results on the standard output.
105  
106 =item --file-list <filename>, -l <filename>
107  
108 Specification of the list of files to concatenate. Each line contains
109 one file name.
110  
111 =item --help
112  
113 print help message for using brat2termlist.pl
114  
115 =item --man
116  
117 print man page of brat2termlist.pl
118  
119 =item --verbose
120  
121 Go into the verbose mode
122  
123 =back
124  
125 =head1 DESCRIPTION
126  
127 This script prints the terms of several files which have been
128 annotated with Brat (<http://brat.nlplab.org/>). The output file can
129 be specified. Otherwise, terms are printed on the standard output.
130  
131 =head1 EXAMPLES
132  
133 Print the terms of all the files in the directory C<examples> in the
134 file C<termlist1.txt>.
135  
136 brat2termlist.pl -d examples -o termlist1.txt
137  
138  
139 Print the terms of all the three file in the file C<termlist2.txt>.
140  
141 brat2termlist.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 -o termlist2.txt
142  
143  
144 Print the terms of all the files indicated in C<examples/list.txt> in
145 the file C<termlist3.txt>.
146  
147 brat2termlist.pl -l examples/list.txt -o termlist3.txt
148  
149 Print the terms of all the files indicated in C<examples/list.txt> on the standard output.
150  
151 brat2termlist.pl -l examples/list.txt
152  
153 =head1 SEE ALSO
154  
155 http://brat.nlplab.org/
156  
157 =head1 AUTHOR
158  
159 Thierry Hamon, E<lt>hamon@limsi.frE<gt>
160  
161 =head1 COPYRIGHT AND LICENSE
162  
163 Copyright (C) 2015 Thierry Hamon
164  
165 This is free software; you can redistribute it and/or modify it under
166 the same terms as Perl itself, either Perl version 5.8.4 or, at your
167 option, any later version of Perl 5 you may have available.
168  
169 =cut
170