| 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->printRelationList($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 | brat2relationlist.pl - Perl script for printing the list of relations between terms in the brat file | ||
| 79 | |||
| 80 | |||
| 81 | =head1 SYNOPSIS | ||
| 82 | |||
| 83 | brat2relationlist.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 brat2relationlist.pl | ||
| 114 | |||
| 115 | =item --man | ||
| 116 | |||
| 117 | print man page of brat2relationlist.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 relations between terms of several files which | ||
| 128 | have been annotated with Brat (<http://brat.nlplab.org/>). The output | ||
| 129 | file can be specified. Otherwise, terms are printed on the standard | ||
| 130 | output. | ||
| 131 | |||
| 132 | =head1 EXAMPLES | ||
| 133 | |||
| 134 | Print the relations of all the files in the directory C<examples> in the | ||
| 135 | file C<relationlist1.txt>. | ||
| 136 | |||
| 137 | brat2relationlist.pl -d examples -o relationslist1.txt | ||
| 138 | |||
| 139 | |||
| 140 | Print the relations of all the three file in the file C<relationlist2.txt>. | ||
| 141 | |||
| 142 | brat2relationlist.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 relationlist2.txt | ||
| 143 | |||
| 144 | |||
| 145 | Print the relations of all the files indicated in C<examples/list.txt> in | ||
| 146 | the file C<relationlist3.txt>. | ||
| 147 | |||
| 148 | brat2relationlist.pl -l examples/list.txt -o relationlist3.txt | ||
| 149 | |||
| 150 | Print the relations of all the files indicated in C<examples/list.txt> on the standard output. | ||
| 151 | |||
| 152 | brat2relationlist.pl -l examples/list.txt | ||
| 153 | |||
| 154 | =head1 SEE ALSO | ||
| 155 | |||
| 156 | http://brat.nlplab.org/ | ||
| 157 | |||
| 158 | =head1 AUTHOR | ||
| 159 | |||
| 160 | Thierry Hamon, E<lt>hamon@limsi.frE<gt> | ||
| 161 | |||
| 162 | =head1 COPYRIGHT AND LICENSE | ||
| 163 | |||
| 164 | Copyright (C) 2015 Thierry Hamon | ||
| 165 | |||
| 166 | This is free software; you can redistribute it and/or modify it under | ||
| 167 | the same terms as Perl itself, either Perl version 5.8.4 or, at your | ||
| 168 | option, any later version of Perl 5 you may have available. | ||
| 169 | |||
| 170 | =cut | ||
| 171 |