my @a = ('church.n.01','church.n.02','church_service.n.01','church.n.04');
my @b = ('temple.n.01','temple.n.02','temple.n.03','synagogue.n.01');
use Data::Dumper;
print Dumper [ get_relatedness(\@a, \@b) ];
sub get_relatedness {
my ($c, $d) = @_;
return map { my $t=$_; map [$t, $_], @$d } @$c;
}
輸出
$VAR1 = [
[
'church.n.01',
'temple.n.01'
],
[
'church.n.01',
'temple.n.02'
],
[
'church.n.01',
'temple.n.03'
],
[
'church.n.01',
'synagogue.n.01'
],
[
'church.n.02',
'temple.n.01'
],
[
'church.n.02',
'temple.n.02'
],
[
'church.n.02',
'temple.n.03'
],
[
'church.n.02',
'synagogue.n.01'
],
[
'church_service.n.01',
'temple.n.01'
],
[
'church_service.n.01',
'temple.n.02'
],
[
'church_service.n.01',
'temple.n.03'
],
[
'church_service.n.01',
'synagogue.n.01'
],
[
'church.n.04',
'temple.n.01'
],
[
'church.n.04',
'temple.n.02'
],
[
'church.n.04',
'temple.n.03'
],
[
'church.n.04',
'synagogue.n.01'
]
];
如何在此處定義相關性? – Vijay
@Vijay:該問題將「查找相關性」定義爲「調用函數get_relatedness(arg1,arg2)」。這個問題是可以回答的,不需要知道該函數內發生了什麼。 –