CAB/Analyzer/EqRW/JsonCDB.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 105 CC 7 SCAR 35.1
CC
7
Cov
0%
analyzeCode_DEBUG
56.0
new
2.0
analyzePre
2.0
CRAP 33.5
1 ## -*- Mode: CPerl -*-
2 ##
3 ## File: DTA::CAB::Analyzer::EqRW::JsonCDB.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: dictionary-based equivalence-class expander, phonetic variant
6  
7 package DTA::CAB::Analyzer::EqRW::JsonCDB;
8 use DTA::CAB::Analyzer ':child';
9 use DTA::CAB::Analyzer::Dict::JsonCDB;
10 use strict;
11  
12 ##==============================================================================
13 ## Globals
14 ##==============================================================================
15  
16 our @ISA = qw(DTA::CAB::Analyzer::Dict::JsonCDB);
17  
18 ##==============================================================================
19 ## Constructors etc.
20 ##==============================================================================
21  
22 ## $obj = CLASS_OR_OBJ->new(%args)
23 ## + object structure: see DTA::CAB::Analyzer::Dict::JsonCDB
24 sub new {
25 my $that = shift;
26 return $that->SUPER::new(
27 ##-- options
28 label => 'eqrw',
29 eqIdWeight => 0,
30 #allowRegex => '(?:^[[:alpha:]\-\x{ac}]*[[:alpha:]]+$)|(?:^[[:alpha:]]+[[:alpha:]\-\x{ac}]+$)',
31 allowRegex => '[[:alpha:]]',
32 ##
33 analyzeCode => join("\n",
34 'return if (defined($_->{$lab})); ##-- avoid re-analysis',
35 '$tmp=undef; ##-- re-initialize temporary used by _am_fst_uniq',
36 '$_->{$lab}=['._am_fst_usort((_am_id_fst('$_', '$dic->{eqIdWeight}')
37 .', map {defined($val=$tied->FETCH($_)) ? @{$jxs->decode($val)} : qw()}'
38 .join(',', _am_xtext, _am_xlit, _am_rw)
39 ),
40 '$tmp'
41 ).'];',
42 ),
43  
44 ##-- user args
45 @_
46 );
47 }
48  
49 ## $prefix = $dict->analyzePre()
50 sub analyzePre {
51 my $dic = shift;
52 return $dic->SUPER::analyzePre(@_)."\n".'my $tied=tied(%$dhash);'."\n".'my ($tmp);';
53 }
54  
55 ##-- DEBUG
56 sub analyzeCode_DEBUG {
57 my $anl = shift;
58  
59 my $jxs=$anl->jsonxs;
60 my $dic=$anl;
61 my $lab=$dic->{label};
62 my $dhash=$dic->dictHash;
63 my ($key,$val,@keys,@vals,%vals);
64 my $tied=tied(%$dhash);
65 my ($tmp);
66 return sub {
67 return if (defined($_->{$lab})); ##-- avoid re-analysis
68 if (!defined($val=$tied->FETCH(($_->{lts} && @{$_->{lts}} ? $_->{lts}[0]{hi} : $_->{text})))) {
69 $_->{$lab} = [{hi=>($_->{xlit} ? $_->{xlit}{latin1Text} : $_->{text}),w=>$dic->{eqIdWeight}}]; ##== _am_id_fst
70 return;
71 }
72 $tmp = undef;
73 $val = $jxs->decode($val);
74 @$val = (
75 sort {
76 ($a->{w}||0) <=> ($b->{w}||0) || ($a->{hi}||"") cmp ($b->{hi}||"")
77 } (
78 map {
79 $tmp && $tmp->{hi} eq $_->{hi} ? qw() : ($tmp=$_)
80 }
81 sort {
82 ($a->{hi}||"") cmp ($b->{hi}||"") || ($a->{w}||0) <=> ($b->{w}||0)
83 }
84 {hi=>($_->{xlit} ? $_->{xlit}{latin1Text} : $_->{text}),w=>$dic->{eqIdWeight}}, ##== _am_id_fst
85 @$val
86 ) ##== _am_fst_uniq
87 ) ##== _am_fst_sort
88 ;
89 $_->{$lab} = $val;
90 };
91 }
92  
93  
94 1; ##-- be happy
95  
96 __END__