-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.cpp
More file actions
37 lines (28 loc) · 1.02 KB
/
Copy pathtest.cpp
File metadata and controls
37 lines (28 loc) · 1.02 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
#include "Ngrams.h"
#include "CorpusAnalyse.h"
#include <iostream>
#include <algorithm>
#include <iterator>
#include <math.h>
int main() {
std::cout << "Generating ngrams frequency list .." << std::endl;
NGramReader* ngr = new NGramReader("../corpus", "../vocab");
CorpusAnalyse* ca = new CorpusAnalyse(ngr->frequencyMap(), ngr->vocab(), ngr->corpusSize());
std::cout << "SUM UP PROBABILITIES OF P(W)" << std::endl;
float total = 0;
for (auto i = ngr->vocab()->begin(); i != ngr->vocab()->end(); ++i) {
total += ca->p(i->first);
}
std::cout << "SUM : " << total << std::endl;
total = 0;
std::cout << "SUM UP PROBABILITIES OF P(W|V)" << std::endl;
for (auto i = ngr->vocab()->begin(); i != ngr->vocab()->end(); ++i) {
total += ca->p(i->first, "the");
}
std::cout << "SUM : " << total << std::endl;
std::cout << "PERPLEXITY" << std::endl;
std::cout << "PP = " << ca->perplexity("../test", EBigram) <<std::endl;
delete ngr;
delete ca;
return 0;
}