| 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
Condition100%2/3
ref $class || $class
MC/DC100%0/2
ref $class || $class
ref $class
$class
Truth table100%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | 'build' => sub { $_[0] ? ' --build' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | 'd' => sub { $_[0] ? ' --database' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | 'database' => sub { $_[0] ? ' --database' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | 'u' => sub { $_[0] ? ' --unicode' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | 'unicode' => sub { $_[0] ? ' --unicode' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | 'm' => sub { $_[0] ? ' --mark' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | 'mark' => sub { $_[0] ? ' --mark' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$_[0] and $_[0] =~ /^[1-9][0-9]*$/x
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
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$_[0] and $_[0] =~ /^[1-9][0-9]*$/x
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
| |||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | 's' => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | ($_[0] && $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[0] and $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
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)$/
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$_[0] and $_[0] =~ /^(exact|dice|cosine|jaccard|overlap)$/
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)$/
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$_[0] and $_[0] =~ /^(?:0\.[0-9]+|1)$/x
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
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$_[0] and $_[0] =~ /^(?:0\.[0-9]+|1)$/x
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
| |||||||||||||||||||||||||||||||||
| 61 | }, | ||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | 'e' => sub { $_[0] ? ' --echo-back' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | 'echo-back' => sub { $_[0] ? ' --echo-back' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | 'q' => sub { $_[0] ? ' --quiet' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | 'quiet' => sub { $_[0] ? ' --quiet' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | 'p' => sub { $_[0] ? ' --benchmark' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | 'benchmark' => sub { $_[0] ? ' --benchmark' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | 'v' => sub { $_[0] ? ' --version' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | 'version' => sub { $_[0] ? ' --version' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | 'h' => sub { $_[0] ? ' --help' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | 'help' => sub { $_[0] ? ' --help' : '';}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $attributes->{$option} and $options->{$option}
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}
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||