| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
##-*- Mode: CPerl -*- |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## File: DDC::Hit.pm |
|
4
|
|
|
|
|
|
|
## Author: Bryan Jurish |
|
5
|
|
|
|
|
|
|
## Description: |
|
6
|
|
|
|
|
|
|
## + DDC Query utilities: Hit |
|
7
|
|
|
|
|
|
|
##====================================================================== |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package DDC::Hit; |
|
10
|
26
|
|
|
26
|
|
191
|
use strict; |
|
|
26
|
|
|
|
|
50
|
|
|
|
26
|
|
|
|
|
7420
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
##====================================================================== |
|
13
|
|
|
|
|
|
|
## Globals |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
##====================================================================== |
|
16
|
|
|
|
|
|
|
## Constructors, etc. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
## $hit = $CLASS_OR_OBJ->new(%args) |
|
19
|
|
|
|
|
|
|
## + %$hit = %args = |
|
20
|
|
|
|
|
|
|
## ( |
|
21
|
|
|
|
|
|
|
## raw_ => $raw_data, ##-- hit data (raw buffer) |
|
22
|
|
|
|
|
|
|
## meta_ => \%meta, ##-- bibliographic metadata (parsed) |
|
23
|
|
|
|
|
|
|
## ctx_ => \@context, ##-- hit context (parsed) |
|
24
|
|
|
|
|
|
|
## ) |
|
25
|
|
|
|
|
|
|
## where \%meta = |
|
26
|
|
|
|
|
|
|
## { |
|
27
|
|
|
|
|
|
|
## file_ => $ddcFile, |
|
28
|
|
|
|
|
|
|
## scan_ => $ddcScanStr, |
|
29
|
|
|
|
|
|
|
## orig_ => $ddcOrigStr, |
|
30
|
|
|
|
|
|
|
## date_ => $ddcDate, |
|
31
|
|
|
|
|
|
|
## page_ => $ddcPage, |
|
32
|
|
|
|
|
|
|
## rank_ => $ddcRank, |
|
33
|
|
|
|
|
|
|
## rank_debug_ => $ddcRankDebug, |
|
34
|
|
|
|
|
|
|
## indices_ => \@indexNames, |
|
35
|
|
|
|
|
|
|
## $biblField => $biblValue, ##-- free bibliographic field fata |
|
36
|
|
|
|
|
|
|
## } |
|
37
|
|
|
|
|
|
|
## and @context = |
|
38
|
|
|
|
|
|
|
## [ |
|
39
|
|
|
|
|
|
|
## \@leftContext, ##-- [$w1,$w2,...,$wN] : pre-hit context: word strings
|
|
40
|
|
|
|
|
|
|
## \@hitTokens, ##-- [$t1,$t2,...\$tN] : hit tokens: parsed (without expandFields) |
|
41
|
|
|
|
|
|
|
## \@leftContext, ##-- [$w1,$w2,...,$wN] : post-hit context: word strings
|
|
42
|
|
|
|
|
|
|
## ] |
|
43
|
|
|
|
|
|
|
## and each $ti = $hitTokens[$i] = |
|
44
|
|
|
|
|
|
|
## [$hl,$f1val,$f2val,...,$fNval] ##-- without expandFields |
|
45
|
|
|
|
|
|
|
## {hl_=>$matchId, $f1name=>$f1val, ...} ##-- with expandFields |
|
46
|
|
|
|
|
|
|
sub new { |
|
47
|
0
|
|
|
0
|
1
|
|
my $that = shift; |
|
48
|
0
|
|
0
|
|
|
|
return bless { @_ }, ref($that)||$that; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
## $hit = $hit->expandFields() |
|
52
|
|
|
|
|
|
|
## $hit = $hit->expandFields(\@fieldNames) |
|
53
|
|
|
|
|
|
|
## + expand hit data tokens from arrays to hashes |
|
54
|
|
|
|
|
|
|
## + initial field is always implicitly 'hl_' (highlighting match-id, can be treated as bool) |
|
55
|
|
|
|
|
|
|
sub expandFields { |
|
56
|
0
|
|
|
0
|
0
|
|
my ($hit,$names) = @_; |
|
57
|
0
|
0
|
0
|
|
|
|
my @names = ('hl_', @{$names||$hit->{meta_}{indices_}||[]}); |
|
|
0
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my ($w); |
|
59
|
0
|
0
|
|
|
|
|
foreach (grep {defined $_} @{$hit->{ctx_}||[]}) { ##-- expand deep-encoded json context tokens if available (ddc >= v2.0.38) |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
foreach (grep {UNIVERSAL::isa($_,'ARRAY')} @$_) { |
|
|
0
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$w = $_; |
|
62
|
0
|
|
0
|
|
|
|
$_ = { map {(($names[$_]||"${_}_")=>$w->[$_])} (0..$#$w) }; |
|
|
0
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
0
|
|
|
|
|
|
return $hit; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
## $thingy = $obj->TO_JSON() |
|
69
|
|
|
|
|
|
|
## + annoying wrapper for JSON |
|
70
|
|
|
|
|
|
|
sub TO_JSON { |
|
71
|
0
|
|
|
0
|
0
|
|
return { %{$_[0]} }; |
|
|
0
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; ##-- be happy |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |