hi everyone ... i am doing the intersection, can someone let me know which intersect with which please... as i am really confuse on the StringSet otherset .. here is my code and class...
which is on red color..
this is my implementation code
Code:
#include "stringset.h"
// insert a value into the set
// Pre: a string value
// Post: the value is inserted into the set if it
// is not already present
void StringSet::insert(string value)
{
if( !contains(value) )
{
contents.push_back(value);
}
}
// test for a value
// Pre: a string value
// Post: returns 1 if the value is present in the StringSet, 0 otherwise
int StringSet::contains(string value)
{
int loc;
bool found = false;
for(loc = 0; loc < contents.size(); loc++)
if(contents[loc] == value)
{
found = true;
break;
}
if(found)
return 1;
else
return 0;
}
// intersection of this set with another
// Pre: a StringSet object
// Post: returns a new StringSet which is the intersection
// of this with otherset, ie. only the items common to both StringSets
StringSet StringSet::set_intersection(StringSet otherset)
{
}
// union of this set with another
// Pre: a StringSet object
// Post: returns a new StringSet which is the union
// of this with otherset, ie. the items in either StringSets
StringSet StringSet::set_union(StringSet otherset)
{
}
// print
// Pre: None
// Post: the stringset will be printed to cout
void StringSet::print()
{
for( int i=0; i<contents.size(); i++ )
cout << "\t" << contents[i] << endl;
}
and this is my mainc.pp
Code:
#include "inverted_index.h"
int main()
{
StringSet ss;
ss.insert("one");
ss.insert("two");
ss.insert("three");
ss.insert("one");
ss.print();
if ( ss.contains("one") )
cout << "ok - contains('one')\n";
else
cout << "fail - contains('one')\n";
/*
// test the InvertedIndex
InvertedIndex idx;
idx.tally("cat", "cats.txt");
idx.tally("cat", "animals.txt");
idx.tally("cat", "everything.txt");
idx.tally("dog", "dogs.txt");
idx.print();
// searching idx for cat should give us three files
vector <string> query;
query.push_back("cat");
StringSet si = idx.search(query);
if (si.contains("cats.txt") && si.contains("animals.txt") && si.contains("everything.txt") )
cout << "ok - search('cat')\n";
else
cout << "fail - search('cat')\n";
if (si.contains("dogs.txt"))
cout << "fail - search('cat') -- dogs.txt found\n";
else
cout << "ok - search('cat') no dogs\n";
*/
system("PAUSE");
return 0;
}
this is another implementation which might be helpful ...
Code:
#include "inverted_index.h"
#include "osdir.h"
// InvertedIndex::tally
// Pre: a word and file pair as strings
// Post: adds the file to the index under word
void InvertedIndex::tally(string word, string file)
{
storage.push_back(word);
//storage.push_back(file);
//vector<string>::iterator theIterator = storage.end();
//storage.insert( theIterator, file );
}
// InvertedIndex::search
// Pre: a vector of strings as search terms
// Post: a vector of strings being the files that all of the
// input words occur in in the index.
StringSet InvertedIndex::search(vector <string> words)
{
}
// print
// Pre: an index structure
// Post: renders the index on the screen
void InvertedIndex::print()
{
for(int i = 0; i < storage.size(); i++)
{
cout<<endl<<storage[i]<<" ";
}
cout<<endl<<endl;
}
//
// These methods have been written for you, there is no need to change
// anything below this text. These methods make use of the other
// methods defined above.
//
// IndexFile
// Pre: a file name as a string
// Post: the words in the file are added to the inverted index
void InvertedIndex::indexFile( string filename ) {
vector <string> words = ReadFile(filename);
for(int i=0; i<words.size(); i++) {
tally(words[i], filename);
}
}
void InvertedIndex::indexDir( string dirname ) {
string filename;
oslink::directory dir(dirname);
while (dir) {
filename = dirname + "/" + dir.next();
indexFile(filename);
}
}