| 1 | package Lingua::Ogmios::DocumentCollection; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use Lingua::Ogmios::DocumentRecord; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 11 | my ($class, $file, $type, $lingAnalysisLoad) = @_; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 11 | my $collection = { | |||||||||||||||||||||||||||
| 13 | 'documents' => {}, | ||||||||||||||||||||||||||||
| 14 | 'count' => 0, | ||||||||||||||||||||||||||||
| 15 | 'attributes' => [], | ||||||||||||||||||||||||||||
| 16 | }; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 11 | bless $collection, $class; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Parsing the file and loading documents | ||||||||||||||||||||||||||||
| 21 | 11 | ▶ | if (($type eq "file") && (defined $file)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "file" and defined $file
MC/DC0%0/2
$type eq "file" and defined $file
$type eq "file"
defined $file
Truth table33%1/3
A and B
A= $type eq "file"B= defined $file
| |||||||||||||||||||||||||||||
| 22 | 11 | $collection->_parseDocumentCollectionFromFile($file, $lingAnalysisLoad); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 11 | ▶ | if (($type eq "data") && (defined $file)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "data" and defined $file
MC/DC0%0/2
$type eq "data" and defined $file
$type eq "data"
defined $file
Truth table33%1/3
A and B
A= $type eq "data"B= defined $file
| |||||||||||||||||||||||||||||
| 26 | 0 | $collection->_parseDocumentCollectionFromData($file, $lingAnalysisLoad); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 11 | return($collection); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 11 | ▶ | sub setAttributes { | ||||||||||||||||||||||||||
|
Subroutine
setAttributes: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 11 | my ($self, $attributes) = @_; | |||||||||||||||||||||||||||
| 36 | 11 | my $attr; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 11 | foreach $attr (@$attributes) { | |||||||||||||||||||||||||||
| 39 | 22 | push @{$self->{'attributes'}}, {'nodeName' => $attr->nodeName, | |||||||||||||||||||||||||||
| 40 | 'value' => $attr->value, | ||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub getAttributes { | ||||||||||||||||||||||||||
|
Subroutine
getAttributes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | return($self->{'attributes'}); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 11 | ▶ | sub _parseDocumentCollectionFromFile { | ||||||||||||||||||||||||||
|
Subroutine
_parseDocumentCollectionFromFile: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 52 | 11 | my ($self, $file, $lingAnalysisLoad) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Parsing the file and loading documents | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 11 | my $Parser=XML::LibXML->new(); | |||||||||||||||||||||||||||
| 57 | 11 | my $document; | |||||||||||||||||||||||||||
| 58 | my $document_record; | ||||||||||||||||||||||||||||
| 59 | 11 | my $parsedDocument; | |||||||||||||||||||||||||||
| 60 | 11 | my $id; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 11 | eval { | |||||||||||||||||||||||||||
| 63 | 11 | $document=$Parser->parse_file($file); | |||||||||||||||||||||||||||
| 64 | }; | ||||||||||||||||||||||||||||
| 65 | 11 | ▶ | if ($@){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | warn "Parsing the doc failed: $@. Trying to get the IDs..\n"; | |||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 11 | ▶ | if ($document) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 11 | $self->_parseDocumentCollection($document, $lingAnalysisLoad); | |||||||||||||||||||||||||||
| 70 | } else { | ||||||||||||||||||||||||||||
| 71 | 0 | warn "Parsing the doc failed. Doc: " . ($self->getCount + 1) . "(in $file)\n"; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub _parseDocumentCollectionFromData { | ||||||||||||||||||||||||||
|
Subroutine
_parseDocumentCollectionFromData: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 77 | 0 | my ($self, $file, $lingAnalysisLoad) = @_; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Parsing the file and loading documents | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | my $Parser=XML::LibXML->new(); | |||||||||||||||||||||||||||
| 82 | 0 | my $document; | |||||||||||||||||||||||||||
| 83 | my $document_record; | ||||||||||||||||||||||||||||
| 84 | 0 | my $parsedDocument; | |||||||||||||||||||||||||||
| 85 | 0 | my $id; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | eval { | |||||||||||||||||||||||||||
| 88 | 0 | $document=$Parser->parse_string($file); | |||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($@){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | warn "Parsing the doc failed: $@. Trying to get the IDs..\n"; | |||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($document) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | $self->_parseDocumentCollection($document, $lingAnalysisLoad); | |||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||
| 96 | 0 | warn "Parsing the doc failed. Doc: " . ($self->getCount + 1) . "(in $file)\n"; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 11 | ▶ | sub _parseDocumentCollection { | ||||||||||||||||||||||||||
|
Subroutine
_parseDocumentCollection: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 102 | 11 | my ($self, $document, $platformConfig) = @_; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # Parsing the file and loading documents | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # my $Parser=XML::LibXML->new(); | ||||||||||||||||||||||||||||
| 107 | # my $document; | ||||||||||||||||||||||||||||
| 108 | 11 | my $document_record; | |||||||||||||||||||||||||||
| 109 | my $parsedDocument; | ||||||||||||||||||||||||||||
| 110 | # my $id; | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # eval { | ||||||||||||||||||||||||||||
| 113 | # $document=$Parser->parse_file($file); | ||||||||||||||||||||||||||||
| 114 | # }; | ||||||||||||||||||||||||||||
| 115 | # if ($@){ | ||||||||||||||||||||||||||||
| 116 | # warn "Parsing the doc failed: $@. Trying to get the IDs..\n"; | ||||||||||||||||||||||||||||
| 117 | # } | ||||||||||||||||||||||||||||
| 118 | # else { | ||||||||||||||||||||||||||||
| 119 | # if ($document) { | ||||||||||||||||||||||||||||
| 120 | 11 | my $root=$document->documentElement(); | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 11 | my @attr = $root->attributes; | |||||||||||||||||||||||||||
| 123 | 11 | $self->setAttributes(\@attr); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 11 | foreach $document_record ($root->getChildrenByTagName('documentRecord')) { | |||||||||||||||||||||||||||
| 126 | 14 | $parsedDocument = Lingua::Ogmios::DocumentRecord->new($document_record, $platformConfig); | |||||||||||||||||||||||||||
| 127 | 14 | $self->addDocument($parsedDocument); | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | # } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 14 | ▶ | sub addDocument { | ||||||||||||||||||||||||||
|
Subroutine
addDocument: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 133 | 14 | my ($self, $parsedDocument) = @_; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 14 | $self->{'documents'}->{$parsedDocument->getId}->{"document"} = $parsedDocument; | |||||||||||||||||||||||||||
| 136 | 14 | $self->{'documents'}->{$parsedDocument->getId}->{"order"} = $self->{'count'}; | |||||||||||||||||||||||||||
| 137 | 14 | $self->{'count'}++; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub setCount { | ||||||||||||||||||||||||||
|
Subroutine
setCount: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 141 | 0 | my ($self, $value)= @_; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | $self->{'count'} = $value; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub resetCount { | ||||||||||||||||||||||||||
|
Subroutine
resetCount: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 148 | 0 | my ($self)= @_; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | $self->setCount(0); | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub getCount { | ||||||||||||||||||||||||||
|
Subroutine
getCount: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 155 | 0 | my ($self)= @_; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | return($self->{'count'}); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub incrCount { | ||||||||||||||||||||||||||
|
Subroutine
incrCount: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 162 | 0 | my ($self)= @_; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | $self->setCount($self->getCount + 1); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub decrCount { | ||||||||||||||||||||||||||
|
Subroutine
decrCount: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 168 | 0 | my ($self)= @_; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | $self->setCount($self->getCount - 1); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 17 | ▶ | sub getDocuments { | ||||||||||||||||||||||||||
|
Subroutine
getDocuments: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 174 | 17 | my ($self) = @_; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 17 | my %documents; | |||||||||||||||||||||||||||
| 177 | my $documentId; | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 17 | foreach $documentId (keys %{$self->{'documents'}}) { | |||||||||||||||||||||||||||
| 180 | 24 | $documents{$documentId} = $self->{'documents'}->{$documentId}->{"document"}; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 17 | return(\%documents); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 1 | ▶ | sub getSortedDocuments { | ||||||||||||||||||||||||||
|
Subroutine
getSortedDocuments: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 187 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 1 | my @documents; | |||||||||||||||||||||||||||
| 190 | my $documentId; | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | foreach $documentId (sort { $self->{'documents'}->{$a}->{"order"} <=> $self->{'documents'}->{$b}->{"order"}} keys %{$self->{'documents'}}) { | |||||||||||||||||||||||||||
| 193 | 1 | push @documents, $self->{'documents'}->{$documentId}->{"document"}; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 1 | return(\@documents); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub getDocument { | ||||||||||||||||||||||||||
|
Subroutine
getDocument: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 200 | 0 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | return($self->getDocuments->{$id}); | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | ▶ | sub existsDocument { | ||||||||||||||||||||||||||
|
Subroutine
existsDocument: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 206 | 0 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | return(exists($self->getDocuments->{$id})); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 8 | ▶ | sub tokenisation { | ||||||||||||||||||||||||||
|
Subroutine
tokenisation: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 212 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 8 | my $document; | |||||||||||||||||||||||||||
| 215 | 8 | my $record_log = 1; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 8 | foreach $document (values %{$self->getDocuments}) { | |||||||||||||||||||||||||||
| 218 | 11 | $record_log = $document->tokenisation; | |||||||||||||||||||||||||||
| 219 | # if ($document->getAnnotations->getTokenLevel->getSize == 0) { | ||||||||||||||||||||||||||||
| 220 | # $record_log = 0; | ||||||||||||||||||||||||||||
| 221 | # } | ||||||||||||||||||||||||||||
| 222 | 11 | $document->computeSectionFromToken($record_log); | |||||||||||||||||||||||||||
| 223 | # $record_log = 1; | ||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | 8 | return(0); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 1 | ▶ | sub XMLout { | ||||||||||||||||||||||||||
|
Subroutine
XMLout: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 229 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 1 | my $document; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | my $str; | ||||||||||||||||||||||||||||
| 234 | 1 | my $attr; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 1 | $str = '<documentCollection'; | |||||||||||||||||||||||||||
| 237 | 1 | foreach $attr (@{$self->getAttributes}) { | |||||||||||||||||||||||||||
| 238 | 2 | $str .= " " . $attr->{'nodeName'} . '="' . $attr->{'value'} . '"'; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | 1 | $str .= ">\n"; | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # foreach $document (values %{$self->getDocuments}) { | ||||||||||||||||||||||||||||
| 244 | 1 | foreach $document (@{$self->getSortedDocuments}) { | |||||||||||||||||||||||||||
| 245 | 1 | $str .= $document->XMLout; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | 1 | $str .= "</documentCollection>"; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 1 | return($str); | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 1 | ▶ | sub getDocumentList { | ||||||||||||||||||||||||||
|
Subroutine
getDocumentList: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 253 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 1 | return(keys %{$self->getDocuments}); | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub printDocumentList { | ||||||||||||||||||||||||||
|
Subroutine
printDocumentList: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 259 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 260 | 0 | my $doc_id; | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 0 | warn "\n\nDocument Id List \n"; | |||||||||||||||||||||||||||
| 263 | 0 | foreach $doc_id ($self->getDocumentList) { | |||||||||||||||||||||||||||
| 264 | 0 | warn "\t$doc_id\n"; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | 0 | warn "\n"; | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 16 | 1; | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | __END__ | ||||||||||||||||||||||||||||