| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Text::Same::Match |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Objects of this class represent a match between a group of chunks |
|
8
|
|
|
|
|
|
|
(generally lines) in one source (eg a file) and a group of chunks in |
|
9
|
|
|
|
|
|
|
another. The "chunks" could potentially be paragraphs or sentences. |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my @pairs = ($chunk_pair1, $chunk_pair2, ...); |
|
14
|
|
|
|
|
|
|
my $match = new Text::Same::Match(@pairs); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 METHODS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
See below. Methods private to this module are prefixed by an |
|
19
|
|
|
|
|
|
|
underscore. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package Text::Same::Match; |
|
24
|
|
|
|
|
|
|
|
|
25
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
86
|
|
|
26
|
3
|
|
|
3
|
|
15
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
186
|
|
|
27
|
3
|
|
|
3
|
|
14
|
use Carp; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
1620
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
3
|
|
|
3
|
|
17
|
use vars qw($VERSION); |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
3531
|
|
|
30
|
|
|
|
|
|
|
$VERSION = '0.07'; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 new |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Title : new |
|
35
|
|
|
|
|
|
|
Usage : $match = new Text::Same::Match(@pairs) |
|
36
|
|
|
|
|
|
|
Function: Creates a new Match object from an array of ChunkPair objects |
|
37
|
|
|
|
|
|
|
Returns : A Text::Same::Match object |
|
38
|
|
|
|
|
|
|
Args : an array of ChunkPair objects |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
107
|
|
|
107
|
1
|
140
|
my $arg = shift; |
|
45
|
107
|
|
33
|
|
|
421
|
my $class = ref($arg) || $arg; |
|
46
|
|
|
|
|
|
|
|
|
47
|
107
|
|
|
|
|
404
|
my $self = {@_}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
107
|
|
|
|
|
201
|
$self->{min1} = 999999999999; |
|
50
|
107
|
|
|
|
|
171
|
$self->{max1} = -1; |
|
51
|
107
|
|
|
|
|
150
|
$self->{min2} = 999999999999; |
|
52
|
107
|
|
|
|
|
172
|
$self->{max2} = -1; |
|
53
|
|
|
|
|
|
|
|
|
54
|
107
|
|
|
|
|
225
|
bless $self, $class; |
|
55
|
107
|
|
|
|
|
117
|
$self->_update_stats(@{$self->{pairs}}); |
|
|
107
|
|
|
|
|
282
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
107
|
|
|
|
|
314
|
return $self; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 add |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Title : add |
|
64
|
|
|
|
|
|
|
Usage : $match->add(@chunk_pairs); |
|
65
|
|
|
|
|
|
|
Function: add ChunkPair objects to this objects - no checks are made that |
|
66
|
|
|
|
|
|
|
the new ChunkPairs are ajacent to the current pairs |
|
67
|
|
|
|
|
|
|
Returns : $self |
|
68
|
|
|
|
|
|
|
Args : an array of ChunkPair objects |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub add |
|
73
|
|
|
|
|
|
|
{ |
|
74
|
206
|
|
|
206
|
1
|
250
|
my $self = shift; |
|
75
|
206
|
|
|
|
|
427
|
$self->_update_stats(@_); |
|
76
|
206
|
|
|
|
|
347
|
push @{$self->{pairs}}, @_; |
|
|
206
|
|
|
|
|
564
|
|
|
77
|
206
|
|
|
|
|
415
|
$self; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 source1 |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Title : source1 |
|
83
|
|
|
|
|
|
|
Usage : my $chunked_source = $match->source1; |
|
84
|
|
|
|
|
|
|
Function: get the ChunkedSource for the source 1 |
|
85
|
|
|
|
|
|
|
Returns : a ChunkedSource reference |
|
86
|
|
|
|
|
|
|
Args : none |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub source1 |
|
91
|
|
|
|
|
|
|
{ |
|
92
|
140
|
|
|
140
|
1
|
192
|
my $self = shift; |
|
93
|
140
|
|
|
|
|
437
|
return $self->{source1}; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 source2 |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Title : source2 |
|
99
|
|
|
|
|
|
|
Usage : my $chunked_source = $match->source2; |
|
100
|
|
|
|
|
|
|
Function: get the ChunkedSource for the source 2 |
|
101
|
|
|
|
|
|
|
Returns : a ChunkedSource reference |
|
102
|
|
|
|
|
|
|
Args : none |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub source2 |
|
107
|
|
|
|
|
|
|
{ |
|
108
|
140
|
|
|
140
|
1
|
174
|
my $self = shift; |
|
109
|
140
|
|
|
|
|
447
|
return $self->{source2}; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _update_stats |
|
113
|
|
|
|
|
|
|
{ |
|
114
|
313
|
|
|
313
|
|
384
|
my $self = shift; |
|
115
|
313
|
|
|
|
|
899
|
my @new_pairs = @_; |
|
116
|
|
|
|
|
|
|
|
|
117
|
313
|
|
|
|
|
494
|
for my $chunk_pair (@new_pairs) { |
|
118
|
313
|
|
|
|
|
779
|
my $chunk_index1 = $chunk_pair->chunk_index1; |
|
119
|
313
|
|
|
|
|
763
|
my $chunk_index2 = $chunk_pair->chunk_index2; |
|
120
|
|
|
|
|
|
|
|
|
121
|
313
|
100
|
|
|
|
778
|
if ($chunk_index1 < $self->{min1}) { |
|
122
|
107
|
|
|
|
|
189
|
$self->{min1} = $chunk_index1; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
313
|
50
|
|
|
|
664
|
if ($chunk_index1 > $self->{max1}) { |
|
125
|
313
|
|
|
|
|
432
|
$self->{max1} = $chunk_index1; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
313
|
100
|
|
|
|
631
|
if ($chunk_index2 < $self->{min2}) { |
|
128
|
107
|
|
|
|
|
140
|
$self->{min2} = $chunk_index2; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
313
|
50
|
|
|
|
621
|
if ($chunk_index2 > $self->{max2}) { |
|
131
|
313
|
|
|
|
|
1018
|
$self->{max2} = $chunk_index2; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 min1 |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Title : min1 |
|
140
|
|
|
|
|
|
|
Usage : $match->min1; |
|
141
|
|
|
|
|
|
|
Function: return the minimum index of the chunks in the first (ie. left) of |
|
142
|
|
|
|
|
|
|
the ChunkedSources held in this Match |
|
143
|
|
|
|
|
|
|
Args : None |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub min1 |
|
148
|
|
|
|
|
|
|
{ |
|
149
|
319
|
|
|
319
|
1
|
1490
|
return $_[0]->{min1}; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 max1 |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Title : max1 |
|
155
|
|
|
|
|
|
|
Usage : $match->max1; |
|
156
|
|
|
|
|
|
|
Function: return the maximum index of the chunks in the first (ie. left) of |
|
157
|
|
|
|
|
|
|
the ChunkedSources held in this Match |
|
158
|
|
|
|
|
|
|
Args : None |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub max1 |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
650
|
|
|
650
|
1
|
2095
|
return $_[0]->{max1}; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 min2 |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Title : min2 |
|
170
|
|
|
|
|
|
|
Usage : $match->min2; |
|
171
|
|
|
|
|
|
|
Function: return the minimum index of the chunks in the second (ie. right) of |
|
172
|
|
|
|
|
|
|
the ChunkedSources held in this Match |
|
173
|
|
|
|
|
|
|
Args : None |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub min2 |
|
178
|
|
|
|
|
|
|
{ |
|
179
|
319
|
|
|
319
|
1
|
1001
|
return $_[0]->{min2}; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 max2 |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Title : max2 |
|
185
|
|
|
|
|
|
|
Usage : $match->max2; |
|
186
|
|
|
|
|
|
|
Function: return the maximum index of the chunks in the second (ie. right) of |
|
187
|
|
|
|
|
|
|
the ChunkedSources held in this Match |
|
188
|
|
|
|
|
|
|
Args : None |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub max2 |
|
193
|
|
|
|
|
|
|
{ |
|
194
|
653
|
|
|
653
|
1
|
2074
|
return $_[0]->{max2}; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 set_min1 |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Title : set_min1 |
|
200
|
|
|
|
|
|
|
Usage : $match->set_min1; |
|
201
|
|
|
|
|
|
|
Function: Set the minimum index of the chunks in the first (ie. left) of |
|
202
|
|
|
|
|
|
|
the ChunkedSources held in this Match |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub set_min1 |
|
207
|
|
|
|
|
|
|
{ |
|
208
|
107
|
|
|
107
|
1
|
132
|
my $self = shift; |
|
209
|
107
|
|
|
|
|
127
|
my $new_val = shift; |
|
210
|
107
|
50
|
|
|
|
247
|
if ($new_val > $self->{max1}) { |
|
211
|
0
|
|
|
|
|
0
|
die "min greater than max\n"; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
107
|
|
|
|
|
253
|
$self->{min1} = $new_val; |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 set_min2 |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Title : set_min2 |
|
219
|
|
|
|
|
|
|
Usage : $match->set_min2; |
|
220
|
|
|
|
|
|
|
Function: Set the minimum index of the chunks in the second (ie. right) of |
|
221
|
|
|
|
|
|
|
the ChunkedSources held in this Match |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub set_min2 |
|
226
|
|
|
|
|
|
|
{ |
|
227
|
107
|
|
|
107
|
1
|
147
|
my $self = shift; |
|
228
|
107
|
|
|
|
|
126
|
my $new_val = shift; |
|
229
|
107
|
50
|
|
|
|
252
|
if ($new_val > $self->{max2}) { |
|
230
|
0
|
|
|
|
|
0
|
die "min greater than max\n"; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
107
|
|
|
|
|
244
|
$self->{min2} = $new_val; |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 set_max1 |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Title : set_max1 |
|
238
|
|
|
|
|
|
|
Usage : $match->set_max1; |
|
239
|
|
|
|
|
|
|
Function: Set the maximum index of the chunks in the first (ie. left) of |
|
240
|
|
|
|
|
|
|
the ChunkedSources held in this Match |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=cut |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub set_max1 |
|
245
|
|
|
|
|
|
|
{ |
|
246
|
107
|
|
|
107
|
1
|
130
|
my $self = shift; |
|
247
|
107
|
|
|
|
|
129
|
my $new_val = shift; |
|
248
|
107
|
50
|
|
|
|
275
|
if ($new_val < $self->{min1}) { |
|
249
|
0
|
|
|
|
|
0
|
die "min greater than max\n"; |
|
250
|
|
|
|
|
|
|
} |
|
251
|
107
|
|
|
|
|
259
|
$self->{max1} = $new_val; |
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head2 set_max2 |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Title : set_max2 |
|
257
|
|
|
|
|
|
|
Usage : $match->set_max2; |
|
258
|
|
|
|
|
|
|
Function: Set the maximum index of the chunks in the second (ie. right) of |
|
259
|
|
|
|
|
|
|
the ChunkedSources held in this Match |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=cut |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub set_max2 |
|
264
|
|
|
|
|
|
|
{ |
|
265
|
107
|
|
|
107
|
1
|
135
|
my $self = shift; |
|
266
|
107
|
|
|
|
|
128
|
my $new_val = shift; |
|
267
|
107
|
50
|
|
|
|
261
|
if ($new_val < $self->{min2}) { |
|
268
|
0
|
|
|
|
|
0
|
die "min greater than max\n"; |
|
269
|
|
|
|
|
|
|
} |
|
270
|
107
|
|
|
|
|
403
|
$self->{max2} = $new_val; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head2 pairs |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Title : pairs |
|
276
|
|
|
|
|
|
|
Usage : my @pairs = $match->pairs; |
|
277
|
|
|
|
|
|
|
Function: return all the ChunkPair objects that have been add()ed to this Match |
|
278
|
|
|
|
|
|
|
Returns : a List of ChunkPair objects |
|
279
|
|
|
|
|
|
|
Args : none |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=cut |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
sub pairs |
|
284
|
|
|
|
|
|
|
{ |
|
285
|
0
|
|
|
0
|
1
|
0
|
return $_[0]->{pairs}; |
|
286
|
|
|
|
|
|
|
} |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=head2 score |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
Title : score |
|
291
|
|
|
|
|
|
|
Usage : $acc = $seq->score; |
|
292
|
|
|
|
|
|
|
Function: The score of this Match - longer match gives a higher score |
|
293
|
|
|
|
|
|
|
Returns : int - currently returns the total number of lines this match |
|
294
|
|
|
|
|
|
|
covers in both files |
|
295
|
|
|
|
|
|
|
Args : None |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=cut |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub score |
|
300
|
|
|
|
|
|
|
{ |
|
301
|
2
|
|
|
2
|
1
|
10
|
my $self = shift; |
|
302
|
2
|
|
|
|
|
14
|
return $self->{max1} - $self->{min1} + $self->{max2} - $self->{min2} + 2; |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head2 as_string |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Title : as_string |
|
309
|
|
|
|
|
|
|
Usage : my $str = $match->as_string |
|
310
|
|
|
|
|
|
|
Function: return a string representation of this Match |
|
311
|
|
|
|
|
|
|
Args : none |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=cut |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
sub as_string |
|
316
|
|
|
|
|
|
|
{ |
|
317
|
35
|
|
|
35
|
1
|
55
|
my $self = shift; |
|
318
|
|
|
|
|
|
|
|
|
319
|
35
|
|
|
|
|
76
|
return $self->min1 . ".." . $self->max1 . "==" . $self->min2 . ".." . $self->max2; |
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=head1 AUTHOR |
|
323
|
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
Kim Rutherford |
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
Copyright 2005,2006 Kim Rutherford. All rights reserved. |
|
329
|
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
331
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=head1 DISCLAIMER |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
This module is provided "as is" without warranty of any kind. It |
|
336
|
|
|
|
|
|
|
may redistributed under the same conditions as Perl itself. |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=cut |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
1; |