| 1 | package Brat::Handler::File; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use open qw(:utf8 :std); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 6 | our $VERSION='0.1'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 17 | ▶ | my ($class, $filename) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 17 | my $annotationFilename; | |||||||||||||||||||||||||||
| 15 | my $textFilename; | ||||||||||||||||||||||||||||
| 16 | 17 | my $textSize = 0; | |||||||||||||||||||||||||||
| 17 | 17 | my @annFiles; | |||||||||||||||||||||||||||
| 18 | my @textFiles; | ||||||||||||||||||||||||||||
| 19 | 17 | my @files; | |||||||||||||||||||||||||||
| 20 | 17 | my $f; | |||||||||||||||||||||||||||
| 21 | 17 | my $line; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # print STDERR "\n==> $filename - " . ref($filename) . ";\n"; | ||||||||||||||||||||||||||||
| 24 | 17 | ▶ | if (defined $filename) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 13 | ▶ | if (ref($filename) eq "") { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 26 | 13 | push @files, $filename; | |||||||||||||||||||||||||||
| 27 | } elsif (ref($filename) eq "ARRAY") { | ||||||||||||||||||||||||||||
| 28 | 0 | push @files, @$filename; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 17 | foreach $f (@files) { | |||||||||||||||||||||||||||
| 32 | # warn "$f\n"; | ||||||||||||||||||||||||||||
| 33 | 13 | $annotationFilename = $f; | |||||||||||||||||||||||||||
| 34 | 13 | $annotationFilename =~ s/\.txt$/.ann/; | |||||||||||||||||||||||||||
| 35 | 13 | $textFilename = $f; | |||||||||||||||||||||||||||
| 36 | 13 | $textFilename =~ s/\.ann$/.txt/; | |||||||||||||||||||||||||||
| 37 | 13 | $textSize = 0; | |||||||||||||||||||||||||||
| 38 | 13 | ▶ | open FILE, $textFilename or die "no such file $textFilename\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 13 | ▶ | while($line = <FILE>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 26 | $textSize += length($line); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 13 | close FILE; | |||||||||||||||||||||||||||
| 43 | # my @s = stat($textFilename); | ||||||||||||||||||||||||||||
| 44 | # $textSize += $s[7]; | ||||||||||||||||||||||||||||
| 45 | 13 | push @annFiles, $annotationFilename; | |||||||||||||||||||||||||||
| 46 | 13 | push @textFiles, $textFilename; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 17 | my $bratfile = { | |||||||||||||||||||||||||||
| 49 | 'annotationFilename' => [@annFiles], | ||||||||||||||||||||||||||||
| 50 | 'textFilename' => [@textFiles], | ||||||||||||||||||||||||||||
| 51 | 'terms' => {}, | ||||||||||||||||||||||||||||
| 52 | 'relations' => {}, | ||||||||||||||||||||||||||||
| 53 | 'attributes' => {}, | ||||||||||||||||||||||||||||
| 54 | 'maxTermId' => 0, | ||||||||||||||||||||||||||||
| 55 | 'maxRelationId' => 0, | ||||||||||||||||||||||||||||
| 56 | 'maxAttributeId' => 0, | ||||||||||||||||||||||||||||
| 57 | 'textSize' => $textSize, | ||||||||||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 17 | bless($bratfile, $class); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 17 | ▶ | if (defined $filename) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 13 | ▶ | if (ref($filename) eq "") { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 64 | 13 | $bratfile->loadBratFile; | |||||||||||||||||||||||||||
| 65 | } elsif (ref($filename) eq "ARRAY") { | ||||||||||||||||||||||||||||
| 66 | 0 | warn "load of several brat files not implemented\n"; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 17 | return($bratfile); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub _textFilename { | ||||||||||||||||||||||||||||
| 73 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_textFilename: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 6 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 3 | my $arg = shift; | |||||||||||||||||||||||||||
| 77 | 3 | push @{$self->{'textFilename'}}, $arg; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 6 | return($self->{'textFilename'}); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | sub _textSize { | ||||||||||||||||||||||||||||
| 83 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_textSize: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 7 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 1 | $self->{'textSize'} = shift; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 7 | return($self->{'textSize'}); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub _annotationFilename { | ||||||||||||||||||||||||||||
| 92 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_annotationFilename: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 93 | 19 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 16 | my $arg = shift; | |||||||||||||||||||||||||||
| 95 | 16 | ▶ | if ($arg =~ /^\d+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 13 | return($self->{'annotationFilename'}->[$arg]); | |||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||
| 98 | 3 | push @{$self->{'annotationFilename'}}, $arg; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 6 | return($self->{'annotationFilename'}); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | sub _terms { | ||||||||||||||||||||||||||||
| 105 | 3938 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_terms: called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 3938 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | my $list = shift; | |||||||||||||||||||||||||||
| 109 | 0 | my $term; | |||||||||||||||||||||||||||
| 110 | 0 | foreach $term (@$list) { | |||||||||||||||||||||||||||
| 111 | 0 | $self->_addTerm($term->{'id'}, $term); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | # $self->{'terms'} = shift; | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # max Term Id | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | 3938 | return($self->{'terms'}); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | sub _addTerm { | ||||||||||||||||||||||||||||
| 121 | 446 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_addTerm: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 446 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 446 | my $id = shift; | |||||||||||||||||||||||||||
| 125 | 446 | $self->_terms->{$id} = shift; | |||||||||||||||||||||||||||
| 126 | # max Term Id | ||||||||||||||||||||||||||||
| 127 | 446 | ▶ | if ($self->_maxTermId < $self->_terms->{$id}->{'numId'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 371 | $self->_maxTermId($self->_terms->{$id}->{'numId'}); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 446 | return($self->_getTermFromId($id)); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 0 | return(undef); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | sub _maxTermId { | ||||||||||||||||||||||||||||
| 136 | 822 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_maxTermId: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 822 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 371 | $self->{'maxTermId'} = shift; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 822 | return($self->{'maxTermId'}); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | sub _getTermFromId { | ||||||||||||||||||||||||||||
| 145 | 1330 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_getTermFromId: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 146 | 1330 | my $id = shift; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 1330 | ▶ | if ((defined $id) && (exists $self->_terms->{$id})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $id and exists $self->_terms->{$id}
MC/DC0%0/2
defined $id and exists $self->_terms->{$id}
defined $id
exists $self->_terms->{$id}
Truth table33%1/3
A and B
A= defined $idB= exists $self->_terms->{$id}
| |||||||||||||||||||||||||||||
| 149 | 1330 | return($self->_terms->{$id}); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | sub _relations { | ||||||||||||||||||||||||||||
| 154 | 729 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_relations: called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 729 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | my $list = shift; | |||||||||||||||||||||||||||
| 158 | 0 | my $relation; | |||||||||||||||||||||||||||
| 159 | 0 | foreach $relation (@$list) { | |||||||||||||||||||||||||||
| 160 | 0 | $self->_addRelation($relation->{'id'}, $relation); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | # $self->{'relations'} = shift; | ||||||||||||||||||||||||||||
| 163 | # max Relation Id | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | 729 | return($self->{'relations'}); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | sub _addRelation { | ||||||||||||||||||||||||||||
| 169 | 70 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_addRelation: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 70 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 70 | my $id = shift; | |||||||||||||||||||||||||||
| 173 | 70 | $self->_relations->{$id} = shift; | |||||||||||||||||||||||||||
| 174 | # max Relation Id | ||||||||||||||||||||||||||||
| 175 | # warn $self->_maxRelationId . " < " . $self->_relations->{$id}->{'numId'} . "\n"; | ||||||||||||||||||||||||||||
| 176 | 70 | ▶ | if ($self->_maxRelationId < $self->_relations->{$id}->{'numId'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 64 | $self->_maxRelationId($self->_relations->{$id}->{'numId'}); | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 70 | return($self->_getRelationFromId($id)); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 0 | return(undef); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | sub _maxRelationId { | ||||||||||||||||||||||||||||
| 185 | 139 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_maxRelationId: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 139 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 64 | $self->{'maxRelationId'} = shift; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 139 | return($self->{'maxRelationId'}); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | sub _getRelationFromId { | ||||||||||||||||||||||||||||
| 194 | 255 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_getRelationFromId: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 195 | 255 | my $id = shift; | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 255 | ▶ | if ((defined $id) && (exists $self->_relations->{$id})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $id and exists $self->_relations->{$id}
MC/DC0%0/2
defined $id and exists $self->_relations->{$id}
defined $id
exists $self->_relations->{$id}
Truth table33%1/3
A and B
A= defined $idB= exists $self->_relations->{$id}
| |||||||||||||||||||||||||||||
| 198 | 255 | return($self->_relations->{$id}); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | sub _attributes { | ||||||||||||||||||||||||||||
| 203 | 69 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_attributes: called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 69 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 0 | my $list = shift; | |||||||||||||||||||||||||||
| 207 | 0 | my $attribute; | |||||||||||||||||||||||||||
| 208 | 0 | foreach $attribute (@$list) { | |||||||||||||||||||||||||||
| 209 | 0 | $self->_addAttribute($attribute->{'id'}, $attribute); | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | # $self->{'attributes'} = shift; | ||||||||||||||||||||||||||||
| 212 | # max Attribute Id | ||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | 69 | return($self->{'attributes'}); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | sub _addAttribute { | ||||||||||||||||||||||||||||
| 218 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_addAttribute: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 10 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 10 | my $id = shift; | |||||||||||||||||||||||||||
| 222 | 10 | $self->_attributes->{$id} = shift; | |||||||||||||||||||||||||||
| 223 | # max Attribute Id | ||||||||||||||||||||||||||||
| 224 | 10 | ▶ | if ($self->_maxAttributeId < $self->_attributes->{$id}->{'numId'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 10 | $self->_maxAttributeId($self->_attributes->{$id}->{'numId'}); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | 10 | return($self->_getAttributeFromId($id)); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | 0 | return(undef); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | sub _maxAttributeId { | ||||||||||||||||||||||||||||
| 233 | 25 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_maxAttributeId: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 25 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 10 | $self->{'maxAttributeId'} = shift; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | 25 | return($self->{'maxAttributeId'}); | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | sub _getAttributeFromId { | ||||||||||||||||||||||||||||
| 242 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_getAttributeFromId: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 243 | 17 | my $id = shift; | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 17 | ▶ | if ((defined $id) && (exists $self->_attributes->{$id})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $id and exists $self->_attributes->{$id}
MC/DC0%0/2
defined $id and exists $self->_attributes->{$id}
defined $id
exists $self->_attributes->{$id}
Truth table33%1/3
A and B
A= defined $idB= exists $self->_attributes->{$id}
| |||||||||||||||||||||||||||||
| 246 | 17 | return($self->_attributes->{$id}); | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | sub loadBratFile { | ||||||||||||||||||||||||||||
| 251 | 13 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
loadBratFile: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 252 | 13 | my $line; | |||||||||||||||||||||||||||
| 253 | my $id; | ||||||||||||||||||||||||||||
| 254 | 13 | my $info; | |||||||||||||||||||||||||||
| 255 | 13 | my $str; | |||||||||||||||||||||||||||
| 256 | 13 | my $type; | |||||||||||||||||||||||||||
| 257 | 13 | my $termId; | |||||||||||||||||||||||||||
| 258 | 13 | my $value; | |||||||||||||||||||||||||||
| 259 | 13 | my $arg1; | |||||||||||||||||||||||||||
| 260 | 13 | my $arg2; | |||||||||||||||||||||||||||
| 261 | 13 | my $o; | |||||||||||||||||||||||||||
| 262 | 13 | my $s; | |||||||||||||||||||||||||||
| 263 | 13 | my $e; | |||||||||||||||||||||||||||
| 264 | 13 | my @starts; | |||||||||||||||||||||||||||
| 265 | 13 | my @ends; | |||||||||||||||||||||||||||
| 266 | 13 | my $numId; | |||||||||||||||||||||||||||
| 267 | # warn "===> " . $self->_filename . "\n"; | ||||||||||||||||||||||||||||
| 268 | 13 | ▶ | open FILE, "<:utf8", $self->_annotationFilename(0) or die "no such file " . $self->_annotationFilename(0) . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 13 | ▶ | while($line = <FILE>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 429 | chomp $line; | |||||||||||||||||||||||||||
| 271 | 429 | @starts = (); | |||||||||||||||||||||||||||
| 272 | 429 | @ends = (); | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 429 | ($id, $info, $str) = split /\t/, $line; | |||||||||||||||||||||||||||
| 275 | # warn "$id\n"; | ||||||||||||||||||||||||||||
| 276 | 429 | ▶ | if ($id =~ /^T(?<numid>\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 363 | $numId = $+{numid}; | |||||||||||||||||||||||||||
| 278 | # ($type, $start, $end) = split / /, $info; | ||||||||||||||||||||||||||||
| 279 | # warn "info: $info\n"; | ||||||||||||||||||||||||||||
| 280 | 363 | ▶ | if ($info =~ /^(?<type>[^ ]+) (?<offsets>.*)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | 363 | $type = $+{type}; | |||||||||||||||||||||||||||
| 282 | 363 | foreach $o (split /;/, $+{offsets}) { | |||||||||||||||||||||||||||
| 283 | 368 | ($s, $e) = split / /, $o; | |||||||||||||||||||||||||||
| 284 | # warn "\t$s : $e\n"; | ||||||||||||||||||||||||||||
| 285 | 368 | push @starts, $s; | |||||||||||||||||||||||||||
| 286 | 368 | push @ends, $e; | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | # warn "->$id\n"; | ||||||||||||||||||||||||||||
| 289 | 363 | $self->_addTerm($id, { | |||||||||||||||||||||||||||
| 290 | 'id' => $id, | ||||||||||||||||||||||||||||
| 291 | 'numId' => $numId, | ||||||||||||||||||||||||||||
| 292 | 'type' => $type, | ||||||||||||||||||||||||||||
| 293 | 'start' => [@starts], | ||||||||||||||||||||||||||||
| 294 | 'end' => [@ends], | ||||||||||||||||||||||||||||
| 295 | 'str' => $str, | ||||||||||||||||||||||||||||
| 296 | 'attrlst' => [], | ||||||||||||||||||||||||||||
| 297 | }); | ||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | 429 | ▶ | if ($id =~ /^A(?<numid>\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 8 | $numId = $+{numid}; | |||||||||||||||||||||||||||
| 302 | 8 | ($type, $termId, $value) = split / /, $info; | |||||||||||||||||||||||||||
| 303 | 8 | $self->_addAttribute($id, { | |||||||||||||||||||||||||||
| 304 | 'id' => $id, | ||||||||||||||||||||||||||||
| 305 | 'numId' => $numId, | ||||||||||||||||||||||||||||
| 306 | 'type' => $type, | ||||||||||||||||||||||||||||
| 307 | 'termId' => $termId, | ||||||||||||||||||||||||||||
| 308 | 'value' => $value, | ||||||||||||||||||||||||||||
| 309 | }); | ||||||||||||||||||||||||||||
| 310 | # warn "termId: $start\n"; | ||||||||||||||||||||||||||||
| 311 | 8 | push @{$self->_getTermFromId($termId)->{'attrlst'}}, $id; | |||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | 429 | ▶ | if ($id =~ /^R(?<numid>\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | # warn "==> $id " . $+{numid} . "\n"; | ||||||||||||||||||||||||||||
| 316 | 58 | $numId = $+{numid}; | |||||||||||||||||||||||||||
| 317 | 58 | ($type, $arg1, $arg2) = split / /, $info; | |||||||||||||||||||||||||||
| 318 | 58 | $arg1 =~ s/^Arg1://; | |||||||||||||||||||||||||||
| 319 | 58 | $arg2 =~ s/^Arg2://; | |||||||||||||||||||||||||||
| 320 | 58 | $self->_addRelation($id, { | |||||||||||||||||||||||||||
| 321 | 'id' => $id, | ||||||||||||||||||||||||||||
| 322 | 'numId' => $numId, | ||||||||||||||||||||||||||||
| 323 | 'type' => $type, | ||||||||||||||||||||||||||||
| 324 | 'arg1' => $arg1, | ||||||||||||||||||||||||||||
| 325 | 'arg2' => $arg2, | ||||||||||||||||||||||||||||
| 326 | }); | ||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | 13 | close FILE; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | sub printStats { | ||||||||||||||||||||||||||||
| 333 | 0 | ▶ | my ($self, $filename, $addmode) = @_; | ||||||||||||||||||||||||||
|
Subroutine
printStats: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 0 | my $id; | |||||||||||||||||||||||||||
| 336 | my %terms; | ||||||||||||||||||||||||||||
| 337 | 0 | my %termTypes; | |||||||||||||||||||||||||||
| 338 | 0 | my %relations; | |||||||||||||||||||||||||||
| 339 | 0 | my %relationTypes; | |||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 0 | my $fh; | |||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ($filename eq "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | 0 | $fh = \*STDOUT; | |||||||||||||||||||||||||||
| 344 | } else { | ||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if (defined $addmode) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | 0 | ▶ | open $fh, ">>:utf8", $filename or die "no such file " . $filename . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | } else { | ||||||||||||||||||||||||||||
| 348 | 0 | ▶ | open $fh, ">:utf8", $filename or die "no such file " . $filename . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | print $fh $self->getStats; | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if ($filename ne "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | 0 | close $fh; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | sub getStats { | ||||||||||||||||||||||||||||
| 360 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
getStats: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 2 | my $id; | |||||||||||||||||||||||||||
| 363 | my %terms; | ||||||||||||||||||||||||||||
| 364 | 2 | my %termTypes; | |||||||||||||||||||||||||||
| 365 | 2 | my %relations; | |||||||||||||||||||||||||||
| 366 | 2 | my %relationTypes; | |||||||||||||||||||||||||||
| 367 | 2 | my $stats; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 2 | foreach $id (keys %{$self->_terms}) { | |||||||||||||||||||||||||||
| 370 | 119 | $terms{$self->_getTermFromId($id)->{'str'}}++; | |||||||||||||||||||||||||||
| 371 | 119 | $termTypes{$self->_getTermFromId($id)->{'type'}}++; | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 2 | foreach $id (keys %{$self->_relations}) { | |||||||||||||||||||||||||||
| 375 | 23 | $relations{$self->_getTermFromId($self->_getRelationFromId($id)->{'arg1'})->{'str'} . " : " . $self->_getTermFromId($self->_getRelationFromId($id)->{'arg2'})->{'str'}}++; | |||||||||||||||||||||||||||
| 376 | 23 | $relationTypes{$self->_getRelationFromId($id)->{'type'}}++; | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 2 | $stats = "number of annotated terms: " . scalar(keys %{$self->_terms}) . "\n"; | |||||||||||||||||||||||||||
| 381 | 2 | $stats .= "number of annotated relations: " . scalar(keys %{$self->_relations}) . "\n"; | |||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 2 | $stats .= "number of terms: " . scalar(keys %terms) . "\n"; | |||||||||||||||||||||||||||
| 384 | 2 | $stats .= "number of term type: " . scalar(keys %termTypes) . "\n"; | |||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 2 | $stats .= "number of relations: " . scalar(keys %relations) . "\n"; | |||||||||||||||||||||||||||
| 387 | 2 | $stats .= "number of relation type: " . scalar(keys %relationTypes) . "\n"; | |||||||||||||||||||||||||||
| 388 | 2 | return($stats); | |||||||||||||||||||||||||||
| 389 | # print "number of relations: " . scalar(keys %{$data->{'relations'}}) . "\n"; | ||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | sub printTermList { | ||||||||||||||||||||||||||||
| 394 | 0 | ▶ | my ($self, $filename, $addmode) = @_; | ||||||||||||||||||||||||||
|
Subroutine
printTermList: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 395 | 0 | my $id; | |||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | my $fh; | ||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if ($filename eq "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 0 | $fh = \*STDOUT; | |||||||||||||||||||||||||||
| 400 | } else { | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if (defined $addmode) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 403 | 0 | ▶ | open $fh, ">>:utf8", $filename or die "no such file " . $filename . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | } else { | ||||||||||||||||||||||||||||
| 405 | 0 | ▶ | open $fh, ">:utf8", $filename or die "no such file " . $filename . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | # foreach $id (keys %{$self->_terms}) { | ||||||||||||||||||||||||||||
| 409 | # print $fh $self->_getTermFromId($id)->{'str'} . " : : " . $self->_getTermFromId($id)->{$id}->{'type'} . " :\n"; | ||||||||||||||||||||||||||||
| 410 | # } | ||||||||||||||||||||||||||||
| 411 | 0 | print $fh $self->getTermList; | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if ($filename ne "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 0 | close $fh; | |||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | sub getTermList { | ||||||||||||||||||||||||||||
| 420 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
getTermList: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 421 | 2 | my $id; | |||||||||||||||||||||||||||
| 422 | 2 | my $termlistStr = ""; | |||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 2 | foreach $id (keys %{$self->_terms}) { | |||||||||||||||||||||||||||
| 425 | 119 | $termlistStr .= $self->_getTermFromId($id)->{'str'} . " : : " . $self->_getTermFromId($id)->{'type'} . " :\n"; | |||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | 2 | return($termlistStr); | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | sub printRelationList { | ||||||||||||||||||||||||||||
| 433 | 0 | ▶ | my ($self, $filename, $addmode) = @_; | ||||||||||||||||||||||||||
|
Subroutine
printRelationList: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 434 | 0 | my $fh; | |||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if ($filename eq "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | 0 | $fh = \*STDOUT; | |||||||||||||||||||||||||||
| 438 | } else { | ||||||||||||||||||||||||||||
| 439 | 0 | ▶ | if (defined $addmode) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | 0 | ▶ | open $fh, ">>:utf8", $filename or die "no such file " . $filename . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 441 | } else { | ||||||||||||||||||||||||||||
| 442 | 0 | ▶ | open $fh, ">:utf8", $filename or die "no such file " . $filename . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | 0 | print $fh $self->getRelationList; | |||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ($filename ne "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | 0 | close $fh; | |||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | sub getRelationList { | ||||||||||||||||||||||||||||
| 452 | 2 | ▶ | my ($self, $addmode) = @_; | ||||||||||||||||||||||||||
|
Subroutine
getRelationList: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 453 | 2 | my $id; | |||||||||||||||||||||||||||
| 454 | 2 | my $relationList = ""; | |||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 2 | foreach $id (keys %{$self->_relations}) { | |||||||||||||||||||||||||||
| 457 | 23 | $relationList .= $self->_getTermFromId($self->_getRelationFromId($id)->{'arg1'})->{'str'} . " : " . $self->_getTermFromId($self->_getRelationFromId($id)->{'arg2'})->{'str'} . " : " . $self->_getRelationFromId($id)->{'type'} . "\n"; | |||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | 2 | return($relationList); | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | sub getAnnotationList { | ||||||||||||||||||||||||||||
| 463 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
getAnnotationList: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 464 | 4 | my $id; | |||||||||||||||||||||||||||
| 465 | my $attrId; | ||||||||||||||||||||||||||||
| 466 | 4 | my $elt; | |||||||||||||||||||||||||||
| 467 | 4 | my $attr; | |||||||||||||||||||||||||||
| 468 | 4 | my $annotations = ""; | |||||||||||||||||||||||||||
| 469 | 4 | my $i; | |||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 4 | foreach $id (sort {&_sortId($a,$b)} keys %{$self->_terms}) { | |||||||||||||||||||||||||||
| 472 | 223 | $elt = $self->_getTermFromId($id); | |||||||||||||||||||||||||||
| 473 | 223 | $annotations .= $elt->{'id'} . "\t"; | |||||||||||||||||||||||||||
| 474 | 223 | $annotations .= $elt->{'type'} . " "; | |||||||||||||||||||||||||||
| 475 | 223 | ▶ | for($i=0; $i < scalar(@{$elt->{'start'}}); $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 476 | 226 | $annotations .= $elt->{'start'}->[$i] . " " . $elt->{'end'}->[$i] . ";"; | |||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | 223 | chop $annotations; | |||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 223 | $annotations .= "\t" . $elt->{'str'} . "\n"; | |||||||||||||||||||||||||||
| 481 | 223 | foreach $attrId (sort {&_sortId($a,$b)} @{$elt->{'attrlst'}}) { | |||||||||||||||||||||||||||
| 482 | 5 | $attr = $self->_getAttributeFromId($attrId); | |||||||||||||||||||||||||||
| 483 | 5 | $annotations .= $attr->{'id'} . "\t"; | |||||||||||||||||||||||||||
| 484 | 5 | $annotations .= $attr->{'type'} . " " . $attr->{'termId'} . " " . $attr->{'value'} . "\n"; | |||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | 4 | foreach $id (sort {&_sortId($a,$b)} keys %{$self->_relations}) { | |||||||||||||||||||||||||||
| 488 | 35 | $elt = $self->_getRelationFromId($id); | |||||||||||||||||||||||||||
| 489 | 35 | $annotations .= $elt->{'id'} . "\t"; | |||||||||||||||||||||||||||
| 490 | 35 | $annotations .= $elt->{'type'} . " Arg1:" . $elt->{'arg1'} . " Arg2:" . $elt->{'arg2'} . "\n"; | |||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | 4 | return($annotations); | |||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | sub _sortId { | ||||||||||||||||||||||||||||
| 496 | 1177 | ▶ | my ($A, $B) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_sortId: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 1177 | my $idA = $a; | |||||||||||||||||||||||||||
| 499 | 1177 | $idA =~ s/^[TAR]//; | |||||||||||||||||||||||||||
| 500 | 1177 | my $idB = $b; | |||||||||||||||||||||||||||
| 501 | 1177 | $idB =~ s/^[TAR]//; | |||||||||||||||||||||||||||
| 502 | 1177 | return($idA <=> $idB); | |||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | sub print { | ||||||||||||||||||||||||||||
| 506 | 0 | ▶ | my ($self, $filename, $addmode) = @_; | ||||||||||||||||||||||||||
|
Subroutine
print: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||
| 507 | 0 | my $fh; | |||||||||||||||||||||||||||
| 508 | my $line; | ||||||||||||||||||||||||||||
| 509 | 0 | my $file; | |||||||||||||||||||||||||||
| 510 | 0 | my $annotationFilename = $filename; | |||||||||||||||||||||||||||
| 511 | 0 | $annotationFilename =~ s/\.txt$/.ann/; | |||||||||||||||||||||||||||
| 512 | 0 | my $textFilename = $filename; | |||||||||||||||||||||||||||
| 513 | 0 | $textFilename =~ s/\.ann$/.txt/; | |||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | # print/copy text | ||||||||||||||||||||||||||||
| 516 | 0 | ▶ | if ($filename eq "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 517 | 0 | $fh = \*STDOUT; | |||||||||||||||||||||||||||
| 518 | } else { | ||||||||||||||||||||||||||||
| 519 | 0 | ▶ | if (defined $addmode) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 520 | 0 | ▶ | open $fh, ">>:utf8", $textFilename or die "no such file $textFilename\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 521 | } else { | ||||||||||||||||||||||||||||
| 522 | 0 | ▶ | open $fh, ">:utf8", $textFilename or die "no such file $textFilename\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | 0 | foreach $file (@{$self->_textFilename}) { | |||||||||||||||||||||||||||
| 526 | 0 | ▶ | open FILE, $file or die "no such file " . $file . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 527 | 0 | ▶ | while($line = <FILE>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 528 | 0 | print $fh $line; | |||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | 0 | close FILE; | |||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||
| 532 | 0 | ▶ | if ($filename ne "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 533 | 0 | close $fh; | |||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | # print annotations | ||||||||||||||||||||||||||||
| 537 | 0 | ▶ | if ($filename eq "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 538 | 0 | $fh = \*STDOUT; | |||||||||||||||||||||||||||
| 539 | } else { | ||||||||||||||||||||||||||||
| 540 | 0 | ▶ | if (defined $addmode) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 541 | 0 | ▶ | open $fh, ">>:utf8", $annotationFilename or die "no such file $annotationFilename\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 542 | } else { | ||||||||||||||||||||||||||||
| 543 | 0 | ▶ | open $fh, ">:utf8", $annotationFilename or die "no such file $annotationFilename\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||
| 546 | 0 | print $fh $self->getAnnotationList; | |||||||||||||||||||||||||||
| 547 | 0 | ▶ | if ($filename ne "-") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 548 | 0 | close $fh; | |||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | 6 | 1; | |||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | __END__ | ||||||||||||||||||||||||||||