line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FrameNet::WordNet::Detour::Data; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require Exporter; |
4
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
5
|
|
|
|
|
|
|
our $VERSION = "0.99"; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4753
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
8
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
9
|
1
|
|
|
1
|
|
712
|
use FrameNet::WordNet::Detour::Frame; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1188
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
13
|
0
|
|
|
|
|
|
my $this = {}; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
bless($this, $class); |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
$this->{'s2f-result'} = shift; |
18
|
0
|
|
|
|
|
|
$this->{'raw'} = $this->{'s2f-result'}{'raw'}; |
19
|
0
|
|
|
|
|
|
$this->{'sorted'} = $this->{'s2f-result'}{'sorted'}; |
20
|
0
|
|
|
|
|
|
my @warr = reverse (sort { $a <=> $b } keys %{$this->{'sorted'}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$this->{'weights'} = \@warr; |
22
|
0
|
|
|
|
|
|
$this->query(shift); |
23
|
0
|
0
|
|
|
|
|
$this->message(shift) || $this->message('OK'); |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
return $this; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub query { |
29
|
0
|
|
|
0
|
1
|
|
my ($self,$query) = @_; |
30
|
0
|
0
|
|
|
|
|
if (defined $query) { |
31
|
0
|
|
|
|
|
|
$self->{'query'} = $query; |
32
|
|
|
|
|
|
|
}; |
33
|
0
|
|
|
|
|
|
return $self->{'query'}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#sub get_query { |
37
|
|
|
|
|
|
|
# my ($self,$query) = @_; |
38
|
|
|
|
|
|
|
# if (defined $query) { |
39
|
|
|
|
|
|
|
# return $self->query($query); |
40
|
|
|
|
|
|
|
# }; |
41
|
|
|
|
|
|
|
# return $self->query; |
42
|
|
|
|
|
|
|
#} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub message { |
45
|
0
|
|
|
0
|
1
|
|
my ($self,$msg) = @_; |
46
|
0
|
0
|
|
|
|
|
if (defined $msg) { |
47
|
0
|
|
|
|
|
|
$self->{'message'} = $msg; |
48
|
|
|
|
|
|
|
}; |
49
|
0
|
|
|
|
|
|
return $self->{'message'}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Checks, wether the query returned some useful results or not. |
55
|
|
|
|
|
|
|
# If not, one should check the error message via &get_message. |
56
|
|
|
|
|
|
|
# Could be better, by checking deeper in the data structure, |
57
|
|
|
|
|
|
|
# if there is a 'Frame'-Object. |
58
|
|
|
|
|
|
|
sub isOK { |
59
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
60
|
0
|
0
|
|
|
|
|
return 1 if ($self->{'message'} eq 'OK'); |
61
|
0
|
|
|
|
|
|
return 0; |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_fees { |
67
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
68
|
0
|
|
|
|
|
|
my $_frame = shift; |
69
|
0
|
|
|
|
|
|
my $f = $self->get_frame($_frame); |
70
|
0
|
0
|
|
|
|
|
return $f if ($f == -1); |
71
|
0
|
|
|
|
|
|
return $f->fees; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get_weight { |
75
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my $frame = shift; |
77
|
0
|
|
|
|
|
|
my $f = $self->get_frame($frame); |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
return $f if ($f == -1); |
80
|
0
|
|
|
|
|
|
return $f->weight; |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get_weights { |
84
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
85
|
0
|
|
|
|
|
|
return $self->{'weights'}; |
86
|
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# not working |
89
|
|
|
|
|
|
|
sub _get_delta { |
90
|
0
|
|
|
0
|
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
my $frame = shift; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $w0 = $self->{'raw'}->{$frame}->{'weight'}; |
95
|
0
|
|
|
|
|
|
my $w1 = 0; |
96
|
0
|
|
|
|
|
|
my @weights = ( sort { $a <=> $b } (keys %{$self->{'sorted'}})); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
for(my $i = 0; $i < scalar @weights; $i++) { |
101
|
0
|
0
|
0
|
|
|
|
$w1 = $weights[$i+1] if ($w0 == $weights[$i] && |
102
|
|
|
|
|
|
|
exists($weights[$i+1])); |
103
|
|
|
|
|
|
|
}; |
104
|
0
|
|
|
|
|
|
return int((($w0 - $w1)*1000)+0.5)/1000; |
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub get_number_of_frames { |
108
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
return scalar (keys %{$self->{'raw'}}); |
|
0
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
}; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Returns a reference to an array containing the arg1 |
113
|
|
|
|
|
|
|
# best frames (as Frame-Objects). Frames are sorted according |
114
|
|
|
|
|
|
|
# to their weight. |
115
|
|
|
|
|
|
|
# If arg1 is not given, the best frame will be returned. |
116
|
|
|
|
|
|
|
# Works always on the first (e.g. 0th) synset. |
117
|
|
|
|
|
|
|
sub get_best_frames { |
118
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
119
|
0
|
|
|
|
|
|
my $n = 0; |
120
|
0
|
|
0
|
|
|
|
my $m = shift || 1; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $ResultsByWeight = $self->{'sorted'}; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $ResultList = []; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $result_counter = 1; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
foreach my $weight (reverse(sort(keys %$ResultsByWeight))) { |
129
|
0
|
0
|
|
|
|
|
if ($result_counter <= $m) { |
130
|
0
|
|
|
|
|
|
foreach my $frame (keys %{$ResultsByWeight->{$weight}}) { |
|
0
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
push (@$ResultList, $ResultsByWeight->{$weight}->{$frame}); |
132
|
|
|
|
|
|
|
}; |
133
|
|
|
|
|
|
|
}; |
134
|
0
|
|
|
|
|
|
$result_counter++; |
135
|
|
|
|
|
|
|
}; |
136
|
0
|
|
|
|
|
|
return $ResultList; |
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# WORKS |
140
|
|
|
|
|
|
|
sub get_best_framenames { |
141
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
142
|
0
|
|
0
|
|
|
|
my $m = shift || 1; |
143
|
0
|
|
|
|
|
|
my $frames = $self->get_best_frames($m); |
144
|
0
|
|
|
|
|
|
my @arr = map($_->name, @$frames); |
145
|
0
|
|
|
|
|
|
return \@arr; |
146
|
|
|
|
|
|
|
}; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Returns a list of all found frames. |
149
|
|
|
|
|
|
|
sub get_all_framenames ($) { |
150
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
151
|
0
|
|
|
|
|
|
my $tmp = {}; |
152
|
0
|
|
|
|
|
|
foreach my $frame (keys %{$self->{'raw'}}) { |
|
0
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
$tmp->{$frame} = 1; |
154
|
|
|
|
|
|
|
} |
155
|
0
|
|
|
|
|
|
my @ret = keys %$tmp; |
156
|
0
|
|
|
|
|
|
return \@ret; |
157
|
|
|
|
|
|
|
}; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub get_all_frames { |
160
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
161
|
0
|
|
|
|
|
|
my $ResultsByWeight = $self->{'sorted'}; |
162
|
0
|
|
|
|
|
|
my $ResultList = []; |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
foreach my $weight (reverse(sort(keys %$ResultsByWeight))) { |
165
|
0
|
|
|
|
|
|
foreach my $frame (keys %{$ResultsByWeight->{$weight}}) { |
|
0
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
push (@$ResultList, $ResultsByWeight->{$weight}->{$frame}); |
167
|
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
}; |
169
|
0
|
|
|
|
|
|
return $ResultList; |
170
|
|
|
|
|
|
|
}; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub get_frame { |
173
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
174
|
0
|
|
|
|
|
|
my $frame = shift; |
175
|
|
|
|
|
|
|
#print STDERR $frame."!!!"; |
176
|
0
|
0
|
|
|
|
|
return $self->{'raw'}->{$frame} if (exists($self->{'raw'}->{$frame})); |
177
|
0
|
0
|
|
|
|
|
return $self->{'raw'}->{lc($frame)} if (exists($self->{'raw'}->{lc($frame)})); |
178
|
0
|
0
|
|
|
|
|
return $self->{'raw'}->{ucfirst($frame)} if (exists($self->{'raw'}->{ucfirst($frame)})); |
179
|
0
|
|
|
|
|
|
return -1; |
180
|
|
|
|
|
|
|
}; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub get_best_weight { |
183
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
184
|
0
|
|
|
|
|
|
my $w = $self->get_weights; |
185
|
0
|
|
|
|
|
|
return $w->[0]; |
186
|
|
|
|
|
|
|
}; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub get_frames_with_weight { |
189
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
190
|
0
|
|
|
|
|
|
my $weight = shift; |
191
|
0
|
|
|
|
|
|
my @l = keys %{$self->{'sorted'}->{$weight}}; |
|
0
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
return \@l; |
193
|
|
|
|
|
|
|
}; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
__END__ |