in reply to Removing common words
Here's somewhere to start. Completely untested code, I just threw this together in the reply textarea :). It may not work at all or it may have glitches. Give it a shot if you will, change whatever you may wish. I'd say that the definition of a "word" your regex uses could use some fixing.
my @banned = qw( a at be for and to of in the as i it are is am on an you me ); push( @banned, 0..10, 'a'..'z' ); my %banned; @banned{@banned} = undef; for my $file (0 .. 20000) { open( my $in, '<', '/var/www/data/' . $file . '.txt' ) or die "open failed: $!"; open( my $out, '>', '/var/www/sorted/' . $file . '.txt' ) or die "open failed: $!"; my %seen; while ( chomp( my $line = <$in> ) ) { for my $word ( split( /\W/, $line ) ) { $word = lc( $word ); ++$seen{$word} if ( exists( $banned{$word} ) ); } } my @frequent = ( sort { $seen{$b} <=> $seen{$a} } keys %seen )[0..50]; print $out join("\n", @frequent); close( $in ) or die "close failed: $!"; close( $out ) or die "close failed: $!"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Removing common words
by Anonymous Monk on Apr 04, 2004 at 05:35 UTC | |
|
Re^2: Removing common words
by Anonymous Monk on Apr 04, 2004 at 05:28 UTC |