line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SimString::Wrapper; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
15342
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
59
|
|
5
|
2
|
|
|
2
|
|
55
|
use 5.008_005; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1629
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#use FileHandle; |
9
|
|
|
|
|
|
|
#use IPC::Open2; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
5
|
|
|
5
|
0
|
748
|
my $class = shift; |
13
|
|
|
|
|
|
|
# uncoverable condition false |
14
|
5
|
100
|
66
|
|
|
39
|
bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; |
|
2
|
100
|
|
|
|
18
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub simstring { |
18
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
3
|
my $query = shift; |
21
|
1
|
|
|
|
|
2
|
my $database = shift; |
22
|
1
|
|
|
|
|
5
|
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
|
1
|
|
|
|
|
1714
|
open( my $reader, "echo $query | simstring -d $database -t $threshold -q|"); |
29
|
1
|
|
|
|
|
1334
|
my @got = <$reader>; |
30
|
1
|
|
|
|
|
75
|
return map { chomp($_);$_ =~ s/^\s+//;$_ } @got; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
31
|
0
|
|
|
|
|
0
|
return @got; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _options { |
35
|
29
|
|
|
29
|
|
171
|
my $self = shift; |
36
|
29
|
|
|
|
|
30
|
my $options = shift; |
37
|
|
|
|
|
|
|
my $attributes = { |
38
|
1
|
50
|
|
1
|
|
14
|
'b' => sub { $_[0] ? ' --build' : '';}, |
39
|
1
|
50
|
|
1
|
|
6
|
'build' => sub { $_[0] ? ' --build' : '';}, |
40
|
1
|
50
|
|
1
|
|
6
|
'd' => sub { $_[0] ? ' --database' : '';}, |
41
|
1
|
50
|
|
1
|
|
4
|
'database' => sub { $_[0] ? ' --database' : '';}, |
42
|
2
|
50
|
|
2
|
|
10
|
'u' => sub { $_[0] ? ' --unicode' : '';}, |
43
|
1
|
50
|
|
1
|
|
4
|
'unicode' => sub { $_[0] ? ' --unicode' : '';}, |
44
|
1
|
50
|
|
1
|
|
5
|
'm' => sub { $_[0] ? ' --mark' : '';}, |
45
|
1
|
50
|
|
1
|
|
5
|
'mark' => sub { $_[0] ? ' --mark' : '';}, |
46
|
2
|
50
|
33
|
2
|
|
27
|
'n' => sub { ($_[0] && $_[0] =~ m/^[1-9][0-9]*$/x ) ? ' --ngram='.$_[0] : '';}, |
47
|
0
|
0
|
0
|
0
|
|
0
|
'ngram' => sub { ($_[0] && $_[0] =~ m/^[1-9][0-9]*$/x ) ? ' --ngram='.$_[0] : '';}, |
48
|
|
|
|
|
|
|
's' => sub { |
49
|
1
|
50
|
33
|
1
|
|
15
|
($_[0] && $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/) |
50
|
|
|
|
|
|
|
? ' --similarity='.$_[0] : ''; |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
'similarity' => sub { |
53
|
5
|
50
|
33
|
5
|
|
105
|
($_[0] && $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/) |
54
|
|
|
|
|
|
|
? ' --similarity='.$_[0] : ''; |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
't' => sub { |
57
|
2
|
50
|
33
|
2
|
|
52
|
($_[0] && $_[0] =~ m/^(?:0\.[0-9]+|1)$/x ) ? ' --threshold='.$_[0] : ''; |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
'threshold' => sub { |
60
|
1
|
50
|
33
|
1
|
|
15
|
($_[0] && $_[0] =~ m/^(?:0\.[0-9]+|1)$/x ) ? ' --threshold='.$_[0] : ''; |
61
|
|
|
|
|
|
|
}, |
62
|
1
|
50
|
|
1
|
|
4
|
'e' => sub { $_[0] ? ' --echo-back' : '';}, |
63
|
1
|
50
|
|
1
|
|
6
|
'echo-back' => sub { $_[0] ? ' --echo-back' : '';}, |
64
|
1
|
50
|
|
1
|
|
5
|
'q' => sub { $_[0] ? ' --quiet' : '';}, |
65
|
1
|
50
|
|
1
|
|
6
|
'quiet' => sub { $_[0] ? ' --quiet' : '';}, |
66
|
1
|
50
|
|
1
|
|
4
|
'p' => sub { $_[0] ? ' --benchmark' : '';}, |
67
|
1
|
50
|
|
1
|
|
7
|
'benchmark' => sub { $_[0] ? ' --benchmark' : '';}, |
68
|
1
|
50
|
|
1
|
|
4
|
'v' => sub { $_[0] ? ' --version' : '';}, |
69
|
1
|
50
|
|
1
|
|
11
|
'version' => sub { $_[0] ? ' --version' : '';}, |
70
|
1
|
50
|
|
1
|
|
1152
|
'h' => sub { $_[0] ? ' --help' : '';}, |
71
|
1
|
50
|
|
1
|
|
4
|
'help' => sub { $_[0] ? ' --help' : '';}, |
72
|
|
|
|
|
|
|
|
73
|
29
|
|
|
|
|
1015
|
}; |
74
|
29
|
|
|
|
|
74
|
$self->{options} = ''; |
75
|
29
|
|
|
|
|
106
|
for my $option (sort keys %$options) { |
76
|
30
|
50
|
33
|
|
|
141
|
if (exists $attributes->{$option} && $options->{$option}) { |
77
|
30
|
|
|
|
|
59
|
$self->{options} .= $attributes->{$option}->($options->{$option}); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
29
|
|
|
|
|
636
|
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
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |