« blib/lib/Lingua/Ogmios/Annotations/DomainSpecificRelation.pm
↑ Summary
blib/lib/Lingua/Ogmios/Annotations/Element.pm »
| 1 | package Lingua::Ogmios::NLPWrappers::Flemm; | ||
| 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 | warn "[LOG] Creating a wrapper of the Flemm\n"; | ||
| 18 | |||
| 19 | |||
| 20 | my $Flemm = $class->SUPER::new($config, $tmpfile_prefix, $logfile, $position, $no_standard_output); | ||
| 21 | |||
| 22 | $Flemm->_input_filename($tmpfile_prefix . ".Flemm.in"); | ||
| 23 | $Flemm->_output_filename($tmpfile_prefix . ".Flemm.out"); | ||
| 24 | |||
| 25 | return($Flemm); | ||
| 26 | |||
| 27 | } | ||
| 28 | |||
| 29 | sub _processFlemm { | ||
| 30 | my ($self, $lang) = @_; | ||
| 31 | |||
| 32 | warn "[LOG] Flemm\n"; | ||
| 33 | |||
| 34 | $lang = $self->_documentSet->[0]->getAnnotations->getLanguage; | ||
| 35 | |||
| 36 | my $perlModule = $self->_config->commands($lang)->{PerlModule}; | ||
| 37 | |||
| 38 | eval "require $perlModule"; | ||
| 39 | |||
| 40 | return($self->_exec_command($self->_defineCommandLine($self->_config->commands($lang)->{FLEMM_CMD} . " " . $self->_config->commands($lang)->{FLEMM_IN_PARAMETERS} . " " . $self->_input_filename . " " . $self->_config->commands($lang)->{FLEMM_OUT_PARAMETERS} . " " . $self->_output_filename))); | ||
| 41 | |||
| 42 | warn "[LOG]\n"; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub _inputFlemm { | ||
| 46 | my ($self) = @_; | ||
| 47 | |||
| 48 | warn "[LOG] making Flemm input\n"; | ||
| 49 | |||
| 50 | $self->_printTreeTaggerFormatOutput($self->_input_filename, 'LATIN1'); | ||
| 51 | |||
| 52 | warn "[LOG] done\n"; | ||
| 53 | } | ||
| 54 | |||
| 55 | |||
| 56 | sub _outputFlemm { | ||
| 57 | my ($self) = @_; | ||
| 58 | |||
| 59 | |||
| 60 | warn "[LOG] . Parsing " . $self->_output_filename . "\n"; | ||
| 61 | |||
| 62 | $self->_parseTreeTaggerFormatOutput($self->_output_filename, 1); | ||
| 63 | |||
| 64 | warn "[LOG] done\n"; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub run { | ||
| 68 | my ($self, $documentSet) = @_; | ||
| 69 | |||
| 70 | # Set variables according the the configuration | ||
| 71 | |||
| 72 | $self->_documentSet($documentSet); | ||
| 73 | |||
| 74 | warn "[LOG] " . $self->_config->comments . " ... \n"; | ||
| 75 | |||
| 76 | $self->_inputFlemm; | ||
| 77 | |||
| 78 | my $command_line = $self->_processFlemm; | ||
| 79 | |||
| 80 | # if ($self->_position eq "last") { | ||
| 81 | # # TODO | ||
| 82 | |||
| 83 | $self->_outputFlemm; | ||
| 84 | # Put log information | ||
| 85 | |||
| 86 | my $information = { 'software_name' => $self->_config->name, | ||
| 87 | 'comments' => $self->_config->comments, | ||
| 88 | 'command_line' => $command_line, | ||
| 89 | 'list_modified_level' => ['morphosyntactic_features_level', 'lemma_level'], | ||
| 90 | }; | ||
| 91 | $self->_log($information); | ||
| 92 | |||
| 93 | |||
| 94 | if (($self->_position eq "last") && ($self->_no_standard_output)) { | ||
| 95 | if ($self->_no_standard_output eq "IFPOSLM") { | ||
| 96 | $self->_printTreeTaggerFormatOutput('stdout', 'LATIN1',0); | ||
| 97 | warn "print no standard output\n"; | ||
| 98 | # my $document; | ||
| 99 | # my $word; | ||
| 100 | # my $MS_features; | ||
| 101 | # foreach $document (@{$documentSet}) { | ||
| 102 | # foreach $word (@{$document->getAnnotations->getWordLevel->getElements}) { | ||
| 103 | # print $word->getForm . "\t"; | ||
| 104 | # print $document->getAnnotations->getLemmaLevel->getElementFromIndex("refid_word", $word->getId)->[0]->canonical_form; | ||
| 105 | # if (($self->_no_standard_output == 2) || ($self->_no_standard_output == 3)) { | ||
| 106 | # print "\t" . $document->getAnnotations->getMorphosyntacticFeaturesLevel->getElementFromIndex("refid_word", $word->getId)->[0]->syntactic_category; | ||
| 107 | # } | ||
| 108 | # print "\n"; | ||
| 109 | # } | ||
| 110 | # } | ||
| 111 | } | ||
| 112 | if ($self->_no_standard_output eq "IFPOSLMLINE") { | ||
| 113 | my $document; | ||
| 114 | my $word; | ||
| 115 | my $MS_features; | ||
| 116 | my $lemma; | ||
| 117 | my $sentence; | ||
| 118 | my $token_start; | ||
| 119 | my $token_end; | ||
| 120 | my $token; | ||
| 121 | |||
| 122 | my @word_set; | ||
| 123 | my @MS_features_set; | ||
| 124 | my @lemma_set; | ||
| 125 | |||
| 126 | foreach $document (@{$documentSet}) { | ||
| 127 | foreach $sentence (@{$document->getAnnotations->getSentenceLevel->getElements}) { | ||
| 128 | @word_set = (); | ||
| 129 | @MS_features_set = (); | ||
| 130 | @lemma_set = (); | ||
| 131 | $token_start = $sentence->refid_start_token; | ||
| 132 | $token = $token_start; | ||
| 133 | $token_end = $sentence->refid_end_token; | ||
| 134 | do { | ||
| 135 | if ($document->getAnnotations->getWordLevel->existsElementFromIndex("list_refid_token", $token->getId)) { | ||
| 136 | $word = $document->getAnnotations->getWordLevel->getElementFromIndex("list_refid_token", $token->getId)->[0]; | ||
| 137 | $lemma = $document->getAnnotations->getLemmaLevel->getElementFromIndex("refid_word", $word->getId)->[0]; | ||
| 138 | $MS_features = $document->getAnnotations->getMorphosyntacticFeaturesLevel->getElementFromIndex("refid_word", $word->getId)->[0]; | ||
| 139 | push @word_set, $word->getForm; | ||
| 140 | push @MS_features_set, $MS_features->syntactic_category; | ||
| 141 | push @lemma_set, $lemma->canonical_form; | ||
| 142 | $token = $word->end_token; | ||
| 143 | } | ||
| 144 | if (!$token->equals($token_end)) { | ||
| 145 | $token = $token->next; | ||
| 146 | } | ||
| 147 | } while (!$token->equals($token_end)); | ||
| 148 | # foreach $word (@{$document->getAnnotations->getWordLevel->getElements}) { | ||
| 149 | # print $word->getForm . "\t"; | ||
| 150 | # print $document->getAnnotations->getLemmaLevel->getElementFromIndex("refid_word", $word->getId)->[0]->canonical_form; | ||
| 151 | # if (($self->_no_standard_output == 2) || ($self->_no_standard_output == 3) || ($self->_no_standard_output eq "IFLMPOS")) { | ||
| 152 | # print "\t" . $document->getAnnotations->getMorphosyntacticFeaturesLevel->getElementFromIndex("refid_word", $word->getId)->[0]->syntactic_category; | ||
| 153 | # } | ||
| 154 | print join(" ", @word_set); | ||
| 155 | print "\t"; | ||
| 156 | print join(" ", @MS_features_set); | ||
| 157 | print "\t"; | ||
| 158 | print join(" ", @lemma_set); | ||
| 159 | print "\n"; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | } | ||
| 164 | # } else { | ||
| 165 | } | ||
| 166 | # $self->_outputParsing; | ||
| 167 | |||
| 168 | |||
| 169 | # die "You call the 'rum' method of the wrapper class base\n | ||
| 170 | # You should define a 'run' method for your wrapper\n"; | ||
| 171 | warn "[LOG] done\n"; | ||
| 172 | } | ||
| 173 | |||
| 174 | |||
| 175 | 1; | ||
| 176 | |||
| 177 | |||
| 178 | __END__ |