#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @results = (["chpt10_2", "sent. 2", "alice", "nsubj", "animals", "protect"], ["chpt12_1", "sent. 54", "bob", "nsubj", "cells", "protect"], ["chpt25_4", "sent. 47", "carol", "nsubj", "plants", "protect"], ["chpt34_1", "sent. 1", "dave", "nsubj", "cells", "protect"], ["chpt35_1", "sent. 2", "eli", "nsubj", "cells", "protect"], ["chpt38_1", "sent. 1", "fred", "nsubj", "animals", "protect"], ["chpt54_1", "sent. 1", "greg", "nsubj", "uticle", "protect"] ); my @sort_results = sort {lc $a->[4] cmp lc $b->[4]} @results; ##By alphabet of arg1 my $last_word; my $current_word; my $word_count; $sort_results[-1][6] = 1; ##This weird step is b/c last element didn't get 7th column appended for my $j (0 .. $#sort_results) { ##[ROW][COLUMN] $current_word = $sort_results[$j][4]; ## current word is arg1 of whichever matchset is being looked at (alphabetical) if (lc $last_word eq lc $current_word) { $word_count++; ##If seen before, increment freq. count } else { ##new word if ($j != 0) ##unless it's the first row { for (my $k = 1; $k <= $word_count; $k++) { ##make a new column with freq. Each of the previous seen word will have to have the same freq. number so iterate back and make them all the same word count $sort_results[($j-$k)][6] = $word_count; } } ##Now set up for next iteration $last_word = $current_word; $word_count = 1; } } @sort_results = sort {$b->[6] <=> $a->[6]} @sort_results; ##Sort the results by the new 7th freq. column for my $i (0 .. $#sort_results) { print "$sort_results[$i][0], $sort_results[$i][1]: "; ##chptnum, sent num print "$sort_results[$i][2]\n\n"; ##sentence print "gramatical relation: $sort_results[$i][3]; argument: $sort_results[$i][4]; freq: $sort_results[$i][6]\n\n\n"; ##dependency args }