lib/Treex/Core/TredView/Vallex.pm

filter: Statementstmt 10.0% 13 / 130 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 17.6% 3 / 17 Podpod 100% 2 / 2 totaltotal 8.3% 18 / 216 CC 31 SCAR 32.9
CC
31
Cov
7%
_OpenValFrameList_Cs
56.0
_assigned_frame_pos_of
42.0
_OpenValFrameList_En
42.0
CRAP 26.9
« lib/Treex/Block/Util/DefinedAttr.pm ↑ Summary lib/Treex/Core/Node/Ordered.pm »
1 package Treex::Core::TredView::Vallex;
2 {
3 2 $Treex::Core::TredView::Vallex::VERSION = '0.08633_1';
4 }
5  
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Treex::Core::TredView::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Treex::Core::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 has '_treex_doc' => (
11 is => 'ro',
12 isa => 'Treex::Core::Document',
13 weak_ref => 1,
14 required => 1
15 );
16  
17 sub _extension_missing {
18 0 ▶ my ( $self, $ext ) = @_;
Subroutine _extension_missing: not called CC=3 SCAR=24.8
19  
20 0 my $name = '';
21 0 ▶ $name = 'Prague English Treebank Annotation' if $ext eq 'pedt';
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "pedt" 0 0 0
22 0 ▶ $name = 'PDT-ValLex Editor' if $ext eq 'pdt_vallex';
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "pdt_vallex" 0 0 0
23  
24 0 my $message = "This function requires additional extension that is missing.\n";
25 0 $message .= "Please install extension '$name'.";
26 0 TredMacro::ToplevelFrame->messageBox( -type => 'ok', -message => $message );
27 0 return;
28 }
29  
30 sub _find_vallex {
31 0 ▶ my ( $self, $node ) = @_;
Subroutine _find_vallex: not called CC=1 SCAR=6.9
32  
33 0 my $ref = $node->attr('val_frame.rf');
34 0 $ref =~ s/#.*//;
35  
36 0 my $file = $self->_treex_doc->metaData('references')->{$ref};
37 0 $file = TredMacro::ResolvePath( TredMacro::FileName(), $file, 1 );
38 0 return $file;
39 }
40  
41 sub OpenValLexicon
42 {
43 0 ▶ my $self = shift;
Subroutine OpenValLexicon: not called CC=4 SCAR=30.0
Pod documented
44 0 my $node = Treex::Core::TredView::Common::cur_node();
45 0 ▶ return unless $node->attr('val_frame.rf');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->attr("val_frame.rf") 0 0 0
46  
47 0 ▶ if ( $node->language eq 'cs' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->language eq "cs") 0 0 0
48 0 $self->_OpenValLexicon_Cs($node);
49 }
50 0 ▶ if ( $node->language eq 'en' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->language eq "en") 0 0 0
51 0 $self->_OpenValLexicon_En($node);
52 }
53 0 return;
54 }
55  
56 sub ChooseValFrame
57 {
58 0 ▶ my $self = shift;
Subroutine ChooseValFrame: not called CC=4 SCAR=30.0
Pod documented
59 0 my $node = Treex::Core::TredView::Common::cur_node();
60 0 ▶ return unless $node->attr('val_frame.rf');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->attr("val_frame.rf") 0 0 0
61  
62 0 ▶ if ( $node->language eq 'cs' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->language eq "cs") 0 0 0
63 0 $self->_OpenValFrameList_Cs($node);
64 }
65 0 ▶ if ( $node->language eq 'en' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->language eq "en") 0 0 0
66 0 $self->_OpenValFrameList_En($node);
67 }
68 0 return;
69 }
70  
71 sub _assigned_frame_pos_of {
72 0 ▶ my ( $self, $node ) = @_;
Subroutine _assigned_frame_pos_of: not called CC=6 SCAR=37.4
73 0 ▶ return unless $node;
Branch: 1 branch
BranchTrueFalseTotal
unless $node 0 0 0
74 0 ▶ if ( $node->{'val_frame.rf'} ne q() )
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"val_frame.rf"} ne "") 0 0 0
75 {
76 0 my $vallex_file = FindVallex('cz');
77 0 my $V = ValLex::GUI::Init( { -vallex_file => $vallex_file } );
78 0 ▶ if ($V)
Branch: 1 branch
BranchTrueFalseTotal
if ($V) 0 0 0
79 {
80 0 for my $id ( AltV( $node->{'val_frame.rf'} ) )
81 {
82 0 my $frame = $V->by_id($id);
83 0 ▶ if ($frame)
Branch: 1 branch
BranchTrueFalseTotal
if ($frame) 0 0 0
84 {
85 0 return lc( $V->getPOS( $V->getWordForFrame($frame) ) );
86 }
87 }
88 }
89 }
90 0 return;
91 }
92  
93 sub _OpenValLexicon_Cs {
94 0 ▶ my ( $self, $node ) = @_;
Subroutine _OpenValLexicon_Cs: not called CC=4 SCAR=30.0
95  
96 0 ▶ if ( not defined &ValLex::GUI::OpenEditor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ValLex::GUI::OpenEditor) 0 0 0
97 0 $self->_extension_missing('pdt_vallex');
98 0 return;
99 }
100  
101 0 local $ValLex::GUI::frameid_attr = "val_frame.rf";
102 0 local $ValLex::GUI::lemma_attr = "t_lemma";
103 0 local $ValLex::GUI::framere_attr = undef;
104 0 local $ValLex::GUI::sempos_attr = "gram/sempos";
105 0 my $vallex_file = $self->_find_vallex($node);
106 0 ▶ return unless $vallex_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $vallex_file 0 0 0
107  
108 0 ▶ ValLex::GUI::OpenEditor(
Condition0%0/3
$node->attr('gram/sempos') || $self->_assigned_frame_pos_of($node)
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->attr('gram/sempos') || $self->_assigned_frame_pos_of($node)
$node->attr('gram/sempos') $self->_assigned_frame_pos_of($node)
Truth table0%0/3
A || B
A= $node->attr('gram/sempos')B= $self->_assigned_frame_pos_of($node)
ABresult
1X1
011
000
109 {
110 -vallex_file => $vallex_file,
111 -lemma => $node->attr('t_lemma'),
112 -sempos => $node->attr('gram/sempos') || $self->_assigned_frame_pos_of($node),
113 -frameid => $node->attr('val_frame.rf')
114 }
115 );
116 0 TredMacro::ChangingFile(0);
117 0 return;
118 }
119  
120 sub _OpenValLexicon_En {
121 0 ▶ my ( $self, $node ) = @_;
Subroutine _OpenValLexicon_En: not called CC=4 SCAR=30.0
122  
123 0 ▶ if ( not defined &TrEd::EngValLex::GUI::OpenEditor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &TrEd::EngValLex::GUI::OpenEditor) 0 0 0
124 0 $self->_extension_missing('pedt');
125 0 return;
126 }
127  
128 0 local $TrEd::EngValLex::GUI::frameid_attr = "val_frame.rf";
129 0 local $TrEd::EngValLex::GUI::lemma_attr = "t_lemma";
130 0 local $TrEd::EngValLex::GUI::framere_attr = undef;
131 0 local $TrEd::EngValLex::GUI::sempos_attr = "gram/sempos";
132 0 $TrEd::EngValLex::Editor::reviewer_can_modify = 0;
133 0 $TrEd::EngValLex::Editor::reviewer_can_delete = 0;
134  
135 # Following subroutines return 1 no matter what. We need to change this behaviour
136 0 require TrEd::EngValLex::Data;
137 0 ▶ *TrEd::EngValLex::Data::user_is_annotator = sub { return 0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
138 0 ▶ *TrEd::EngValLex::Data::user_is_reviewer = sub { return 0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
139  
140 0 my $a_node = $self->_treex_doc->get_node_by_id( $node->attr('a/lex.rf') );
141 0 my $vallex_file = $self->_find_vallex($node);
142 0 ▶ return unless $vallex_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $vallex_file 0 0 0
143  
144 0 my $opts = {
145 -vallex_file => $vallex_file,
146 -lemma => $node->attr('t_lemma'),
147 -sempos => $node->attr('gram/sempos'),
148 -frameid => $node->attr('val_frame.rf')
149 };
150 0 ▶ $opts->{-pos} = $a_node->attr('tag') if $a_node->attr('tag');
Branch: 1 branch
BranchTrueFalseTotal
if $a_node->attr("tag") 0 0 0
151 0 TrEd::EngValLex::GUI::OpenEditor($opts);
152 0 TredMacro::ChangingFile(0);
153 0 return;
154 }
155  
156 sub _OpenValFrameList_Cs {
157 0 ▶ my ( $self, $node ) = @_;
Subroutine _OpenValFrameList_Cs: not called CC=7 SCAR=40.3
158  
159 0 ▶ if ( not defined &ValLex::GUI::ChooseFrame ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ValLex::GUI::ChooseFrame) 0 0 0
160 0 $self->_extension_missing('pdt_vallex');
161 0 return;
162 }
163  
164 0 local $ValLex::GUI::frameid_attr = "val_frame.rf";
165 0 local $ValLex::GUI::lemma_attr = "t_lemma";
166 0 local $ValLex::GUI::framere_attr = undef;
167 0 local $ValLex::GUI::sempos_attr = "gram/sempos";
168 0 my $vallex_file = $self->_find_vallex($node);
169 0 ▶ return unless $vallex_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $vallex_file 0 0 0
170  
171 0 ▶ my $sempos = [ $node->attr('gram/sempos') || $self->_assigned_frame_pos_of($node) ];
Condition0%0/3
$node->attr('gram/sempos') || $self->_assigned_frame_pos_of($node)
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->attr('gram/sempos') || $self->_assigned_frame_pos_of($node)
$node->attr('gram/sempos') $self->_assigned_frame_pos_of($node)
Truth table0%0/3
A || B
A= $node->attr('gram/sempos')B= $self->_assigned_frame_pos_of($node)
ABresult
1X1
011
000
172 0 ▶ if ( !$sempos->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sempos->[0]) 0 0 0
173 0 $sempos = ['v'];
174 0 ▶ ListQuery( 'Semantical POS', 'browse', [qw(v n)], $sempos ) or return;
Branch: 1 branch
BranchTrueFalseTotal
ListQuery("Semantical POS", "browse", ["v", "n"], $sempos) or return 0 0 0
175 }
176  
177 ValLex::GUI::ChooseFrame(
178 {
179 0 ▶ -withdraw => 1,
Condition0%0/2
$node->attr('t_lemma') || undef
l!l
00
MC/DC0%0/1
$node->attr('t_lemma') || undef
$node->attr('t_lemma')
Truth table0%0/2
A
A= $node->attr('t_lemma')
Aresult
11
00
180 -vallex_file => $vallex_file,
181 -lemma => $node->attr('t_lemma') || undef,
182 -sempos => $sempos->[0],
183 -lemma_attr => 't_lemma',
184 -sempos_attr => 'gram/sempos',
185 -frameid => $node->attr('val_frame.rf'),
186 -no_assign => 1,
187 -noadd => 1
188 }
189 );
190 0 TredMacro::ChangingFile(0);
191 0 return;
192 }
193  
194 sub _OpenValFrameList_En {
195 0 ▶ my ( $self, $node ) = @_;
Subroutine _OpenValFrameList_En: not called CC=6 SCAR=37.4
196  
197 0 ▶ if ( not defined &TrEd::EngValLex::GUI::ChooseFrame ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &TrEd::EngValLex::GUI::ChooseFrame) 0 0 0
198 0 $self->_extension_missing('pedt');
199 0 return;
200 }
201  
202 0 local $EngValLex::GUI::frameid_attr = "val_frame.rf";
203 0 local $EngValLex::GUI::lemma_attr = "t_lemma";
204 0 local $EngValLex::GUI::framere_attr = undef;
205 0 local $EngValLex::GUI::sempos_attr = "gram/sempos";
206 0 $TrEd::EngValLex::Editor::reviewer_can_modify = 0;
207 0 $TrEd::EngValLex::Editor::reviewer_can_delete = 0;
208  
209 # Following subroutines return 1 no matter what. We need to change this behaviour
210 0 require TrEd::EngValLex::Data;
211 0 ▶ *TrEd::EngValLex::Data::user_is_annotator = sub { return 0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
212 0 ▶ *TrEd::EngValLex::Data::user_is_reviewer = sub { return 0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
213  
214 0 my $a_node = $self->_treex_doc->get_node_by_id( $node->attr('a/lex.rf') );
215 0 my $vallex_file = $self->_find_vallex($node);
216 0 ▶ return unless $vallex_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $vallex_file 0 0 0
217  
218 my $opts = {
219 -withdraw => 1,
220 -vallex_file => $vallex_file,
221 -lemma => $node->{t_lemma} || undef,
222 -sempos => $node->attr('gram/sempos') || undef,
223 -lemma_attr => 't_lemma',
224 -sempos_attr => 'gram/sempos',
225 -frameid => $node->attr('val_frame.rf'),
226 ▶ -assignfunc => sub { }
Subroutine __ANON__: not called CC=1 SCAR=0.0
227 0 ▶ };
Condition0%0/4
$node->{'t_lemma'} || undef
l!l
00
$node->attr('gram/sempos') || undef
l!l
00
MC/DC0%0/1
$node->{'t_lemma'} || undef
$node->{'t_lemma'}
MC/DC0%0/1
$node->attr('gram/sempos') || undef
$node->attr('gram/sempos')
Truth table0%0/2
A
A= $node->{'t_lemma'}
Aresult
11
00
Truth table0%0/2
A
A= $node->attr('gram/sempos')
Aresult
11
00
228 0 ▶ $opts->{-pos} = $a_node->attr('tag') if $a_node->attr('tag');
Branch: 1 branch
BranchTrueFalseTotal
if $a_node->attr("tag") 0 0 0
229 0 TrEd::EngValLex::GUI::ChooseFrame($opts);
230 0 TredMacro::ChangingFile(0);
231 0 return;
232 }
233  
234 2 1;
235  
236 __END__
237  
238 =head1 NAME
239  
240 Treex::Core::TredView::Vallex - Browsing valency lexicons
241  
242 =head1 VERSION
243  
244 version 0.08633_1
245  
246 =head1 DESCRIPTION
247  
248 This package provides browsers of valency lexicons
249  
250 =head1 METHODS
251  
252 =head2 Public methods
253  
254 =over 4
255  
256 =item OpenValLexicon
257  
258 =item ChooseValFrame
259  
260 =back
261  
262 =head2 Private methods
263  
264 =over 4
265  
266 =item _OpenValLexicon_Cs
267  
268 =item _ChooseValFrame_Cs
269  
270 =item _OpenValLexicon_En
271  
272 =item _ChooseValFrame_En
273  
274 =item _extension_missing
275  
276 =item _find_vallex
277  
278 =item _assigned_frame_pos_of
279  
280 =back
281  
282 =head1 AUTHOR
283  
284 Josef Toman <toman@ufal.mff.cuni.cz>
285  
286 =head1 COPYRIGHT AND LICENSE
287  
288 Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague
289  
290 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« lib/Treex/Block/Util/DefinedAttr.pm ↑ Summary lib/Treex/Core/Node/Ordered.pm »