-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWord.cpp
More file actions
83 lines (66 loc) · 1.67 KB
/
Copy pathWord.cpp
File metadata and controls
83 lines (66 loc) · 1.67 KB
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
72
73
74
75
76
77
78
79
80
81
//
// Created by Kevin Leong on 11/15/20.
//
#include "Word.h"
Word::Word(string word) {
this->word = word;
this->totalFreq = 0;
}
Word::Word(char *word) {
this->word = word;
this->totalFreq = 0;
}
Word::Word(const Word ©) {
this->word = copy.word;
this->titleList = copy.titleList;
this->totalFreq = copy.totalFreq;
}
Word::~Word() = default;
bool Word::operator>(const Word &comp) const {
return this->word > comp.word;
}
bool Word::operator<(const Word &comp) const {
return this->word < comp.word;
}
bool Word::operator==(const Word &comp) const {
return this->word == comp.word;
}
string Word::getWord(){
return this->word;
}
map<string, int>& Word::getTitleList() {
return this->titleList;
}
void Word::addPaperID(string paperID) {
this->titleList[paperID];
this->titleList.at(paperID) = 0;
}
int Word::getTotalFreq() {
return this->totalFreq;
}
void Word::iterTotalFreq() {
this->totalFreq++;
}
ostream &operator<<(ostream &os, const Word &word)
{
os << "\t\t{\n\t\t\t\"string\": \"" << word.word << "\",\n"
<< "\t\t\t\"total frequency\": \"" << word.totalFreq <<"\",\n" //add comma after total frequency
<< "\t\t\t\"ids\": [\n";
auto it = word.titleList.begin();
while(it != prev(word.titleList.end()))
{
os << "\t\t\t\t{\n\t\t\t\t\t\"id\": \"" << it->first << "\"\n\t\t\t\t},\n";
it++;
}
os << "\t\t\t\t{\n\t\t\t\t\t\"id\": \"" << it->first << "\"\n\t\t\t\t}\n";
os << "\t\t\t]\n\t\t}";
return os;
}
void Word::setWord(const string &word)
{
this->word = word;
}
void Word::setTotalFreq(const int &totalFreq)
{
this->totalFreq = totalFreq;
}