在perl中对数组使用编辑距离 [英] use edit distance on arrays in perl
本文介绍了在perl中对数组使用编辑距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试比较两个数组之间的编辑距离.我尝试使用Text:Levenshtein.
I am attempting to compare the edit distance between two arrays. I have tried using Text:Levenshtein.
#!/usr/bin/perl -w
use strict;
use Text::Levenshtein qw(distance);
my @words = qw(four foo bar);
my @list = qw(foo fear);
my @distances = distance(@list, @words);
print "@distances\n";
#results: 3 2 0 3
但是我希望结果显示如下:
I however want the results to appear as follows:
2 0 3
2 3 2
通过@words数组获取@list的第一个元素,并在@list的其余元素中进行相同的操作. 我计划将其扩展到更大的数组.
Taking the first element of @list through the array of @words and doing the same through out the rest of the elements of @list. I plan on upscaling this to a much larger arrays.
推荐答案
我不确定您的意思到底是什么,但是我认为这就是您的期望:
I'm not sure to understand exactly what you meant, but I think this is what you expect :
#!/usr/bin/perl -w
use strict;
use Text::Levenshtein qw(distance);
my @words = qw(four foo bar);
my @list = qw(foo fear);
foreach my $word (@list) {
my @distances = distance($word, @words);
print "@distances\n";
}
这篇关于在perl中对数组使用编辑距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文