blib/script/concatBratFiles.pl untested

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