| 1 | package Lingua::Ogmios; | ||
| 2 | |||
| 3 | |||
| 4 | our $VERSION='0.01'; | ||
| 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=2.6
| |||
| 15 | use Lingua::Ogmios::DocumentCollection; | ||
| 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 | |||
| 74 | |||
| 75 | # mkpath($config{'ALVISTMP'}); | ||
| 76 | # return(%config); | ||
| 77 | } | ||
| 78 | |||
| 79 | sub getConfig { | ||
| 80 | my ($self) = @_; | ||
| 81 | |||
| 82 | return($self->{Config}); | ||
| 83 | } | ||
| 84 | |||
| 85 | sub printConfig { | ||
| 86 | |||
| 87 | my $self = shift @_; | ||
| 88 | |||
| 89 | return($self->getConfig->print(@_)); | ||
| 90 | } | ||
| 91 | |||
| 92 | sub printConfigDOT { | ||
| 93 | |||
| 94 | my $self = shift @_; | ||
| 95 | |||
| 96 | return($self->getConfig->printDOT(@_)); | ||
| 97 | } | ||
| 98 | |||
| 99 | sub getDocumentCollection { | ||
| 100 | my ($self) = @_; | ||
| 101 | |||
| 102 | return($self->{'DocumentCollection'}); | ||
| 103 | } | ||
| 104 | |||
| 105 | sub addDocumentCollection { | ||
| 106 | my ($self, $documentCollection) = @_; | ||
| 107 | |||
| 108 | push @{$self->getDocumentCollection}, $documentCollection; | ||
| 109 | } | ||
| 110 | |||
| 111 | sub loadData { | ||
| 112 | my ($self, $data) = @_; | ||
| 113 | |||
| 114 | my $documentCollection = Lingua::Ogmios::DocumentCollection->new($data, "data"); | ||
| 115 | |||
| 116 | $self->addDocumentCollection($documentCollection); | ||
| 117 | } | ||
| 118 | |||
| 119 | |||
| 120 | |||
| 121 | sub loadDocuments { | ||
| 122 | |||
| 123 | my ($self, $files) = @_; | ||
| 124 | |||
| 125 | my $file; | ||
| 126 | my $type; | ||
| 127 | my $Filemanager; | ||
| 128 | |||
| 129 | # is a directory | ||
| 130 | # foreach do below foreach file | ||
| 131 | |||
| 132 | # is a file | ||
| 133 | |||
| 134 | # 1. Alvis : a. 1 document (keep in memory) | ||
| 135 | # b. N documents | ||
| 136 | # I. Keep all in memory | ||
| 137 | # II. Store temporary in a spool | ||
| 138 | |||
| 139 | # i. Processing by document | ||
| 140 | # ii. Processing of M documents | ||
| 141 | |||
| 142 | # 2. non Alvis, XML : -> Convert to Alvis XML format (1 document - or less often N documents ) | ||
| 143 | |||
| 144 | # 3. non Alvis, non XML : -> Convertion to Alvis (1 document) | ||
| 145 | |||
| 146 | $Filemanager = Lingua::Ogmios::FileManager->new($self->getConfig->getSupplementaryMagicFile); | ||
| 147 | |||
| 148 | foreach $file (@$files) { | ||
| 149 | if ( ! -e $file ) { | ||
| 150 | warn "$file does not exist; File not loaded\n"; | ||
| 151 | } else { | ||
| 152 | # Type/format of the document | ||
| 153 | if (($self->getConfig->isInputInALVISFormat) || ($Filemanager->getType($file) eq "text/xml ns=http://alvis.info/enriched/")) { | ||
| 154 | warn "Document $file is in Alvis XML format\n"; | ||
| 155 | # Alvis XML format | ||
| 156 | my $documentCollection = Lingua::Ogmios::DocumentCollection->new($file, "file", $self->getConfig); | ||
| 157 | |||
| 158 | $self->addDocumentCollection($documentCollection); | ||
| 159 | } | ||
| 160 | |||
| 161 | # Convert into ALVIS XML | ||
| 162 | } | ||
| 163 | |||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | sub tokenisation { | ||
| 168 | my ($self) = @_; | ||
| 169 | |||
| 170 | my $documentCollection; | ||
| 171 | |||
| 172 | foreach $documentCollection (@{$self->getDocumentCollection}) { | ||
| 173 | $documentCollection->tokenisation; | ||
| 174 | } | ||
| 175 | return(0); | ||
| 176 | } | ||
| 177 | |||
| 178 | sub linguisticProcessing { | ||
| 179 | my ($self) = @_; | ||
| 180 | |||
| 181 | my $documentCollection; | ||
| 182 | my $processing; | ||
| 183 | my $wrapper; | ||
| 184 | |||
| 185 | |||
| 186 | # warn "Processing with the wrapper: " . $self->getConfig->getNLPToolFromIndex($self->getConfig->processingTool($processing))->wrapper . "\n"; | ||
| 187 | |||
| 188 | # } | ||
| 189 | |||
| 190 | warn "\n"; | ||
| 191 | |||
| 192 | my @docset = values(%{$self->getDocumentCollection->[0]->getDocuments}); | ||
| 193 | |||
| 194 | my $tool_config; | ||
| 195 | |||
| 196 | my $NLPTool; | ||
| 197 | my $position; | ||
| 198 | |||
| 199 | # TODO Externalize the setting of the NLP wrappers; | ||
| 200 | |||
| 201 | # foreach $wrapper ($self->getConfig->getOrderedWrappers) { | ||
| 202 | |||
| 203 | warn "number of process: " . $self->getConfig->getProcessingSetSize . "\n"; | ||
| 204 | |||
| 205 | if ($self->getConfig->getProcessingSetSize > 0) { | ||
| 206 | |||
| 207 | $position = 0; | ||
| 208 | foreach $processing ($self->getConfig->getOrderedProcessing) { | ||
| 209 | $position++; | ||
| 210 | $tool_config = $self->getConfig->getNLPToolFromIndex($self->getConfig->processingTool($processing)); | ||
| 211 | $wrapper = $tool_config->wrapper; | ||
| 212 | |||
| 213 | warn "[LOG] Processing with the wrapper: " . $wrapper . " ($processing) " . $self->getConfig->processingTool($processing) . "\n"; | ||
| 214 | |||
| 215 | eval "require $wrapper"; | ||
| 216 | if ($@) { | ||
| 217 | warn $@ . "\n"; | ||
| 218 | die "Problem while loading wrapper $wrapper - Abort\n\n"; | ||
| 219 | } else { | ||
| 220 | if ($position == $self->getConfig->getProcessingSetSize) { | ||
| 221 | $position = 'last'; | ||
| 222 | } | ||
| 223 | warn "[LOG] position: $position (" . $self->getConfig->getProcessingSetSize . ")\n"; | ||
| 224 | $NLPTool = $wrapper->new($tool_config, $self->getConfig->getOgmiosTMPFILE, $self->getConfig->getOgmiosLOGFILE, $position, $self->getConfig->xmloutput_noStdXmlOutput, $self->getConfig->OgmiosOutStream); | ||
| 225 | $NLPTool->run(\@docset); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | # foreach $documentCollection (@{$self->getDocumentCollection}) { | ||
| 231 | # $documentCollection->printDocumentList; | ||
| 232 | # } | ||
| 233 | |||
| 234 | # docColl | ||
| 235 | # subdocColl | ||
| 236 | # docRec | ||
| 237 | return(0); | ||
| 238 | } | ||
| 239 | |||
| 240 | sub XMLout { | ||
| 241 | my ($self) = @_; | ||
| 242 | |||
| 243 | my $documentCollection; | ||
| 244 | my $str; | ||
| 245 | |||
| 246 | $str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | ||
| 247 | |||
| 248 | foreach $documentCollection (@{$self->getDocumentCollection}) { | ||
| 249 | $str .= $documentCollection->XMLout; | ||
| 250 | } | ||
| 251 | return($str); | ||
| 252 | |||
| 253 | } | ||
| 254 | |||
| 255 | |||
| 256 | sub getTimer { | ||
| 257 | my ($self) = @_; | ||
| 258 | |||
| 259 | return($self->{'timer'}); | ||
| 260 | } | ||
| 261 | |||
| 262 | |||
| 263 | 1; | ||
| 264 | |||
| 265 | __END__ | ||