Algorithm-HowSimilar
view release on metacpan or search on metacpan
HowSimilar.pm view on Meta::CPAN
39404142434445464748495051525354555657585960
else
{
$seq1
= _tokenize(
$_
[0]);
$seq2
= _tokenize(
$_
[1]);
}
my
(
$match
,
$d1
,
$d2
) = (
''
,
''
,
''
);
traverse_sequences(
$seq1
,
$seq2
, {
MATCH
=>
sub
{
$match
.=
$seq1
->[
$_
[0]] },
DISCARD_A
=>
sub
{
$d1
.=
$seq1
->[
$_
[0]] },
DISCARD_B
=>
sub
{
$d2
.=
$seq2
->[
$_
[1]] },
});
my
$m1
=
length
(
$match
)/(
length
(
$match
)+
length
(
$d1
));
my
$m2
=
length
(
$match
)/(
length
(
$match
)+
length
(
$d2
));
my
$mav
= (
$m1
+
$m2
)/2;
return
$mav
,
$m1
,
$m2
,
$match
,
$d1
,
$d2
;
}
}
sub
_tokenize {
return
[
split
//,
$_
[0]] }
1;
__END__
HowSimilar.pm view on Meta::CPAN
84858687888990919293949596979899100101102103104
my
(
$av_similarity
,
$sim_str1_to_str2
,
$sim_str2_to_str1
,
$matches
,
$in_str1_but_not_str2
,
$in_str2_but_not_str1
) = compare(
'this is a string-a'
,
'this is a string bbb'
);
Note that the mathematical similarities of one string to another will be
different
unless
the strings have the same
length
. The first result returned
is the average similarity. Totally dissimilar strings will
return
0. Identical
strings will
return
1. The degree of similarity therefore ranges from 0-1 and
is reported as the biggest float your OS/Perl can manage.
You can also compare two array refs compare( \
@ary1
, \
@ary2
):
my
(
$av_similarity
,
$sim_ary1_to_ary2
,
$sim_ary2_to_ary1
,
$ref_ary_matches
,
html/HowSimilar.html view on Meta::CPAN
575859606162636465666768697071727374757677<P>You can call compare
with
either two strings compare(
$str1
,
$str2
):</P>
<PRE>
my
(
$av_similarity
,
$sim_str1_to_str2
,
$sim_str2_to_str1
,
$matches
,
$in_str1_but_not_str2
,
$in_str2_but_not_str1
) = compare(
'this is a string-a'
,
'this is a string bbb'
);</PRE>
<P>Note that the mathematical similarities of one string to another will be
different
unless
the strings have the same
length
. The first result returned
is the average similarity. Totally dissimilar strings will
return
0. Identical
strings will
return
1. The degree of similarity therefore ranges from 0-1 and
is reported as the biggest float your OS/Perl can manage.</P>
<P>You can also compare two array refs compare( \
@ary1
, \
@ary2
):</P>
<PRE>
my
(
$av_similarity
,
$sim_ary1_to_ary2
,
$sim_ary2_to_ary1
,
$ref_ary_matches
,
$ref_ary_in_ary1_but_not_ary2
,
misc/make_manifest.pl view on Meta::CPAN
454647484950515253545556575859606162636465fix_line_endings(
$_
)
for
@files
;
# remove all the makefile/make rubbish
sub
make_clean {
my
$root
=
shift
;
my
(
$dirs
,
$files
) = recurse_tree(
$root
.
"blib/"
);
my
@dirs
=
@$dirs
;
my
@files
=
@$files
;
unlink
for
@files
;
# need to do longest dir paths first - must be deepest
rmdir
for
sort
{
length
$b
<=>
length
$a
}
@dirs
;
my
@makefiles
=
grep
{ /makefile(?!\.PL)/i } <
$root
*>;
unlink
for
(
@makefiles
,
$root
.
'&1'
,
$root
.
'pm_to_blib'
,
$root
.
'MANIFEST'
,
$root
.
'manifest'
);
unlink
<${root}pod2htm*>;
}
# recurse the directory tree
sub
recurse_tree {
my
$root
=
shift
;
my
@files
;
my
@dirs
= (
$root
);
( run in 0.608 second using v1.01-cache-2.11-cpan-95122f20152 )