demisheep has asked for the wisdom of the Perl Monks concerning the following question:
I am using the following example from Lingua::StopWords:
use Lingua::StopWords qw( getStopWords ); my $stopwords = getStopWords('en'); my @words = qw( i am the walrus goo goo g'joob ); # prints "walrus goo goo g'joob" print join ' ', grep { !$stopwords->{$_} } @words;
How do I get it to use my $document, remove stopwords and print the results to a file? See my code here:
open(FILESOURCE, "sample.txt") or die("Unable to open requested file." +); my $document = <FILESOURCE>; close (FILESOURCE); open(TEST, "results_stopwords.txt") or die("Unable to open requested f +ile."); use Lingua::StopWords qw( getStopWords ); my $stopwords = getStopWords('en'); print join ' ', grep { !$stopwords->{$_} } $document;
I tried these variations:
print join ' ', grep { !$stopwords->{$_} } TEST;
print TEST join ' ', grep { !$stopwords->{$_} } @words;
Basically, how do I read in a document, remove the stop words and then write the result to a new file?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I read in a document, remove the stop words and then write the result to a new file?
by toolic (Bishop) on May 14, 2012 at 17:50 UTC | |
|
Re: How do I read in a document, remove the stop words and then write the result to a new file?
by grg (Initiate) on May 14, 2012 at 18:53 UTC | |
|
Re: How do I read in a document, remove the stop words and then write the result to a new file?
by ww (Archbishop) on May 14, 2012 at 19:17 UTC | |
|
Re: How do I read in a document, remove the stop words and then write the result to a new file?
by Anonymous Monk on May 14, 2012 at 17:42 UTC | |
|
Re: How do I read in a document, remove the stop words and then write the result to a new file?
by Kenosis (Priest) on May 15, 2012 at 00:48 UTC |