lab_dict
Devious Dictionaries: Cleverness Through Association
 All Classes Namespaces Files Functions Variables
CommonWords Class Reference

CommonWords class. More...

#include <common_words.h>

Collaboration diagram for CommonWords:
[legend]

Public Member Functions

 CommonWords (const std::vector< std::string > &filenames)
 Constructs a CommonWords object from a vector of filenames. More...
 
std::vector< std::stringget_common_words (unsigned int n) const
 

Private Member Functions

void init_file_word_maps (const vector< string > &filenames)
 Initializes file_word_maps. More...
 
void init_common ()
 Initializes common. More...
 
vector< stringfile_to_vector (const string &filename) const
 Takes a filename and transforms it to a vector of all words in that file. More...
 

Private Attributes

vector< map< string, unsigned
int > > 
file_word_maps
 file_word_maps holds a map for each file. More...
 
std::map< std::string,
unsigned int > 
common
 common maps a word to the number of documents that word appears in More...
 

Detailed Description

CommonWords class.

Definition of a class to find all the common words across multiple files

Author
Zach Widder
Date
October 2014

Constructor & Destructor Documentation

CommonWords::CommonWords ( const std::vector< std::string > &  filenames)

Constructs a CommonWords object from a vector of filenames.

Parameters
filenamesThe list of filenames to read.

Member Function Documentation

vector< string > CommonWords::file_to_vector ( const string filename) const
private

Takes a filename and transforms it to a vector of all words in that file.

Parameters
filenameThe name of the file that will fill the vector
vector< string > CommonWords::get_common_words ( unsigned int  n) const
Parameters
nThe number of times to word has to appear.
Returns
A vector of strings. The vector contains all words that appear in each file >= n times.
void CommonWords::init_common ( )
private

Initializes common.

void CommonWords::init_file_word_maps ( const vector< string > &  filenames)
private

Initializes file_word_maps.

Parameters
filenamesThe vector of names of the files that will be used

Member Data Documentation

std::map<std::string, unsigned int> CommonWords::common
private

common maps a word to the number of documents that word appears in

vector<map<string, unsigned int> > CommonWords::file_word_maps
private

file_word_maps holds a map for each file.

Each map associates a word in that file to the number of times it has been seen in that file.


The documentation for this class was generated from the following files: