CAB/Analyzer/EqLemma/JsonCDB.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 58 CC 5 SCAR 22.3
CC
5
Cov
0%
analyzeSentences
20.0
doAnalyze
6.0
new
2.0
CRAP 9.3
1 ## -*- Mode: CPerl -*-
2 ##
3 ## File: DTA::CAB::Analyzer::EqLemma::JsonCDB.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: DB dictionary-based equivalence-class expander, rewrite variant
6  
7 package DTA::CAB::Analyzer::EqLemma::JsonCDB;
8 use DTA::CAB::Analyzer ':child';
9 use DTA::CAB::Analyzer::Dict::JsonCDB;
10 use strict;
11  
12 ##==============================================================================
13 ## Globals
14 ##==============================================================================
15 our @ISA = qw(DTA::CAB::Analyzer::Dict::JsonCDB);
16  
17 ##==============================================================================
18 ## Constructors etc.
19 ##==============================================================================
20  
21 ## $obj = CLASS_OR_OBJ->new(%args)
22 ## + object structure: see DTA::CAB::Analyzer::Dict::CDB
23 sub new {
24 my $that = shift;
25 return $that->SUPER::new(
26 ##-- options
27 label => 'eqlemma',
28 ##-- user args
29 @_
30 );
31 }
32  
33  
34 ##========================================================================
35 ## analysis overrides
36  
37 ## $bool = $anl->doAnalyze(\%opts, $name)
38 sub doAnalyze {
39 my $anl = shift;
40 return 0 if ($_[1] eq 'Types');
41 return $anl->SUPER::doAnalyze(@_);
42 }
43  
44 ## $doc = $anl->analyzeTypes($doc,\%types,\%opts)
45 ## + perform type-wise analysis of all (text) types in $doc->{types}
46 ## + override does nothing
47 sub analyzeTypes { return $_[1]; }
48  
49 ## $doc = $anl->analyzeSentences($doc,\%opts)
50 ## + perform sentence-wise analysis of all sentences $doc->{body}[$si]
51 ## + expand lemma equivalence
52 sub analyzeSentences {
53 my ($anl,$doc,$opts) = @_;
54  
55 ##-- common vars
56 my $lab = $anl->{label};
57 my $tied = $anl->{dbf}{tied};
58 my $jxs = $anl->jsonxs;
59  
60 ##-- map by moot lemmata
61 my $l2eql = {}; ##-- $l2eql = {$lemma => \@eqlemma, ...}; cache
62 my ($l,$eqls);
63 foreach (map {@{$_->{tokens}}} @{$doc->{body}}) {
64 next if (!$_->{moot} || !defined($l=$_->{moot}{lemma}));
65 if (exists($l2eql->{$l})) {
66 $_->{$lab} = $l2eql->{$l};
67 next;
68 }
69 $_->{$lab} = $l2eql->{$l} = defined($eqls=$tied->FETCH($l)) ? $jxs->decode($eqls) : [$l];
70 }
71  
72 ##-- return
73 return $doc;
74 }
75  
76  
77 1; ##-- be happy
78  
79 __END__