in reply to term frequency and mutual info
The split into words is very naive and you will have to look into it. Perhaps first discarding punctuation and the like. Still the idea should be clear.use strict; use warnings; use 5.012; use Data::Dumper; my @file1 = ( 'this is an example.', 'the example is just for display.', 'how to solve it in an efficient way?', ); my @file2 = ( 'este es un ejemplo.', 'el ejemplo es sólo para mostrar.', 'cómo resolverlo de una manera eficiente?', ); say Dumper(parse(@file1)); say Dumper(parse(@file2)); sub parse { my @sentences = @_; my %words_catalogue; my $line = 1; for my $sentence (@sentences) { my @words = split ' ', $sentence; $words_catalogue{$_}{$line}++ for @words; $line++; } return \%words_catalogue; }
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: term frequency and mutual info
by perl_lover_always (Acolyte) on Oct 22, 2010 at 08:28 UTC |