blib/lib/SimString/Wrapper.pm

filter: Statementstmt 91.0% 51 / 56 Branchbran 51.8% 28 / 54 Conditioncond 37.5% 8 / 24 (1 uncoverable) MC/DCmcdc 12.5% 0 / 16 (2 uncoverable) Subroutinesub 96.6% 29 / 30 Podpod 0.0% 0 / 2 totaltotal 65.3% 116 / 182 (3 uncoverable) CC 37 SCAR 11.8
CC
37
Cov
66%
__ANON__
12.0
_options
5.1
__ANON__
4.1
CRAP 3.3
↑ Summary
1 package SimString::Wrapper;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our $VERSION = '0.03';
7  
8 #use FileHandle;
9 #use IPC::Open2;
10  
11 5 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
12 5 my $class = shift;
13 # uncoverable condition false
14 5 ▶ bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 3 2 5
@_ > 1 ? : 1 2 3
Condition100%2/3
ref $class || $class
l!l&&r!l&&!r
410
MC/DC100%0/2
ref $class || $class
ref $class $class
Truth table100%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
15 }
16  
17 1 ▶sub simstring {
Subroutine simstring: called CC=1 SCAR=0.5
Pod undocumented
18 1 my $self = shift;
19  
20 1 my $query = shift;
21 1 my $database = shift;
22 1 my $threshold = shift;
23  
24 # my $pid = open2(*Reader, *Writer, "simstring -d ../sample/names.2");
25 # print Writer "$query\n";
26 # my $got = <Reader>;
27  
28 1 open( my $reader, "echo $query | simstring -d $database -t $threshold -q|");
29 1 my @got = <$reader>;
30 0 return map { chomp($_);$_ =~ s/^\s+//;$_ } @got;
31 0 return @got;
32 }
33  
34 29 ▶sub _options {
Subroutine _options: called CC=4 SCAR=16.3
35 29 my $self = shift;
36 29 my $options = shift;
37 my $attributes = {
38 1 ▶ 'b' => sub { $_[0] ? ' --build' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
39 1 ▶ 'build' => sub { $_[0] ? ' --build' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
40 1 ▶ 'd' => sub { $_[0] ? ' --database' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
41 1 ▶ 'database' => sub { $_[0] ? ' --database' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
42 2 ▶ 'u' => sub { $_[0] ? ' --unicode' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 2 0 2
43 1 ▶ 'unicode' => sub { $_[0] ? ' --unicode' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
44 1 ▶ 'm' => sub { $_[0] ? ' --mark' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
45 1 ▶ 'mark' => sub { $_[0] ? ' --mark' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
46 2 ▶ 'n' => sub { ($_[0] && $_[0] =~ m/^[1-9][0-9]*$/x ) ? ' --ngram='.$_[0] : '';},
Subroutine __ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && $_[0] =~ /^[1-9][0-9]*$/x ? : 2 0 2
Condition33%1/3
$_[0] and $_[0] =~ /^[1-9][0-9]*$/x
!ll&&!rl&&r
002
MC/DC0%0/2
$_[0] and $_[0] =~ /^[1-9][0-9]*$/x
$_[0] $_[0] =~ /^[1-9][0-9]*$/x
Truth table33%1/3
A and B
A= $_[0]B= $_[0] =~ /^[1-9][0-9]*$/x
ABresult
0X0
100
111
47 0 ▶ 'ngram' => sub { ($_[0] && $_[0] =~ m/^[1-9][0-9]*$/x ) ? ' --ngram='.$_[0] : '';},
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && $_[0] =~ /^[1-9][0-9]*$/x ? : 0 0 0
Condition0%0/3
$_[0] and $_[0] =~ /^[1-9][0-9]*$/x
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and $_[0] =~ /^[1-9][0-9]*$/x
$_[0] $_[0] =~ /^[1-9][0-9]*$/x
Truth table0%0/3
A and B
A= $_[0]B= $_[0] =~ /^[1-9][0-9]*$/x
ABresult
0X0
100
111
48 1 ▶ 's' => sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
49 1 ▶ ($_[0] && $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/)
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/ ? : 1 0 1
Condition33%1/3
$_[0] and $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
!ll&&!rl&&r
001
MC/DC0%0/2
$_[0] and $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
$_[0] $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
Truth table33%1/3
A and B
A= $_[0]B= $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
ABresult
0X0
100
111
50 ? ' --similarity='.$_[0] : '';
51 },
52 5 ▶ 'similarity' => sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
53 5 ▶ ($_[0] && $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/)
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/ ? : 5 0 5
Condition33%1/3
$_[0] and $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
!ll&&!rl&&r
005
MC/DC0%0/2
$_[0] and $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
$_[0] $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
Truth table33%1/3
A and B
A= $_[0]B= $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
ABresult
0X0
100
111
54 ? ' --similarity='.$_[0] : '';
55 },
56 2 ▶ 't' => sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
57 2 ▶ ($_[0] && $_[0] =~ m/^(?:0\.[0-9]+|1)$/x ) ? ' --threshold='.$_[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && $_[0] =~ /^(?:0\.[0-9]+|1)$/x ? : 2 0 2
Condition33%1/3
$_[0] and $_[0] =~ /^(?:0\.[0-9]+|1)$/x
!ll&&!rl&&r
002
MC/DC0%0/2
$_[0] and $_[0] =~ /^(?:0\.[0-9]+|1)$/x
$_[0] $_[0] =~ /^(?:0\.[0-9]+|1)$/x
Truth table33%1/3
A and B
A= $_[0]B= $_[0] =~ /^(?:0\.[0-9]+|1)$/x
ABresult
0X0
100
111
58 },
59 1 ▶ 'threshold' => sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
60 1 ▶ ($_[0] && $_[0] =~ m/^(?:0\.[0-9]+|1)$/x ) ? ' --threshold='.$_[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && $_[0] =~ /^(?:0\.[0-9]+|1)$/x ? : 1 0 1
Condition33%1/3
$_[0] and $_[0] =~ /^(?:0\.[0-9]+|1)$/x
!ll&&!rl&&r
001
MC/DC0%0/2
$_[0] and $_[0] =~ /^(?:0\.[0-9]+|1)$/x
$_[0] $_[0] =~ /^(?:0\.[0-9]+|1)$/x
Truth table33%1/3
A and B
A= $_[0]B= $_[0] =~ /^(?:0\.[0-9]+|1)$/x
ABresult
0X0
100
111
61 },
62 1 ▶ 'e' => sub { $_[0] ? ' --echo-back' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
63 1 ▶ 'echo-back' => sub { $_[0] ? ' --echo-back' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
64 1 ▶ 'q' => sub { $_[0] ? ' --quiet' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
65 1 ▶ 'quiet' => sub { $_[0] ? ' --quiet' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
66 1 ▶ 'p' => sub { $_[0] ? ' --benchmark' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
67 1 ▶ 'benchmark' => sub { $_[0] ? ' --benchmark' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
68 1 ▶ 'v' => sub { $_[0] ? ' --version' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
69 1 ▶ 'version' => sub { $_[0] ? ' --version' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
70 1 ▶ 'h' => sub { $_[0] ? ' --help' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
71 1 ▶ 'help' => sub { $_[0] ? ' --help' : '';},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 1 0 1
72  
73 29 };
74 29 $self->{options} = '';
75 29 for my $option (sort keys %$options) {
76 30 ▶ if (exists $attributes->{$option} && $options->{$option}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attributes->{$option} and $options->{$option}) 30 0 30
Condition33%1/3
exists $attributes->{$option} and $options->{$option}
!ll&&!rl&&r
0030
MC/DC0%0/2
exists $attributes->{$option} and $options->{$option}
exists $attributes->{$option} $options->{$option}
Truth table33%1/3
A and B
A= exists $attributes->{$option}B= $options->{$option}
ABresult
0X0
100
111
77 30 $self->{options} .= $attributes->{$option}->($options->{$option});
78 }
79 }
80 29 return $self->{options};
81 }
82  
83 =pod
84  
85 -b, --build build a database for strings read from STDIN
86 -d, --database=DB specify a database file
87 -u, --unicode use Unicode (wchar_t) for representing characters
88 -n, --ngram=N specify the unit of n-grams (DEFAULT=3)
89 -m, --mark include marks for begins and ends of strings
90 -s, --similarity=SIM specify a similarity measure (DEFAULT='cosine'):
91 exact exact match
92 dice dice coefficient
93 cosine cosine coefficient
94 jaccard jaccard coefficient
95 overlap overlap coefficient
96 -t, --threshold=TH specify the threshold (DEFAULT=0.7)
97 -e, --echo-back echo back query strings to the output
98 -q, --quiet suppress supplemental information from the output
99 -p, --benchmark show benchmark result (retrieved strings are suppressed)
100 -v, --version show this version information and exit
101 -h, --help show this help message and exit
102  
103  
104 =cut
105  
106 2 1;
107  
108 __END__
↑ Summary