blib/lib/Lingua/Ogmios.pm

filter: Statementstmt 90.3% 103 / 114 Branchbran 68.1% 15 / 22 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.0% 17 / 20 Podpod 100% 13 / 13 totaltotal 83.8% 150 / 179 CC 18 SCAR 12.3
CC
18
Cov
85%
load_config
7.0
loadDocuments
5.1
linguisticProcessing
5.1
CRAP 3.4
« blib/lib/Lingua/Ogmios/DocumentCollection.pm ↑ Summary blib/lib/Lingua/Ogmios/Annotations/LogProcessing.pm »
1 package Lingua::Ogmios;
2  
3  
4 16 our $VERSION='0.011';
5  
6  
7 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 16 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 16 ▶use Lingua::Ogmios::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 16 ▶use Lingua::Ogmios::FileManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 ▶use Lingua::Ogmios::DocumentCollection;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 16 ▶use Lingua::Ogmios::Timer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 16 my $debug_devel_level = 0;
20  
21 14 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
22 14 my $class = shift;
23 14 my %args = @_;
24  
25 14 binmode(STDERR, ":utf8");
26 14 binmode(STDOUT, ":utf8");
27 14 binmode(STDIN, ":utf8");
28  
29 14 ▶ warn "\n----\nNew Platform\n" unless $debug_devel_level < 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $debug_devel_level < 1 0 14 14
30  
31 14 my $rcfile = "/etc/ogmios/nlpplatform.rc";
32 14 my $config;
33  
34 14 ▶ if (exists $args{"rcfile"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"rcfile"}) 13 1 14
35 13 $rcfile = $args{"rcfile"};
36 }
37  
38 14 my $NLPPlatform = {
39 'Config' => undef,
40 'DocumentCollection' => [],
41 "timer" => Lingua::Ogmios::Timer->new(),
42 };
43  
44 14 bless $NLPPlatform, $class;
45 14 $NLPPlatform->{"timer"}->start;
46
47 14 $NLPPlatform->load_config($rcfile);
48  
49 14 return $NLPPlatform;
50  
51 }
52  
53 sub load_config
54 14 ▶{
Subroutine load_config: called CC=6 SCAR=19.4
Pod documented
55 14 my ($self,$rcfile) = @_;
56  
57 14 ▶ warn "self = $self\nrcfile=$rcfile\n" unless $debug_devel_level < 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $debug_devel_level < 2 0 14 14
58  
59 14 ▶ if ( ! -f $rcfile ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $rcfile) 1 13 14
60 1 warn "$rcfile does not exist; Configuration is not loaded\n";
61 1 return (-1);
62 }
63
64 # Read the configuration file
65  
66 13 ▶ warn "Setting the configuration file ...\n" unless $debug_devel_level < 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $debug_devel_level < 1 0 13 13
67 13 ▶ if ((!defined $rcfile) || ($rcfile eq "")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rcfile or $rcfile eq "") 0 13 13
Condition33%1/3
not defined $rcfile or $rcfile eq ""
l!l&&r!l&&!r
0013
MC/DC0%0/2
not defined $rcfile or $rcfile eq ""
not defined $rcfile $rcfile eq ""
Truth table33%1/3
not(A) or B
A= not defined $rcfileB= $rcfile eq ""
ABresult
1X1
011
000
68 0 $rcfile = "/etc/ogmios/nlpplatform.rc";
69 }
70  
71 13 $self->{'Config'} = Lingua::Ogmios::Config->new($rcfile);
72
73 # mkpath($config{'ALVISTMP'});
74 # return(%config);
75 }
76  
77 273 ▶sub getConfig {
Subroutine getConfig: called CC=1 SCAR=0.0
Pod documented
78 273 my ($self) = @_;
79  
80 273 return($self->{Config});
81 }
82  
83 3 ▶sub printConfig {
Subroutine printConfig: called CC=1 SCAR=0.0
Pod documented
84  
85 3 my $self = shift @_;
86  
87 3 return($self->getConfig->print(@_));
88 }
89  
90 0 ▶sub printConfigDOT {
Subroutine printConfigDOT: not called CC=1 SCAR=6.9
Pod documented
91  
92 0 my $self = shift @_;
93  
94 0 return($self->getConfig->printDOT(@_));
95 }
96  
97 31 ▶sub getDocumentCollection {
Subroutine getDocumentCollection: called CC=1 SCAR=0.0
Pod documented
98 31 my ($self) = @_;
99  
100 31 return($self->{'DocumentCollection'});
101 }
102  
103 11 ▶sub addDocumentCollection {
Subroutine addDocumentCollection: called CC=1 SCAR=0.0
Pod documented
104 11 my ($self, $documentCollection) = @_;
105  
106 11 push @{$self->getDocumentCollection}, $documentCollection;
107 }
108  
109 0 ▶sub loadData {
Subroutine loadData: not called CC=1 SCAR=6.9
Pod documented
110 0 my ($self, $data) = @_;
111  
112 0 my $documentCollection = Lingua::Ogmios::DocumentCollection->new($data, "data");
113
114 0 $self->addDocumentCollection($documentCollection);
115 }
116  
117  
118  
119 12 ▶sub loadDocuments {
Subroutine loadDocuments: called CC=5 SCAR=16.3
Pod documented
120  
121 12 my ($self, $files) = @_;
122  
123 12 my $file;
124 my $type;
125 12 my $Filemanager;
126  
127 # is a directory
128 # foreach do below foreach file
129  
130 # is a file
131  
132 # 1. Alvis : a. 1 document (keep in memory)
133 # b. N documents
134 # I. Keep all in memory
135 # II. Store temporary in a spool
136  
137 # i. Processing by document
138 # ii. Processing of M documents
139  
140 # 2. non Alvis, XML : -> Convert to Alvis XML format (1 document - or less often N documents )
141  
142 # 3. non Alvis, non XML : -> Convertion to Alvis (1 document)
143  
144 12 $Filemanager = Lingua::Ogmios::FileManager->new($self->getConfig->getSupplementaryMagicFile);
145  
146 12 foreach $file (@$files) {
147 12 ▶ if ( ! -e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $file) { } 1 11 12
148 1 warn "$file does not exist; File not loaded\n";
149 } else {
150 # Type/format of the document
151 11 ▶ if (($self->getConfig->isInputInALVISFormat) || ($Filemanager->getType($file) eq "text/xml ns=http://alvis.info/enriched/")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getConfig->isInputInALVISFormat or $Filemanager->getType($file) eq "text/xml ns=http://alvis.info/enriched/") 11 0 11
Condition33%1/3
$self->getConfig->isInputInALVISFormat or $Filemanager->getType($file) eq "text/xml ns=http://alvis.info/enriched/"
l!l&&r!l&&!r
1100
MC/DC0%0/2
$self->getConfig->isInputInALVISFormat or $Filemanager->getType($file) eq "text/xml ns=http://alvis.info/enriched/"
$self->getConfig->isInputInALVISFormat $Filemanager->getType($file) eq "text/xml ns=http://alvis.info/enriched/"
Truth table33%1/3
A or B
A= $self->getConfig->isInputInALVISFormatB= $Filemanager->getType($file) eq "text/xml ns=http://alvis.info/enriched/"
ABresult
1X1
011
000
152 11 warn "Document $file is in Alvis XML format\n";
153 # Alvis XML format
154 11 my $documentCollection = Lingua::Ogmios::DocumentCollection->new($file, "file", $self->getConfig);
155
156 11 $self->addDocumentCollection($documentCollection);
157 }
158  
159 # Convert into ALVIS XML
160 }
161
162 }
163 }
164  
165 9 ▶sub tokenisation {
Subroutine tokenisation: called CC=2 SCAR=6.9
Pod documented
166 9 my ($self) = @_;
167  
168 9 my $documentCollection;
169  
170 9 foreach $documentCollection (@{$self->getDocumentCollection}) {
171 8 $documentCollection->tokenisation;
172 }
173 9 return(0);
174 }
175  
176 6 ▶sub linguisticProcessing {
Subroutine linguisticProcessing: called CC=5 SCAR=16.3
Pod documented
177 6 my ($self) = @_;
178  
179 6 my $documentCollection;
180 my $processing;
181 6 my $wrapper;
182  
183  
184 # warn "Processing with the wrapper: " . $self->getConfig->getNLPToolFromIndex($self->getConfig->processingTool($processing))->wrapper . "\n";
185
186 # }
187  
188 6 warn "\n";
189  
190 6 my @docset = values(%{$self->getDocumentCollection->[0]->getDocuments});
191  
192 6 my $tool_config;
193  
194 my $NLPTool;
195 6 my $position;
196  
197 # TODO Externalize the setting of the NLP wrappers;
198  
199 # foreach $wrapper ($self->getConfig->getOrderedWrappers) {
200  
201 6 warn "number of process: " . $self->getConfig->getProcessingSetSize . "\n";
202  
203 6 ▶ if ($self->getConfig->getProcessingSetSize > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getConfig->getProcessingSetSize > 0) 6 0 6
204  
205 6 $position = 0;
206 6 foreach $processing ($self->getConfig->getOrderedProcessing) {
207 24 $position++;
208 24 $tool_config = $self->getConfig->getNLPToolFromIndex($self->getConfig->processingTool($processing));
209 24 $wrapper = $tool_config->wrapper;
210
211 24 warn "[LOG] Processing with the wrapper: " . $wrapper . " ($processing) " . $self->getConfig->processingTool($processing) . "\n";
212
213 24 eval "require $wrapper";
214 24 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 24 24
215 0 warn $@ . "\n";
216 0 die "Problem while loading wrapper $wrapper - Abort\n\n";
217 } else {
218 24 ▶ if ($position == $self->getConfig->getProcessingSetSize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position == $self->getConfig->getProcessingSetSize) 5 19 24
219 5 $position = 'last';
220 }
221 24 warn "[LOG] position: $position (" . $self->getConfig->getProcessingSetSize . ")\n";
222 24 $NLPTool = $wrapper->new($tool_config, $self->getConfig->getOgmiosTMPFILE, $self->getConfig->getOgmiosLOGFILE, $position, $self->getConfig->xmloutput_noStdXmlOutput, $self->getConfig->OgmiosOutStream);
223 24 $NLPTool->run(\@docset);
224 }
225 }
226 }
227  
228 # foreach $documentCollection (@{$self->getDocumentCollection}) {
229 # $documentCollection->printDocumentList;
230 # }
231  
232 # docColl
233 # subdocColl
234 # docRec
235 0 return(0);
236 }
237  
238 2 ▶sub XMLout {
Subroutine XMLout: called CC=2 SCAR=6.9
Pod documented
239 2 my ($self) = @_;
240  
241 2 my $documentCollection;
242 my $str;
243  
244 2 $str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
245  
246 2 foreach $documentCollection (@{$self->getDocumentCollection}) {
247 1 $str .= $documentCollection->XMLout;
248 }
249 2 return($str);
250
251 }
252  
253  
254 0 ▶sub getTimer {
Subroutine getTimer: not called CC=1 SCAR=6.9
Pod documented
255 0 my ($self) = @_;
256  
257 0 return($self->{'timer'});
258 }
259  
260  
261 16 1;
262  
263 __END__
« blib/lib/Lingua/Ogmios/DocumentCollection.pm ↑ Summary blib/lib/Lingua/Ogmios/Annotations/LogProcessing.pm »