line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CQL::TermNode; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
3296
|
use strict; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
388
|
|
4
|
10
|
|
|
10
|
|
52
|
use warnings; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
1015
|
|
5
|
10
|
|
|
10
|
|
89
|
use base qw( CQL::Node ); |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
2047
|
|
6
|
10
|
|
|
10
|
|
59
|
use Carp qw( croak ); |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
869
|
|
7
|
10
|
|
|
10
|
|
2479
|
use CQL::Utils qw( indent xq renderPrefixes ); |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
19651
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
CQL::TermNode - represents a terminal Node in a CQL Parse Tree |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
CQL::TermNode represents a terminal in a CQL parse tree. A term node |
18
|
|
|
|
|
|
|
consists of the string itself with optional qualifier string and relation. |
19
|
|
|
|
|
|
|
Examples could include: |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=over 4 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=item * george |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item * dc.creator=george |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=back |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 new() |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
The constructor which has must have at least a term attribute, and |
34
|
|
|
|
|
|
|
can also include optional qualifier and modifier terms. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
96
|
|
|
96
|
1
|
3596
|
my ($class,%args) = @_; |
40
|
96
|
50
|
|
|
|
247
|
croak( "must supply term parameter" ) if ! exists( $args{term} ); |
41
|
96
|
|
33
|
|
|
689
|
return bless \%args, ref($class) || $class; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 getQualifier() |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Get the qualifier in the terminal. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub getQualifier { |
51
|
204
|
|
|
204
|
1
|
560
|
return shift->{qualifier}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 getRelation() |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Get the relation in the terminal. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub getRelation { |
61
|
213
|
|
|
213
|
1
|
3237
|
return shift->{relation}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 getTerm() |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Get the actual term string in the terminal. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub getTerm { |
71
|
206
|
|
|
206
|
1
|
1398
|
return shift->{term}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 toCQL() |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Returns a CQL representation of the terminal node. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub toCQL { |
81
|
163
|
|
|
163
|
1
|
3952
|
my $self = shift; |
82
|
163
|
|
|
|
|
372
|
my $qualifier = maybeQuote( $self->getQualifier() ); |
83
|
163
|
|
|
|
|
478
|
my $term = maybeQuote( $self->getTerm() ); |
84
|
163
|
|
|
|
|
404
|
my $relation = $self->getRelation(); |
85
|
|
|
|
|
|
|
|
86
|
163
|
|
|
|
|
435
|
my $cql; |
87
|
163
|
100
|
100
|
|
|
876
|
if ( $qualifier and $qualifier !~ /srw\.serverChoice/i ) { |
88
|
46
|
|
|
|
|
157
|
$cql = join( ' ', $qualifier, $relation->toCQL(), $term); |
89
|
|
|
|
|
|
|
} else { |
90
|
117
|
|
|
|
|
210
|
$cql = $term; |
91
|
|
|
|
|
|
|
} |
92
|
163
|
|
|
|
|
790
|
return $cql; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 toSwish() |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub toSwish { |
100
|
14
|
|
|
14
|
1
|
110
|
my $self = shift; |
101
|
14
|
|
|
|
|
23
|
my $qualifier = maybeQuote( $self->getQualifier() ); |
102
|
14
|
|
|
|
|
28
|
my $term = maybeQuote( $self->getTerm() ); |
103
|
14
|
|
|
|
|
27
|
my $relation = $self->getRelation(); |
104
|
14
|
|
|
|
|
11
|
my $swish; |
105
|
14
|
100
|
66
|
|
|
58
|
if ( $qualifier and $qualifier !~ /srw\.serverChoice/i ) { |
106
|
2
|
|
|
|
|
7
|
$swish = join( ' ', $qualifier, $relation->toSwish(), $term ); |
107
|
|
|
|
|
|
|
} else { |
108
|
12
|
|
|
|
|
13
|
$swish = $term; |
109
|
|
|
|
|
|
|
} |
110
|
13
|
|
|
|
|
44
|
return $swish; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 toXCQL() |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub toXCQL { |
118
|
6
|
|
|
6
|
1
|
15
|
my ($self,$level,@prefixes) = @_; |
119
|
6
|
100
|
|
|
|
18
|
$level = 0 unless $level; |
120
|
6
|
|
|
|
|
22
|
my $xml = |
121
|
|
|
|
|
|
|
indent($level) . "\n" . |
122
|
|
|
|
|
|
|
renderPrefixes($level+1,@prefixes) . |
123
|
|
|
|
|
|
|
indent($level+1) . "".xq($self->getQualifier())."\n"; |
124
|
6
|
100
|
|
|
|
21
|
if ( $self->getRelation() ) { |
125
|
2
|
|
|
|
|
7
|
$xml .= $self->getRelation()->toXCQL($level+1); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
$xml .= |
128
|
6
|
|
|
|
|
35
|
indent($level+1) . "" . xq($self->getTerm()) . "\n" . |
129
|
|
|
|
|
|
|
indent($level) . "\n"; |
130
|
6
|
|
|
|
|
46
|
return $self->addNamespace( $level, $xml ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 toLucene() |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub toLucene { |
138
|
19
|
|
|
19
|
1
|
134
|
my $self = shift; |
139
|
19
|
|
|
|
|
35
|
my $qualifier = maybeQuote( $self->getQualifier() ); |
140
|
19
|
|
|
|
|
48
|
my $term = maybeQuote( $self->getTerm() ); |
141
|
19
|
|
|
|
|
39
|
my $relation = $self->getRelation(); |
142
|
|
|
|
|
|
|
|
143
|
19
|
|
|
|
|
21
|
my $query; |
144
|
19
|
100
|
66
|
|
|
99
|
if ( $qualifier and $qualifier !~ /srw\.serverChoice/i ) { |
145
|
3
|
|
|
|
|
13
|
my $base = $relation->getBase(); |
146
|
3
|
|
|
|
|
15
|
my @modifiers = $relation->getModifiers(); |
147
|
|
|
|
|
|
|
|
148
|
3
|
|
|
|
|
6
|
foreach my $m ( @modifiers ) { |
149
|
1
|
50
|
|
|
|
5
|
if( $m->[ 1 ] eq 'fuzzy' ) { |
150
|
1
|
|
|
|
|
4
|
$term = "$term~"; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
3
|
100
|
|
|
|
11
|
if( $base eq '=' ) { |
155
|
2
|
|
|
|
|
13
|
$base = ':'; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
else { |
158
|
1
|
|
|
|
|
20
|
croak( "Lucene doesn't support relations other than '='" ); |
159
|
|
|
|
|
|
|
} |
160
|
2
|
|
|
|
|
13
|
return "$qualifier$base$term"; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
else { |
163
|
16
|
|
|
|
|
59
|
return $term; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub maybeQuote { |
168
|
392
|
|
|
392
|
0
|
547
|
my $str = shift; |
169
|
392
|
100
|
|
|
|
798
|
return if ! defined $str; |
170
|
381
|
100
|
|
|
|
984
|
if ( $str =~ m|[" \t=<>/()]| ) { |
171
|
39
|
|
|
|
|
69
|
$str =~ s/"/\\"/g; |
172
|
39
|
|
|
|
|
84
|
$str = qq("$str"); |
173
|
|
|
|
|
|
|
} |
174
|
381
|
|
|
|
|
660
|
return $str; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |