File Coverage

blib/lib/SimString/Wrapper.pm
Criterion Covered Total %
statement 24 38 63.1
branch 9 28 32.1
condition 6 21 33.3
subroutine 9 17 52.9
pod 0 2 0.0
total 48 106 46.2


line stmt bran cond sub pod time code
1             package SimString::Wrapper;
2              
3 2     2   45183 use strict;
  2         5  
  2         73  
4 2     2   10 use warnings;
  2         3  
  2         56  
5 2     2   74 use 5.008_005;
  2         5  
  2         1699  
6             our $VERSION = '0.02';
7              
8             #use FileHandle;
9             #use IPC::Open2;
10              
11             sub new {
12 5     5 0 848 my $class = shift;
13             # uncoverable condition false
14 5 100 66     35 bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
  2 100       13  
15             }
16              
17             sub simstring {
18 0     0 0 0 my $self = shift;
19            
20 0         0 my $query = shift;
21 0         0 my $database = shift;
22 0         0 my $threshold = shift;
23            
24             # my $pid = open2(*Reader, *Writer, "simstring -d ../sample/names.2");
25             # print Writer "$query\n";
26             # my $got = ;
27              
28 0         0 open( my $reader, "echo $query | simstring -d $database -t $threshold -q|");
29 0         0 my @got = <$reader>;
30              
31 0         0 return @got;
32              
33             }
34              
35             sub _options {
36 6     6   8 my $self = shift;
37 6         7 my $options = shift;
38             my $attributes = {
39 0 0   0   0 'b' => sub { $_[0] ? ' --build' : '';},
40 0 0   0   0 'build' => sub { $_[0] ? ' --build' : '';},
41 2 50   2   11 'u' => sub { $_[0] ? ' --unicode' : '';},
42 0 0   0   0 'unicode' => sub { $_[0] ? ' --unicode' : '';},
43 0 0   0   0 'm' => sub { $_[0] ? ' --mark' : '';},
44 0 0   0   0 'mark' => sub { $_[0] ? ' --mark' : '';},
45 2 50 33 2   20 'n' => sub { ($_[0] && $_[0] =~ m/^[1-9][0-9]*$/x ) ? ' --ngram='.$_[0] : '';},
46 0 0 0 0   0 'ngram' => sub { ($_[0] && $_[0] =~ m/^[1-9][0-9]*$/x ) ? ' --ngram='.$_[0] : '';},
47             's' => sub {
48 0 0 0 0   0 ($_[0] && $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/)
49             ? ' --similarity='.$_[0] : '';
50             },
51             'similarity' => sub {
52 1 50 33 1   13 ($_[0] && $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/)
53             ? ' --similarity='.$_[0] : '';
54             },
55             't' => sub {
56 2 50 33 2   30 ($_[0] && $_[0] =~ m/^(?:0\.[0-9]+|1)$/x ) ? ' --threshold='.$_[0] : '';
57             },
58            
59            
60 6         105 };
61 6         13 $self->{options} = '';
62 6         22 for my $option (sort keys %$options) {
63 7 50 33     38 if (exists $attributes->{$option} && $options->{$option}) {
64 7         18 $self->{options} .= $attributes->{$option}->($options->{$option});
65             }
66             }
67 6         95 return $self->{options};
68             }
69              
70             =pod
71              
72             -b, --build build a database for strings read from STDIN
73             -d, --database=DB specify a database file
74             -u, --unicode use Unicode (wchar_t) for representing characters
75             -n, --ngram=N specify the unit of n-grams (DEFAULT=3)
76             -m, --mark include marks for begins and ends of strings
77             -s, --similarity=SIM specify a similarity measure (DEFAULT='cosine'):
78             exact exact match
79             dice dice coefficient
80             cosine cosine coefficient
81             jaccard jaccard coefficient
82             overlap overlap coefficient
83             -t, --threshold=TH specify the threshold (DEFAULT=0.7)
84             -e, --echo-back echo back query strings to the output
85             -q, --quiet suppress supplemental information from the output
86             -p, --benchmark show benchmark result (retrieved strings are suppressed)
87             -v, --version show this version information and exit
88             -h, --help show this help message and exit
89              
90              
91             =cut
92              
93             1;
94              
95             __END__