« blib/lib/Lingua/Ogmios/Annotations/Lemma.pm
↑ Summary
blib/lib/Lingua/Ogmios/Annotations/Stem.pm »
| 1 | package Lingua::Ogmios::NLPWrappers::BasicWordSegmentizer; | ||
| 2 | |||
| 3 | |||
| 4 | our $VERSION='0.1'; | ||
| 5 | |||
| 6 | |||
| 7 | use Lingua::Ogmios::NLPWrappers::Wrapper; | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use warnings; | ||
| 11 | |||
| 12 | our @ISA = qw(Lingua::Ogmios::NLPWrappers::Wrapper); | ||
| 13 | |||
| 14 | sub new { | ||
| 15 | my ($class, $config, $tmpfile_prefix, $logfile, $position, $no_standard_output) = @_; | ||
| 16 | |||
| 17 | my $lang; | ||
| 18 | my $lang2; | ||
| 19 | |||
| 20 | warn "[LOG] Creating a wrapper of the BasicWordSegmentizer\n"; | ||
| 21 | |||
| 22 | my $BasicWordSegmentizer = $class->SUPER::new($config, $tmpfile_prefix, $logfile, $position, $no_standard_output); | ||
| 23 | |||
| 24 | if (defined $BasicWordSegmentizer->_config->configuration->{'CONFIG'}) { | ||
| 25 | foreach $lang (keys %{$BasicWordSegmentizer->_config->configuration->{'CONFIG'}}) { | ||
| 26 | if ($lang =~ /language=([\w]+)/io) { | ||
| 27 | $lang2 = $1; | ||
| 28 | |||
| 29 | if (defined $BasicWordSegmentizer->_config->configuration->{'CONFIG'}->{$lang}->{"OPTION"}) { | ||
| 30 | $BasicWordSegmentizer->{'parameter'}->{$lang2} = $BasicWordSegmentizer->_config->configuration->{'CONFIG'}->{$lang}->{"OPTION"}; | ||
| 31 | } else { | ||
| 32 | $BasicWordSegmentizer->{'parameter'}->{"FR"} = "?.!"; | ||
| 33 | $BasicWordSegmentizer->{'parameter'}->{"EN"} = "?.!"; | ||
| 34 | warn "*** OPTION is not set ***\n"; | ||
| 35 | } | ||
| 36 | } else { | ||
| 37 | $BasicWordSegmentizer->{'parameter'}->{"FR"} = "?.!"; | ||
| 38 | $BasicWordSegmentizer->{'parameter'}->{"EN"} = "?.!"; | ||
| 39 | warn "*** OPTION is not set ***\n"; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } else { | ||
| 43 | $BasicWordSegmentizer->{'parameter'}->{"FR"} = "?.!"; | ||
| 44 | $BasicWordSegmentizer->{'parameter'}->{"EN"} = "?.!"; | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | $BasicWordSegmentizer->_input_filename($tmpfile_prefix . ".BasicWordSegmentizer.in"); | ||
| 49 | $BasicWordSegmentizer->_output_filename($tmpfile_prefix . ".BasicWordSegmentizer.out"); | ||
| 50 | |||
| 51 | return($BasicWordSegmentizer); | ||
| 52 | |||
| 53 | } | ||
| 54 | |||
| 55 | sub _processBasicWordSegmentizer { | ||
| 56 | my ($self, $lang) = @_; | ||
| 57 | |||
| 58 | warn "[LOG] BasicWordSegmentizer\n"; | ||
| 59 | |||
| 60 | $lang = $self->_documentSet->[0]->getAnnotations->getLanguage; | ||
| 61 | |||
| 62 | return($self->_exec_command($self->_defineCommandLine($self->_config->commands($lang)->{BasicWordSegmentizer_CMD} . " < " . $self->_input_filename . ">" . $self->_output_filename))); | ||
| 63 | |||
| 64 | warn "[LOG]\n"; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub _inputBasicWordSegmentizer { | ||
| 68 | my ($self) = @_; | ||
| 69 | |||
| 70 | warn "[LOG] making BasicWordSegmentizer input\n"; | ||
| 71 | |||
| 72 | warn "[LOG] done\n"; | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | sub _outputBasicWordSegmentizer { | ||
| 77 | my ($self) = @_; | ||
| 78 | |||
| 79 | my $token; | ||
| 80 | my $section; | ||
| 81 | my @corpus_in; | ||
| 82 | my $document; | ||
| 83 | |||
| 84 | my $word_form = ""; | ||
| 85 | my @Word2tokens = (); | ||
| 86 | my $IsNE = 0; | ||
| 87 | my $isInNE; | ||
| 88 | my $word; | ||
| 89 | |||
| 90 | warn "[LOG] . Parsing " . $self->_output_filename . "\n"; | ||
| 91 | |||
| 92 | foreach $document (@{$self->_documentSet}) { | ||
| 93 | foreach $token (@{$document->getAnnotations->getTokenLevel->getElements}) { | ||
| 94 | # warn "token: " . $token->getContent . "\n"; | ||
| 95 | if ((($token->isSep) || ($document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $token->getId))) && (!$isInNE)) { | ||
| 96 | if ((!$token->isSep) && (!$token->isSymb)) { | ||
| 97 | # warn "+\n"; | ||
| 98 | push @Word2tokens, $token; | ||
| 99 | $word_form .= $token->getContent; | ||
| 100 | $isInNE = $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId); | ||
| 101 | $IsNE ||= $isInNE; | ||
| 102 | } | ||
| 103 | if (scalar(@Word2tokens) > 0) { | ||
| 104 | # warn "add $word_form;\n"; | ||
| 105 | # warn " " . scalar(@Word2tokens) . "\n"; | ||
| 106 | $word = Lingua::Ogmios::Annotations::Word->new( | ||
| 107 | {'form' => $word_form, | ||
| 108 | 'list_refid_token' => \@Word2tokens, | ||
| 109 | 'isNE' => $IsNE, | ||
| 110 | }); | ||
| 111 | $document->getAnnotations->addWord($word); | ||
| 112 | $word_form = ""; | ||
| 113 | @Word2tokens = (); | ||
| 114 | $IsNE = 0; | ||
| 115 | $isInNE = 0; | ||
| 116 | } | ||
| 117 | } else { | ||
| 118 | $word_form .= $token->getContent; | ||
| 119 | push @Word2tokens, $token; | ||
| 120 | $isInNE = $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId); | ||
| 121 | $IsNE ||= $isInNE; | ||
| 122 | } | ||
| 123 | |||
| 124 | # # warn "$token: " . $token->getContent . ";\n"; | ||
| 125 | # $corpus_in .= $token->getContent; | ||
| 126 | # if ($document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $token->getId)) { | ||
| 127 | # $corpus_in .= "\n"; | ||
| 128 | } | ||
| 129 | } | ||
| 130 | warn "[LOG] done\n"; | ||
| 131 | } | ||
| 132 | |||
| 133 | sub run { | ||
| 134 | my ($self, $documentSet) = @_; | ||
| 135 | |||
| 136 | # Set variables according the the configuration | ||
| 137 | |||
| 138 | $self->_documentSet($documentSet); | ||
| 139 | |||
| 140 | warn "[LOG] " . $self->_config->comments . " ... \n"; | ||
| 141 | |||
| 142 | # $self->_inputBasicWordSegmentizer; | ||
| 143 | |||
| 144 | my $command_line = ""; | ||
| 145 | |||
| 146 | # if ($self->_position eq "last") { | ||
| 147 | # # TODO | ||
| 148 | if (($self->_position eq "last") && ($self->_no_standard_output)) { | ||
| 149 | warn "print no standard output\n"; | ||
| 150 | } else { | ||
| 151 | $self->_outputBasicWordSegmentizer; | ||
| 152 | } | ||
| 153 | # $self->_outputParsing; | ||
| 154 | |||
| 155 | |||
| 156 | # Put log information | ||
| 157 | |||
| 158 | my $information = { 'software_name' => $self->_config->name, | ||
| 159 | 'comments' => $self->_config->comments, | ||
| 160 | 'command_line' => $command_line, | ||
| 161 | 'list_modified_level' => [''], | ||
| 162 | }; | ||
| 163 | $self->_log($information); | ||
| 164 | |||
| 165 | |||
| 166 | # die "You call the 'rum' method of the wrapper class base\n | ||
| 167 | # You should define a 'run' method for your wrapper\n"; | ||
| 168 | warn "[LOG] done\n"; | ||
| 169 | } | ||
| 170 | |||
| 171 | |||
| 172 | 1; | ||
| 173 | |||
| 174 | |||
| 175 | __END__ |