Hi everyone.
I have a new question. I've written some code and I need to modify it in order to make it work with a new input I have. My code was a simple one, used to compute Average Precision on some data.
Now my data has changed because I have a list like the following. I need for it to work on separate elements, so to say, I need it to compute Average precision for different element.
My input is the following:

1 acacia-n hyper tree-n 0.838364743354488 2 acacia-n hyper plant-n 0.740581661563839 3 acacia-n mero wood-n 0.687569086370938 4 acacia-n mero flower-n 0.650909477491374 5 acacia-n coord oak-n 0.610092594991099 6 acacia-n coord pine-n 0.537690234715029 7 acacia-n mero branch-n 0.510899195919917 8 acacia-n mero root-n 0.491198721010063 9 acacia-n coord willow-n 0.481680704877001 1 ant-n hyper animal-n 0.634580215370739 2 ant-n hyper insect-n 0.53621081509255 3 ant-n mero head-n 0.535980012877533 4 ant-n mero body-n 0.505827598873949 5 ant-n coord bee-n 0.481918895790599 1 apricot-n hyper fruit-n 0.76748797529242 2 apricot-n coord apple-n 0.685155565667883 3 apricot-n mero juice-n 0.560337418489082 4 apricot-n coord banana-n 0.559525300446683

My output (given that I compute AP for hyper) should be like the following:

acacia-n hyper 1 ant-n hyper 1 apricot-n hyper 1

I've picked lucky cases in which AP is 1!
My code at the moment is the following:

my $conteggio_trovato=0; my $conteggio_hyper=0; my $precision_glob=0; my $precision=0; my $average_precision=0; my ($rank, $u, $relaz, $v, $score); while (<INPUT>) { ($rank, $u, $relaz, $v, $score) = split; if ($relaz eq "hyper"){ print "REl:".$relaz; $conteggio_hyper++; my $precision = $conteggio_trovato/$rank; print "precision:".$precision."\n"; $precision_glob=$precision_glob+$precision; } $conteggio_trovato++; # $precision_glob=$precision_glob+$precision; } #$precision_glob=$precision_glob+$precision; $average_precision=$precision_glob/$conteggio_hyper; #print "precision totale: ".$precision_glob."\n"; #print "Conteggio: ".$conteggio_hyper."\n"; print $u."\t"."hyper"."\t".$average_precision."\n";

How can I modify it?
Thanks!
Giulia </code>


In reply to Iterate over multiple data by remluvr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.