$precision = $feature_found / $rank;
####
$precision = eval {
$feature_found ? $rank / $feature_found : 0; };
####
#!/usr/bin/perl
use strict;
use autodie;
use Devel::SimpleTrace;
use Data::Dumper::Concise;
my $input = shift @ARGV;
my $input_bless = '';
my $log = '/root/Desktop/log.txt';
die $! unless open IN, '<', $input;
die $! unless open OUT, '>', $log;
my %matrice;
while ( defined( $_ = ) ) {
my ( $rank, $nome, $relaz, $entry2, $score ) = split( ' ', $_, 6 );
push @{ $matrice{$nome}; }, "${relaz}_$entry2,$rank,$score";
}
my %HOH;
while ( my ( $name, $aref ) = each %matrice ) {
do {
foreach my $item (@$aref) {
my ( $prop, $rank, $score ) = split( /,/, $item, 4 );
$HOH{$name}{$prop} = "$rank,$score" || 0;
}
};
}
die unless open INB, '<', $input;
while ( defined( $_ = ) ) {
my ( $u, $superclass, $rel, $v ) = (
split( ' ', $_, 0 ) )[ 0, 1, 2, 3 ];
my $conteggio = &calcolo( $u, $v );
print OUT "$u" . "\t" . $rel . "\t" . $v . "\t" . $conteggio;
}
sub calcolo {
my ( $name1, $name2 ) = @_;
my $first = $HOH{$name1};
my $second = $HOH{$name2};
my ( $rank_fv, $score_fv );
my $rank_v;
my $count_feat_fv;
my $provaprec = 0;
my $proptoexamine;
my $count_feat_rel;
my $precision;
my $rel_par;
my $num = 0;
my $count_feat_fu;
my $apinc;
my $rank2 = 0;
my ( $prop, $score );
my $rank = 0;
my $feature_found = 0;
my $feat_finale;
my $rel_to_sum;
while ( my ( $name1, $aref ) = each %matrice ) {
++$count_feat_fu;
$num = 0;
my $feat_rel = 0;
foreach my $item (@$aref) {
( $prop, $rank, $score ) = split( /,/, $item, 4 );
$feat_finale = &last_el_v( $name2, $prop );
while ( my ( $prop1, $rankscore1 ) = each %$second ) {
($rank_fv, $score_fv ) = split( /,/, $rankscore1, 3);
if ( $prop1 eq $prop ) {
++$feature_found;
print 'PROP:' . $prop . "\n";
print "TROVATO" . "\n";
++$feat_rel;
$rank2 = $rank_fv;
print 'RANK 2:' . $rank2 . "\n";
print 'RANK 1: ' . $rank . "\n";
print 'COUNT FEAT FOUND: ' . $feature_found . "\n";
$precision = eval {
$feature_found ? $rank / $feature_found : 0; };
print 'PRECISION: ' . $precision . "\n";
$rel_par = $rank2 / ( $feat_finale + 1 );
$rel_to_sum = 1 - $rel_par;
print 'FEAT FINALE: ' . $feat_finale . "\n";
print 'REL PAR: ' . $rel_par . "\n";
my $tosum = $precision * $rel_to_sum;
print 'TO SUM: ' . $tosum . "\n";
$num = $num + $tosum;
print 'NUM: ' . $num . "\n";
}
};
}
print 'RANK: ' . $rank . "\n";
$apinc = eval { $num ? $rank / $num : 0; };
print 'APINC: ' . $apinc . "\n";
return $apinc;
};
}
sub last_el_v {
my ( $name2, $prop1 ) = @_;
my $second = $HOH{$name2};
my $count_feat_fv;
while ( my ( $prop1, $rankscore1 ) = each %$second ) {
++$count_feat_fv;
};
return $count_feat_fv;
}
close IN;
close INB;
close OUT;