line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Search::InvertedIndex::Simple; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Name: |
4
|
|
|
|
|
|
|
# Search::InvertedIndex::Simple. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Documentation: |
7
|
|
|
|
|
|
|
# POD-style documentation is at the end. Extract it with pod2html.*. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Reference: |
10
|
|
|
|
|
|
|
# Object Oriented Perl |
11
|
|
|
|
|
|
|
# Damian Conway |
12
|
|
|
|
|
|
|
# Manning |
13
|
|
|
|
|
|
|
# 1-884777-79-1 |
14
|
|
|
|
|
|
|
# P 114 |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# Note: |
17
|
|
|
|
|
|
|
# o Tab = 4 spaces || die. |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# Author: |
20
|
|
|
|
|
|
|
# Ron Savage |
21
|
|
|
|
|
|
|
# Home page: http://savage.net.au/index.html |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# Licence: |
24
|
|
|
|
|
|
|
# Australian copyright (c) 1999-2002 Ron Savage. |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# All Programs of mine are 'OSI Certified Open Source Software'; |
27
|
|
|
|
|
|
|
# you can redistribute them and/or modify them under the terms of |
28
|
|
|
|
|
|
|
# The Artistic License, a copy of which is available at: |
29
|
|
|
|
|
|
|
# http://www.opensource.org/licenses/index.html |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
355561
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
850
|
|
32
|
1
|
|
|
1
|
|
10
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
56
|
|
33
|
1
|
|
|
1
|
|
7
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
require 5.005_62; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
4603
|
use Set::Array; |
|
1
|
|
|
|
|
24667
|
|
|
1
|
|
|
|
|
731
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
require Exporter; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
44
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
45
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# This allows declaration use Search::InvertedIndex::Simple ':all'; |
48
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
49
|
|
|
|
|
|
|
# will save memory. |
50
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
) ] ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
our @EXPORT = qw( |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
our $VERSION = '1.04'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# ----------------------------------------------- |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Encapsulated class data. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
my(%_attr_data) = |
67
|
|
|
|
|
|
|
( # Alphabetical order. |
68
|
|
|
|
|
|
|
_dataset => [], |
69
|
|
|
|
|
|
|
_keyset => [], |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _default_for |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
0
|
|
0
|
my($self, $attr_name) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
$_attr_data{$attr_name}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _standard_keys |
80
|
|
|
|
|
|
|
{ |
81
|
2
|
|
|
2
|
|
18
|
sort keys %_attr_data; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} # End of Encapsulated class data. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# ----------------------------------------------- |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub build_index |
89
|
|
|
|
|
|
|
{ |
90
|
2
|
|
|
2
|
0
|
4
|
my($self) = @_; |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
3
|
my($i, $data, $key, $value, $offset, $prefix, %index); |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
|
|
|
4
|
for $i (0 .. $#{$$self{'_dataset'} }) |
|
2
|
|
|
|
|
8
|
|
95
|
|
|
|
|
|
|
{ |
96
|
8
|
|
|
|
|
16
|
$data = $$self{'_dataset'}[$i]; |
97
|
|
|
|
|
|
|
|
98
|
8
|
|
|
|
|
10
|
for $key (@{$$self{'_keyset'} }) |
|
8
|
|
|
|
|
22
|
|
99
|
|
|
|
|
|
|
{ |
100
|
16
|
|
|
|
|
27
|
$value = $$data{$key}; |
101
|
16
|
100
|
|
|
|
44
|
$index{$key} = {} if (! $index{$key}); |
102
|
|
|
|
|
|
|
|
103
|
16
|
|
|
|
|
36
|
for $offset (1 .. length $value) |
104
|
|
|
|
|
|
|
{ |
105
|
133
|
|
|
|
|
202
|
$prefix = substr($value, 0, $offset); |
106
|
133
|
100
|
|
|
|
501
|
$index{$key}{$prefix} = [] if (! $index{$key}{$prefix}); |
107
|
|
|
|
|
|
|
|
108
|
133
|
|
|
|
|
166
|
push @{$index{$key}{$prefix} }, $i; |
|
133
|
|
|
|
|
380
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
2
|
|
|
|
|
7
|
for $key (keys %index) |
114
|
|
|
|
|
|
|
{ |
115
|
4
|
|
|
|
|
410
|
for $prefix (keys %{$index{$key} }) |
|
4
|
|
|
|
|
31
|
|
116
|
|
|
|
|
|
|
{ |
117
|
109
|
|
|
|
|
811
|
$index{$key}{$prefix} = Set::Array -> new(@{$index{$key}{$prefix} }); |
|
109
|
|
|
|
|
340
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
|
|
27
|
\%index; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} # End of build_index. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# ----------------------------------------------- |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub new |
128
|
|
|
|
|
|
|
{ |
129
|
2
|
|
|
2
|
0
|
1893
|
my($caller, %arg) = @_; |
130
|
2
|
|
|
|
|
5
|
my($caller_is_obj) = ref($caller); |
131
|
2
|
|
33
|
|
|
14
|
my($class) = $caller_is_obj || $caller; |
132
|
2
|
|
|
|
|
13
|
my($self) = bless({}, $class); |
133
|
|
|
|
|
|
|
|
134
|
2
|
|
|
|
|
9
|
for my $attr_name ($self -> _standard_keys() ) |
135
|
|
|
|
|
|
|
{ |
136
|
4
|
|
|
|
|
19
|
my($arg_name) = $attr_name =~ /^_(.*)/; |
137
|
|
|
|
|
|
|
|
138
|
4
|
50
|
|
|
|
12
|
if (exists($arg{$arg_name}) ) |
|
|
0
|
|
|
|
|
|
139
|
|
|
|
|
|
|
{ |
140
|
4
|
|
|
|
|
20
|
$$self{$attr_name} = $arg{$arg_name}; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
elsif ($caller_is_obj) |
143
|
|
|
|
|
|
|
{ |
144
|
0
|
|
|
|
|
0
|
$$self{$attr_name} = $$caller{$attr_name}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else |
147
|
|
|
|
|
|
|
{ |
148
|
0
|
|
|
|
|
0
|
$$self{$attr_name} = $self -> _default_for($attr_name); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
2
|
|
|
|
|
13
|
$self; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
} # End of new. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# ----------------------------------------------- |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
__END__ |