forked from FruitPunch5amurai/LevenshteinsAutomata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry.cpp
65 lines (61 loc) · 1.75 KB
/
entry.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
59
60
61
62
63
64
65
#include <string>
#include <stdio.h>
#include <list>
#include <iostream>
#include <fstream>
#include <ctime>
#include "Trie.h"
#include "LevenshteinNFA.h"
#include "LevenshteinDFA.h"
using namespace std;
int main(int argc, char **argv)
{
ifstream file;
Trie trie;
clock_t timer;
double duration = 0;
double totalTime = 0;
int maxDist = 2;
LevenshteinAutomata::LevenshteinNFA *nfa;
LevenshteinAutomata::LevenshteinDFA *dfa;
char line[256];
trie.rootNode = getNode(' ', "");
file.open("wordList.txt");
cout << "Constructing Trie..."<< endl;
timer = clock();
/*Load in all resources*/
while (file.good())
{
file.getline(line,256);
trie.Insert(line);
}
file.close();
duration = (clock() - timer) / (double)CLOCKS_PER_SEC;
cout << "Constructing Trie Complete! Time: " << duration << " Seconds" << endl;
cout << "Levenshteins Distance: " << maxDist << endl;
file.open("wordsToTest.txt");
//Search
while (file.good())
{
file.getline(line, 256);
cout << "===================================================================" << endl;
cout << "Constructing Levenshteins Automata for word: " << line << endl;
timer = clock();
nfa = LevenshteinAutomata::LevenshteinNFA::ConstructNFA(line, maxDist);
dfa = LevenshteinAutomata::LevenshteinDFA::SubsetConstruct(nfa);
list<string> output;
cout << "Searching..." << endl;
dfa->Search(&trie, dfa->start, trie.rootNode, output);
duration = (clock() - timer) / (double)CLOCKS_PER_SEC;
totalTime += duration;
cout << "Construction and Search complete! Time: " << duration << " Seconds" << endl;
cout << "Number of hits found: " << output.size() << endl;
}
cout << "Total time: " << totalTime << " Seconds.."<<endl;
file.close();
//Clean Up
delete nfa;
delete dfa;
char c = getchar();
return 0;
}