Hello, does anyone know how can i discard the stop word form text file?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <sstream>
#include <fstream>
#include <map>
using namespace std;
int main()
{
const string path = "1.txt";
ifstream input( path.c_str() );
if ( !input )
{
cout << "Error opening file." << endl;
return 0;
}
multimap< string, int, less<string> > words;
int line;
string word;
// For each line of text
for ( line = 1; input; line++ )
{
char buf[ 255 ];
input.getline( buf, 128 );
// Discard all punctuation characters, leaving only words
for ( char *p = buf;
*p != '\0';
p++ )
{
if ( !isalpha( *p ) )
*p = ' ';
}
istringstream i( buf );
while ( i )
{
i >> word;
if ( word != "" )
{
words.insert( pair<const string,int>( word, line ) );
}
}
}
input.close();
// Output results
multimap< string, int, less<string> >::iterator it1;
multimap< string, int, less<string> >::iterator it2;
for ( it1 = words.begin(); it1 != words.end(); )
{
it2 = words.upper_bound( (*it1).first );
cout << (*it1).first << " : ";
for ( ; it1 != it2; it1++ )
{
cout << (*it1).second << " ";
}
cout << endl;
}
return 0;
}
|
below is my text file for stopword.txt
and
any
are
a
as
at
be
because
been
before
can't
cannot
could
couldn't
did
didn't
do
does
during
each
few
for
from
further
had
hadn't
has
hasn't
have
he'd
he'll
he's
her
here
here's
hers
herself
him
himself
his
how
how's
is
if
its
itself
let's
on
once
only
or
other
ought
our
ours
ourselves
out
over
own
same
shan't
she
she'd
she'll
she's
should
shouldn't
so
some
such
whom
why
yourself
yourselves
this one is my text file 1.txt
A keystone prey species in the Southern Ocean is retreating towards
the Antarctic because of climate change.
Krill are small, shrimp-like creatures that swarm in vast numbers and
form a major part of the diets of whales, penguins, seabirds, seals
and fish.
Scientists say warming conditions in recent decades have led to the
krill contracting poleward.
If the shift is maintained, it will have negative ecosystem impacts,
they warn.
Already there is some evidence that macaroni penguins and fur seals
may be finding it harder to get enough of the krill to support their
populations.
side note : i need to discard this word and output only the leftover word