-
Notifications
You must be signed in to change notification settings - Fork 29
/
main.cpp
50 lines (46 loc) · 1.41 KB
/
main.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
/**
* @file main.cpp
* @author Sean Massung
* @date September 2012
*
* An example using the Porter2Stemmer namespace.
*
* Words are read from the file diffs.txt
* (from http://snowball.tartarus.org/algorithms/english/diffs.txt)
* and compared against the correct output.
*/
#include <iostream>
#include <fstream>
#include <string>
#include <chrono>
#include "porter2_stemmer.h"
int main()
{
std::ifstream in{"diffs.txt"};
std::string to_stem;
std::string stemmed;
bool mistake = false;
using timer = std::chrono::high_resolution_clock;
timer::time_point start_time = timer::now();
while (in >> to_stem >> stemmed)
{
std::string orig = to_stem;
Porter2Stemmer::trim(to_stem);
Porter2Stemmer::stem(to_stem);
if (to_stem != stemmed)
{
std::cout << " incorrect!" << std::endl
<< std::endl
<< "to stem: " << orig << std::endl
<< "stemmed: " << to_stem << std::endl
<< "expected: " << stemmed << std::endl;
mistake = true;
}
}
timer::time_point end_time = timer::now();
if (!mistake)
std::cout << "Passed all tests!" << std::endl;
std::cout << "Time elapsed: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(
end_time - start_time).count() << "ms" << std::endl;
}