| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Lingua::Ogmios; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION='0.011'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
16
|
|
|
16
|
|
334894
|
use strict; |
|
|
16
|
|
|
|
|
38
|
|
|
|
16
|
|
|
|
|
417
|
|
|
8
|
16
|
|
|
16
|
|
72
|
use warnings; |
|
|
16
|
|
|
|
|
25
|
|
|
|
16
|
|
|
|
|
431
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
16
|
|
|
16
|
|
71
|
use File::Path; |
|
|
16
|
|
|
|
|
31
|
|
|
|
16
|
|
|
|
|
1090
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
16
|
|
|
16
|
|
9235
|
use Lingua::Ogmios::Config; |
|
|
16
|
|
|
|
|
76
|
|
|
|
16
|
|
|
|
|
541
|
|
|
14
|
16
|
|
|
16
|
|
9238
|
use Lingua::Ogmios::FileManager; |
|
|
16
|
|
|
|
|
58
|
|
|
|
16
|
|
|
|
|
562
|
|
|
15
|
16
|
|
|
16
|
|
9116
|
use Lingua::Ogmios::DocumentCollection; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Lingua::Ogmios::Timer; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $debug_devel_level = 0; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
|
22
|
|
|
|
|
|
|
my $class = shift; |
|
23
|
|
|
|
|
|
|
my %args = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
binmode(STDERR, ":utf8"); |
|
26
|
|
|
|
|
|
|
binmode(STDOUT, ":utf8"); |
|
27
|
|
|
|
|
|
|
binmode(STDIN, ":utf8"); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
warn "\n----\nNew Platform\n" unless $debug_devel_level < 1; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $rcfile = "/etc/ogmios/nlpplatform.rc"; |
|
32
|
|
|
|
|
|
|
my $config; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if (exists $args{"rcfile"}) { |
|
35
|
|
|
|
|
|
|
$rcfile = $args{"rcfile"}; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $NLPPlatform = { |
|
39
|
|
|
|
|
|
|
'Config' => undef, |
|
40
|
|
|
|
|
|
|
'DocumentCollection' => [], |
|
41
|
|
|
|
|
|
|
"timer" => Lingua::Ogmios::Timer->new(), |
|
42
|
|
|
|
|
|
|
}; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
bless $NLPPlatform, $class; |
|
45
|
|
|
|
|
|
|
$NLPPlatform->{"timer"}->start; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$NLPPlatform->load_config($rcfile); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
return $NLPPlatform; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub load_config |
|
54
|
|
|
|
|
|
|
{ |
|
55
|
|
|
|
|
|
|
my ($self,$rcfile) = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
warn "self = $self\nrcfile=$rcfile\n" unless $debug_devel_level < 2; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if ( ! -f $rcfile ) { |
|
60
|
|
|
|
|
|
|
warn "$rcfile does not exist; Configuration is not loaded\n"; |
|
61
|
|
|
|
|
|
|
return (-1); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Read the configuration file |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
warn "Setting the configuration file ...\n" unless $debug_devel_level < 1; |
|
67
|
|
|
|
|
|
|
if ((!defined $rcfile) || ($rcfile eq "")) { |
|
68
|
|
|
|
|
|
|
$rcfile = "/etc/ogmios/nlpplatform.rc"; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$self->{'Config'} = Lingua::Ogmios::Config->new($rcfile); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# mkpath($config{'ALVISTMP'}); |
|
74
|
|
|
|
|
|
|
# return(%config); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub getConfig { |
|
78
|
|
|
|
|
|
|
my ($self) = @_; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return($self->{Config}); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub printConfig { |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $self = shift @_; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return($self->getConfig->print(@_)); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub printConfigDOT { |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $self = shift @_; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return($self->getConfig->printDOT(@_)); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub getDocumentCollection { |
|
98
|
|
|
|
|
|
|
my ($self) = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return($self->{'DocumentCollection'}); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub addDocumentCollection { |
|
104
|
|
|
|
|
|
|
my ($self, $documentCollection) = @_; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
push @{$self->getDocumentCollection}, $documentCollection; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub loadData { |
|
110
|
|
|
|
|
|
|
my ($self, $data) = @_; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $documentCollection = Lingua::Ogmios::DocumentCollection->new($data, "data"); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$self->addDocumentCollection($documentCollection); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub loadDocuments { |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my ($self, $files) = @_; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $file; |
|
124
|
|
|
|
|
|
|
my $type; |
|
125
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
$Filemanager = Lingua::Ogmios::FileManager->new($self->getConfig->getSupplementaryMagicFile); |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
foreach $file (@$files) { |
|
147
|
|
|
|
|
|
|
if ( ! -e $file ) { |
|
148
|
|
|
|
|
|
|
warn "$file does not exist; File not loaded\n"; |
|
149
|
|
|
|
|
|
|
} else { |
|
150
|
|
|
|
|
|
|
# Type/format of the document |
|
151
|
|
|
|
|
|
|
if (($self->getConfig->isInputInALVISFormat) || ($Filemanager->getType($file) eq "text/xml ns=http://alvis.info/enriched/")) { |
|
152
|
|
|
|
|
|
|
warn "Document $file is in Alvis XML format\n"; |
|
153
|
|
|
|
|
|
|
# Alvis XML format |
|
154
|
|
|
|
|
|
|
my $documentCollection = Lingua::Ogmios::DocumentCollection->new($file, "file", $self->getConfig); |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
$self->addDocumentCollection($documentCollection); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# Convert into ALVIS XML |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub tokenisation { |
|
166
|
|
|
|
|
|
|
my ($self) = @_; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
my $documentCollection; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
foreach $documentCollection (@{$self->getDocumentCollection}) { |
|
171
|
|
|
|
|
|
|
$documentCollection->tokenisation; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
return(0); |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub linguisticProcessing { |
|
177
|
|
|
|
|
|
|
my ($self) = @_; |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $documentCollection; |
|
180
|
|
|
|
|
|
|
my $processing; |
|
181
|
|
|
|
|
|
|
my $wrapper; |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# warn "Processing with the wrapper: " . $self->getConfig->getNLPToolFromIndex($self->getConfig->processingTool($processing))->wrapper . "\n"; |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# } |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
warn "\n"; |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
my @docset = values(%{$self->getDocumentCollection->[0]->getDocuments}); |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
my $tool_config; |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
my $NLPTool; |
|
195
|
|
|
|
|
|
|
my $position; |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# TODO Externalize the setting of the NLP wrappers; |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# foreach $wrapper ($self->getConfig->getOrderedWrappers) { |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
warn "number of process: " . $self->getConfig->getProcessingSetSize . "\n"; |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
if ($self->getConfig->getProcessingSetSize > 0) { |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
$position = 0; |
|
206
|
|
|
|
|
|
|
foreach $processing ($self->getConfig->getOrderedProcessing) { |
|
207
|
|
|
|
|
|
|
$position++; |
|
208
|
|
|
|
|
|
|
$tool_config = $self->getConfig->getNLPToolFromIndex($self->getConfig->processingTool($processing)); |
|
209
|
|
|
|
|
|
|
$wrapper = $tool_config->wrapper; |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
warn "[LOG] Processing with the wrapper: " . $wrapper . " ($processing) " . $self->getConfig->processingTool($processing) . "\n"; |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
eval "require $wrapper"; |
|
214
|
|
|
|
|
|
|
if ($@) { |
|
215
|
|
|
|
|
|
|
warn $@ . "\n"; |
|
216
|
|
|
|
|
|
|
die "Problem while loading wrapper $wrapper - Abort\n\n"; |
|
217
|
|
|
|
|
|
|
} else { |
|
218
|
|
|
|
|
|
|
if ($position == $self->getConfig->getProcessingSetSize) { |
|
219
|
|
|
|
|
|
|
$position = 'last'; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
warn "[LOG] position: $position (" . $self->getConfig->getProcessingSetSize . ")\n"; |
|
222
|
|
|
|
|
|
|
$NLPTool = $wrapper->new($tool_config, $self->getConfig->getOgmiosTMPFILE, $self->getConfig->getOgmiosLOGFILE, $position, $self->getConfig->xmloutput_noStdXmlOutput, $self->getConfig->OgmiosOutStream); |
|
223
|
|
|
|
|
|
|
$NLPTool->run(\@docset); |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# foreach $documentCollection (@{$self->getDocumentCollection}) { |
|
229
|
|
|
|
|
|
|
# $documentCollection->printDocumentList; |
|
230
|
|
|
|
|
|
|
# } |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# docColl |
|
233
|
|
|
|
|
|
|
# subdocColl |
|
234
|
|
|
|
|
|
|
# docRec |
|
235
|
|
|
|
|
|
|
return(0); |
|
236
|
|
|
|
|
|
|
} |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub XMLout { |
|
239
|
|
|
|
|
|
|
my ($self) = @_; |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
my $documentCollection; |
|
242
|
|
|
|
|
|
|
my $str; |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
$str = "\n"; |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
foreach $documentCollection (@{$self->getDocumentCollection}) { |
|
247
|
|
|
|
|
|
|
$str .= $documentCollection->XMLout; |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
return($str); |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
} |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub getTimer { |
|
255
|
|
|
|
|
|
|
my ($self) = @_; |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
return($self->{'timer'}); |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
1; |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
__END__ |