-
Notifications
You must be signed in to change notification settings - Fork 1
/
dictConversion.cpp
56 lines (49 loc) · 1.26 KB
/
dictConversion.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
#include "trie/trie.hpp"
#include "csv/csv.hpp"
#include "experimental/filesystem"
namespace fs = std::experimental::filesystem;
/**
* Parse the input CSV file to create a `TrieNode` object instance and serialize
* that instance in JSON format, which can be used later to perform search operation
* on the data.
*/
int main(int args, char** argv);
int main(int args, char** argv) {
if (args < 2) {
cout << "CSV filename and/or word to search missing; exitting...\n";
exit(1);
}
string csvFilePath = fs::current_path().string() + "/static/EnglishDictionary.csv";
TrieNode* trieRoot = CsvReader::parseToTrie(csvFilePath);
/**
* @todo Serialize trie object instance in a file. Use a JSON library to store the data
* in following format:
* {
* "isEnd": false,
* "freq": 0,
* "arr": [
* {
* "isEnd": true,
* "freq": 127,
* "arr": [
* null,
* null,
* null,
* null
* ]
* },
* null,
* null,
* null
* ]
* }
*/
string wordToSearch = argv[1];
pair<bool, int> searchedWord = trieRoot->search(wordToSearch);
if (!searchedWord.first) {
cout << "No\n";
} else {
cout << "YES, " << searchedWord.second << "\n";
}
return 0;
}