line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# GENERATED WITH PDL::PP! Don't modify! |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
package PDL::Ngrams::Utils; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
@EXPORT_OK = qw( PDL::PP ng_delimit PDL::PP ng_undelimit ); |
8
|
|
|
|
|
|
|
%EXPORT_TAGS = (Func=>[@EXPORT_OK]); |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
23
|
use PDL::Core; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
24
|
|
11
|
4
|
|
|
4
|
|
1279
|
use PDL::Exporter; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
24
|
|
12
|
4
|
|
|
4
|
|
96
|
use DynaLoader; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
289
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$PDL::Ngrams::Utils::VERSION = 0.09; |
17
|
|
|
|
|
|
|
@ISA = ( 'PDL::Exporter','DynaLoader' ); |
18
|
|
|
|
|
|
|
push @PDL::Core::PP, __PACKAGE__; |
19
|
|
|
|
|
|
|
bootstrap PDL::Ngrams::Utils $VERSION; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1668
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=pod |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
PDL::Ngrams::ngutils - Basic N-Gram utilities for PDL: low-level utilities |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use PDL; |
36
|
|
|
|
|
|
|
use PDL::Ngrams::ngutils; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
##--------------------------------------------------------------------- |
39
|
|
|
|
|
|
|
## ... stuff happens |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 FUNCTIONS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=pod |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 Delimiter Insertion and Removal |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 ng_delimit |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=for sig |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Signature: (toks(NToks); indx boffsets(NBlocks); delims(NDelims); [o]dtoks(NDToks)) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Add block-delimiters to a raw token vector |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Splices the vector $delims into the vector $toks starting at each index |
78
|
|
|
|
|
|
|
listed in $boffsets, returning the result as $dtoks. Values in $boffsets |
79
|
|
|
|
|
|
|
should be in the range [0..N-1]. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
For consistency, it should be the case that: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$NDToks == $NToks + $NBlocks * $NDelims |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=for bad |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
ng_delimit does not process bad values. |
90
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub PDL::ng_delimit { |
99
|
7
|
|
|
7
|
0
|
3400
|
my ($toks,$boffsets,$delims,$dtoks,$ndtoks) = @_; |
100
|
|
|
|
|
|
|
barf('Usage: ng_delimit(toks(NToks), indx boffsets(NBlocks), delims(NDelims), [o]dtoks(NDToks), ndtoks=>NDToks)') |
101
|
7
|
50
|
|
|
|
13
|
if (grep {!defined($_)} ($toks,$boffsets,$delims)); |
|
21
|
|
|
|
|
56
|
|
102
|
|
|
|
|
|
|
## |
103
|
|
|
|
|
|
|
##-- basic data |
104
|
7
|
|
|
|
|
25
|
my @tokdims = $toks->dims; |
105
|
7
|
|
|
|
|
159
|
my $NToks = shift(@tokdims); |
106
|
7
|
|
|
|
|
26
|
my $NBlocks = $boffsets->dim(0); |
107
|
7
|
|
|
|
|
38
|
my $NDelims = $delims->dim(0); |
108
|
|
|
|
|
|
|
## |
109
|
|
|
|
|
|
|
##-- $ndtoks: maybe compute number of delimiters+tokens |
110
|
7
|
50
|
33
|
|
|
47
|
$ndtoks = $NToks + ($NBlocks * $NDelims) |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
111
|
|
|
|
|
|
|
if ((!defined($dtoks) || $dtoks->isempty) && (!defined($ndtoks) || $ndtoks <= 0)); |
112
|
|
|
|
|
|
|
## |
113
|
|
|
|
|
|
|
##-- $dtoks: maybe allocate |
114
|
7
|
50
|
33
|
|
|
39
|
$dtoks = $toks->zeroes($toks->type, $ndtoks,@tokdims) |
115
|
|
|
|
|
|
|
if (!defined($dtoks) || $dtoks->isempty); |
116
|
|
|
|
|
|
|
## |
117
|
|
|
|
|
|
|
##-- underlying low-level call |
118
|
7
|
|
|
|
|
715
|
&PDL::_ng_delimit_int($toks,$boffsets,$delims,$dtoks); |
119
|
7
|
|
|
|
|
49
|
return $dtoks; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
*ng_delimit = \&PDL::ng_delimit; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 ng_undelimit |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=for sig |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Signature: (dtoks(NDToks); indx boffsets(NBlocks); int NDelims(); [o]toks(NToks)) |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Remove block-delimiters from a delimited token vector. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Removes chunks of length $delims from the vector $toks starting at each index |
138
|
|
|
|
|
|
|
listed in $boffsets, returning the result as $toks. Values in $boffsets |
139
|
|
|
|
|
|
|
should be in the range [0..N-1]. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=for bad |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
ng_undelimit does not process bad values. |
146
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub PDL::ng_undelimit { |
155
|
5
|
|
|
5
|
0
|
2971
|
my ($dtoks,$boffsets,$NDelims,$toks) = @_; |
156
|
|
|
|
|
|
|
barf('Usage: ng_delimit(dtoks(NDToks), indx boffsets(NBlocks), NDelims(), [o]toks(NToks))') |
157
|
5
|
50
|
|
|
|
9
|
if (grep {!defined($_)} ($dtoks,$boffsets,$NDelims)); |
|
15
|
|
|
|
|
38
|
|
158
|
|
|
|
|
|
|
## |
159
|
|
|
|
|
|
|
##-- $toks: maybe allocate |
160
|
5
|
50
|
33
|
|
|
33
|
if (!defined($toks) || $toks->isempty) { |
161
|
5
|
|
|
|
|
18
|
$NDelims = PDL->topdl($NDelims); |
162
|
5
|
|
|
|
|
304
|
my @dtokdims = $dtoks->dims; |
163
|
5
|
|
|
|
|
95
|
my $NDToks = shift(@dtokdims); |
164
|
5
|
|
|
|
|
16
|
my $NBlocks = $boffsets->dim(0); |
165
|
5
|
|
|
|
|
21
|
my $NToks = $NDToks - ($NDelims->max * $NBlocks); |
166
|
5
|
|
|
|
|
232
|
$toks = zeroes($dtoks->type, $NToks,@dtokdims); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
## |
169
|
|
|
|
|
|
|
##-- underlying low-level call |
170
|
5
|
|
|
|
|
411
|
&PDL::_ng_undelimit_int($dtoks,$boffsets,$NDelims, $toks); |
171
|
5
|
|
|
|
|
36
|
return $toks; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
*ng_undelimit = \&PDL::ng_undelimit; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
##--------------------------------------------------------------------- |
181
|
|
|
|
|
|
|
=pod |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Perl by Larry Wall. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
PDL by Karl Glazebrook, Tuomas J. Lukka, Christian Soeller, and others. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
##---------------------------------------------------------------------- |
192
|
|
|
|
|
|
|
=pod |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 KNOWN BUGS |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Probably many. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
##--------------------------------------------------------------------- |
202
|
|
|
|
|
|
|
=pod |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 AUTHOR |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Bryan Jurish Emoocow@cpan.orgE |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 Copyright Policy |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Copyright (C) 2007, Bryan Jurish. All rights reserved. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This package is free software, and entirely without warranty. |
213
|
|
|
|
|
|
|
You may redistribute it and/or modify it under the same terms |
214
|
|
|
|
|
|
|
as Perl itself. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 SEE ALSO |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
perl(1), PDL(3perl) |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=cut |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# Exit with OK status |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
1; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
|