« blib/lib/Lingua/Ogmios/Annotations/SemanticFeatures.pm
↑ Summary
blib/lib/Lingua/Ogmios/Annotations/Word.pm »
| 1 | package Lingua::Ogmios::NLPWrappers::MarkerDetection; | ||
| 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 MarkerDetection\n"; | ||
| 18 | |||
| 19 | |||
| 20 | my $MarkerDetection = $class->SUPER::new($config, $tmpfile_prefix, $logfile, $position, $no_standard_output); | ||
| 21 | |||
| 22 | $MarkerDetection->_input_filename($tmpfile_prefix . ".MarkerDetection.in"); | ||
| 23 | $MarkerDetection->_output_filename($tmpfile_prefix . ".MarkerDetection.out"); | ||
| 24 | |||
| 25 | return($MarkerDetection); | ||
| 26 | |||
| 27 | } | ||
| 28 | |||
| 29 | sub _processMarkerDetection { | ||
| 30 | my ($self, $lang) = @_; | ||
| 31 | |||
| 32 | warn "[LOG] POS tagger\n"; | ||
| 33 | |||
| 34 | $lang = $self->_documentSet->[0]->getAnnotations->getLanguage; | ||
| 35 | |||
| 36 | return($self->_exec_command($self->_defineCommandLine($self->_config->commands($lang)->{MarkerDetection_CMD} . " < " . $self->_input_filename . ">" . $self->_output_filename))); | ||
| 37 | |||
| 38 | warn "[LOG]\n"; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub _inputMarkerDetection { | ||
| 42 | my ($self) = @_; | ||
| 43 | |||
| 44 | warn "[LOG] making MarkerDetection input\n"; | ||
| 45 | |||
| 46 | warn "[LOG] done\n"; | ||
| 47 | } | ||
| 48 | |||
| 49 | |||
| 50 | sub _outputMarkerDetection { | ||
| 51 | my ($self) = @_; | ||
| 52 | |||
| 53 | warn "[LOG] . Parsing " . $self->_output_filename . "\n"; | ||
| 54 | |||
| 55 | warn "[LOG] done\n"; | ||
| 56 | } | ||
| 57 | |||
| 58 | sub run { | ||
| 59 | my ($self, $documentSet) = @_; | ||
| 60 | |||
| 61 | # Set variables according the the configuration | ||
| 62 | |||
| 63 | $self->_documentSet($documentSet); | ||
| 64 | |||
| 65 | warn "[LOG] " . $self->_config->comments . " ... \n"; | ||
| 66 | |||
| 67 | $self->_inputMarkerDetection; | ||
| 68 | |||
| 69 | my $command_line = $self->_processMarkerDetection; | ||
| 70 | |||
| 71 | # if ($self->_position eq "last") { | ||
| 72 | # # TODO | ||
| 73 | if (($self->_position eq "last") && ($self->_no_standard_output)) { | ||
| 74 | warn "print no standard output\n"; | ||
| 75 | } else { | ||
| 76 | $self->_outputMarkerDetection; | ||
| 77 | } | ||
| 78 | # $self->_outputParsing; | ||
| 79 | |||
| 80 | |||
| 81 | # Put log information | ||
| 82 | |||
| 83 | my $information = { 'software_name' => $self->_config->name, | ||
| 84 | 'comments' => $self->_config->comments, | ||
| 85 | 'command_line' => $command_line, | ||
| 86 | }; | ||
| 87 | $self->_log($information); | ||
| 88 | |||
| 89 | |||
| 90 | # die "You call the 'rum' method of the wrapper class base\n | ||
| 91 | # You should define a 'run' method for your wrapper\n"; | ||
| 92 | warn "[LOG] done\n"; | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | sub checkMarkerFromTagSuffix { | ||
| 97 | my ($self, $term, $tagSuffix, $document, $windowLimitFrom, $windowLimitTo, $wordLimit) = @_; | ||
| 98 | |||
| 99 | return($self->checkMarkerInContext($term, $tagSuffix, $document, $windowLimitFrom, $windowLimitTo, $wordLimit)); | ||
| 100 | } | ||
| 101 | |||
| 102 | sub checkMarkerInContext { | ||
| 103 | |||
| 104 | my ($self, $term, $tagSuffix, $document, $windowLimitFrom, $windowLimitTo, $wordLimit) = @_; | ||
| 105 | |||
| 106 | my $token; | ||
| 107 | my $tmpTerm; | ||
| 108 | |||
| 109 | # my @windowLimits = $self->getWindowLimits($term, $lineIdx, $tmpTermIdx, $document); | ||
| 110 | |||
| 111 | my %words; | ||
| 112 | |||
| 113 | $token = $term->start_token; | ||
| 114 | |||
| 115 | my $markerInContext = 0; | ||
| 116 | |||
| 117 | # warn "Search $tagSuffix around " . $token->getContent . "\n"; | ||
| 118 | # check after\n"; | ||
| 119 | |||
| 120 | while(($token->getFrom <= $windowLimitTo->getTo) && (scalar(keys %words) <= $wordLimit)) { | ||
| 121 | my @words = @{$document->getAnnotations->getWordLevel->getElementByToken($token)}; | ||
| 122 | if (scalar(@words) > 0) { | ||
| 123 | $words{$words[0]->getId}++; | ||
| 124 | } | ||
| 125 | foreach $tmpTerm (@{$document->getAnnotations->getSemanticUnitLevel->getElementByToken($token)}) { | ||
| 126 | # warn "\t" . $tmpTerm->getForm . "\n"; | ||
| 127 | if ($tmpTerm->isTerm) { | ||
| 128 | # warn "\t" . $tmpTerm->getForm . " : " . $tmpTerm->start_token->getFrom . "\n"; | ||
| 129 | my $semf = $document->getAnnotations->getSemanticFeaturesLevel->getElementFromIndex("refid_semantic_unit", $tmpTerm->getId)->[0]; | ||
| 130 | # warn "$semf\n"; | ||
| 131 | if ((defined $semf) && ($semf->first_node_first_semantic_category eq "post-$tagSuffix")) { | ||
| 132 | warn "find post-$tagSuffix (a) : " . $tmpTerm->getForm . "(" . $tmpTerm->start_token->getFrom . ")\n"; | ||
| 133 | $markerInContext = 1; | ||
| 134 | # push @reasons, $tmpTerm; | ||
| 135 | $token = $tmpTerm->end_token; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | } | ||
| 139 | # } | ||
| 140 | $token = $token->next; | ||
| 141 | } | ||
| 142 | |||
| 143 | $token = $term->start_token; | ||
| 144 | %words = (); | ||
| 145 | while(($token->getTo >= $windowLimitFrom->getFrom) && (scalar(keys %words) <= $wordLimit)) { | ||
| 146 | # warn "token: " . $token->getContent . "(" . $token->getTo . ")\n"; | ||
| 147 | my @words = @{$document->getAnnotations->getWordLevel->getElementByToken($token)}; | ||
| 148 | # warn "words: " . scalar(@words) . "\n"; | ||
| 149 | if (scalar(@words) > 0) { | ||
| 150 | $words{$words[0]->getId}++; | ||
| 151 | } | ||
| 152 | foreach $tmpTerm (@{$document->getAnnotations->getSemanticUnitLevel->getElementByToken($token)}) { | ||
| 153 | if ($tmpTerm->isTerm) { | ||
| 154 | # warn "\t" . $tmpTerm->getForm . " : " . $tmpTerm->start_token->getFrom . "\n"; | ||
| 155 | my $semf = $document->getAnnotations->getSemanticFeaturesLevel->getElementFromIndex("refid_semantic_unit", $tmpTerm->getId)->[0]; | ||
| 156 | # # warn "$semf\n"; | ||
| 157 | if ((defined $semf) && ($semf->first_node_first_semantic_category eq "pre-$tagSuffix")) { | ||
| 158 | warn "find pre-$tagSuffix (b) : " . $tmpTerm->getForm . "(" . $tmpTerm->start_token->getFrom . ")\n"; | ||
| 159 | # push @reasons, $tmpTerm; | ||
| 160 | $markerInContext = 1; | ||
| 161 | $token = $tmpTerm->start_token; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | } | ||
| 165 | $token = $token->previous; | ||
| 166 | } ; | ||
| 167 | |||
| 168 | return($markerInContext) | ||
| 169 | } | ||
| 170 | |||
| 171 | |||
| 172 | 1; | ||
| 173 | |||
| 174 | |||
| 175 | __END__ |