-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordRef.cpp
58 lines (46 loc) · 972 Bytes
/
WordRef.cpp
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
/*
* File: WordRef.cpp
* Author: carter
*
* Created on November 14, 2012, 4:23 PM
*/
#include "WordRef.h"
WordRef::WordRef(string word_) {
word = word_;
pages = new AvlTree<double,Page *>(); //here the key will be the term frequency in that said document.
}
WordRef::WordRef(const WordRef& orig) {
}
WordRef::~WordRef() {
}
void WordRef::insertPage(int key, Page * &t)
{
pages->insert(key, t); //no sorting neccisary as avl tree keeps node in order.
}
void WordRef::insertPage(Page * &t)
{
double key;
key = calculateTF(word, t);
pages->insert(key, t); //no sorting neccisary as avl tree keeps node in order.
}
Page * WordRef::findPage(int key)
{
return pages->find(key);
}
int WordRef::calculateDF()
{
return pages->size();
}
int WordRef::calculateTF(string word_, Page * page_)
{
int freq = 0;
string str;
stringstream ss;
ss << page_->getText(); // >> ss;
while(ss >> str)
{
if(str == word_)
freq++;
}
return freq;
}