blib/lib/Lingua/Ogmios/NLPWrappers/NegEx.pm untested

filter: Statementstmt 0.0% 0 / 81 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 111 CC 7 SCAR 21.3
CC
7
Cov
0%
new
12.0
_processNegEx
12.0
run
12.0
CRAP 8.4
1 package Lingua::Ogmios::NLPWrappers::NegEx;
2  
3  
4 our $VERSION='0.1';
5  
6 # use Lingua::NegEx qw( negation_scope );
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, $out_stream) = @_;
16  
17 my $lang;
18 my $lang2;
19  
20 warn "[LOG] Creating a wrapper of the NegEx\n";
21  
22 my $NegEx = $class->SUPER::new($config, $tmpfile_prefix, $logfile, $position, $no_standard_output, $out_stream);
23  
24 if (defined $NegEx->_config->configuration->{'CONFIG'}) {
25 foreach $lang (keys %{$NegEx->_config->configuration->{'CONFIG'}}) {
26 if ($lang =~ /language=([\w]+)/io) {
27 $lang2 = $1;
28  
29 # $NegEx->_setOption($lang2, "MODE", "mode", "eval");
30 # if (defined $NegEx->_config->configuration->{'CONFIG'}->{$lang}->{"OPTION"}) {
31 # $NegEx->{'parameter'}->{$lang2} = $NegEx->_config->configuration->{'CONFIG'}->{$lang}->{"OPTION"};
32 # } else {
33 # $NegEx->{'parameter'}->{"FR"} = "?.!";
34 # $NegEx->{'parameter'}->{"EN"} = "?.!";
35 # warn "*** OPTION is not set ***\n";
36 # }
37 # } else {
38 # $NegEx->{'parameter'}->{"FR"} = "?.!";
39 # $NegEx->{'parameter'}->{"EN"} = "?.!";
40 # warn "*** OPTION is not set ***\n";
41 }
42 }
43 # } else {
44 # $NegEx->{'parameter'}->{"FR"} = "?.!";
45 # $NegEx->{'parameter'}->{"EN"} = "?.!";
46 }
47  
48  
49 $NegEx->_input_filename($tmpfile_prefix . ".NegEx.in");
50 $NegEx->_output_filename($tmpfile_prefix . ".NegEx.out");
51  
52 return($NegEx);
53  
54 }
55  
56 sub _processNegEx {
57 my ($self, $lang) = @_;
58  
59 warn "[LOG] NegEx\n";
60  
61 $lang = $self->_documentSet->[0]->getAnnotations->getLanguage;
62  
63 my $document;
64 my $sentence;
65 my $scope;
66 my @terms;
67 my $words;
68 my $i;
69  
70 my $perlModule = $self->_config->commands($lang)->{PerlModule};
71  
72 eval "require $perlModule"; # qw( negation_scope )";
73 # eval "require Lingua::NegEx qw( negation_scope )";
74 if ($@) {
75 warn $@ . "\n";
76 die "Problem while loading perlModule $perlModule - Abort\n\n";
77 } else {
78 $perlModule->import(qw( negation_scope ));
79 foreach $document (@{$self->_documentSet}) {
80 foreach $sentence (@{$document->getAnnotations->getSentenceLevel->getElements}) {
81 $scope = negation_scope($sentence->getForm);
82 # print STDERR $sentence->getForm . "\n";
83 if ($scope != 0) {
84 # print STDERR join(', ', @$scope) . "\n";
85 $words = $sentence->getWordsFromSentence($document);
86 # print STDERR "\t";
87 @terms = $document->getAnnotations->getSemanticUnitLevel->getElementsBetweenStartEndTokens($words->[$scope->[0]]->start_token, $words->[$scope->[1]]->end_token);
88  
89 for($i=0;$i < scalar(@terms);$i++) {
90 $terms[$i]->negation(1);
91 }
92 # print STDERR "\n";
93 }
94 # # $corpus_in .= $sentence->getForm;
95 # # $corpus_in .= "\n";
96 }
97 }
98 }
99  
100 warn "[LOG]\n";
101 return($perlModule);
102 }
103  
104 sub _inputNegEx {
105 my ($self) = @_;
106  
107 warn "[LOG] making NegEx input\n";
108
109 warn "[LOG] done\n";
110 }
111  
112  
113 sub _outputNegEx {
114 my ($self) = @_;
115  
116 warn "[LOG] . Parsing " . $self->_output_filename . "\n";
117  
118 warn "[LOG] done\n";
119 }
120  
121 sub run {
122 my ($self, $documentSet) = @_;
123  
124 # Set variables according the the configuration
125  
126 $self->_documentSet($documentSet);
127  
128 warn "[LOG] " . $self->_config->comments . " ... \n";
129  
130 $self->_inputNegEx;
131  
132 my $command_line = $self->_processNegEx;
133  
134 # if ($self->_position eq "last") {
135 # # TODO
136 if (($self->_position eq "last") && ($self->_no_standard_output)) {
137 warn "print no standard output\n";
138 if ($self->_no_standard_output eq "QALD") {
139 warn "print Tagged Sentence output (QALD)\n";
140 warn $self->_out_stream . "\n";
141 $self->_QALDoutput;
142 }
143 } else {
144 $self->_outputNegEx;
145 }
146 # $self->_outputParsing;
147  
148  
149 # Put log information
150  
151 my $information = { 'software_name' => $self->_config->name,
152 'comments' => $self->_config->comments,
153 'command_line' => $command_line,
154 'list_modified_level' => [''],
155 };
156 $self->_log($information);
157  
158  
159 $self->getTimer->_printTimes;
160 $self->getTimer->_printTimesInLine($self->_config->name);
161  
162 # die "You call the 'rum' method of the wrapper class base\n
163 # You should define a 'run' method for your wrapper\n";
164 warn "[LOG] done\n";
165 }
166  
167 1;
168  
169 __END__