This repository has been archived by the owner on Jan 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordcount.h
50 lines (39 loc) · 1.51 KB
/
wordcount.h
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
// Copyright [2011] <Tom Leo>
#include <iostream>
#include <string>
#include <vector>
using std::string;
using std::vector;
typedef vector<string>::iterator VecIter;
// Counts the frequency of words in a string.
class WordCount {
public:
// All words found from generate_words is added to words_
vector<string> words_;
// fdic_words_ is an array of all the words in a sentence without
// duplicates. fdic_count_ contains the number of times each word in
// fdic_words_ occors. The two arrays are related based on their index, and
// are ment to mimic a dictionary.
string *fdic_words_;
int *fdic_count_;
// Default constructor does do anything
WordCount();
// Create a vector of all words in sentence.
//
// The deliminators are the comma and period. Boosts tokenizer might be a
// better solution but this is simple and does not require external
// libraries.
void generate_words(string);
// Returns index of string in member variable fdic_words_ if word is not
// found returns -1
int in_array(string);
// Generates a fake dictionary like structure, where the index of a word
// is in member variable fdic_words_ and the index of
// a word count in fdic_count_
void generate_fdic();
// Each valid entry (not equal to ',') from fdic_words_ is prited along with
// the number of times the word accures via fdic_count_
void get_wordcounts();
// Returns true if string is present in fdic_words_
bool find_word(string);
};