-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
67 lines (62 loc) · 1.97 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <vector>
#include "ArgumentParsing/Options.h"
#include "TextParsing/RawTextParser.h"
#include "Printing/PrettyPrinter.h"
#include "Printing/FilePrinter.h"
#include "TextParsing/ParsedTextParser.h"
#include <string>
/*
* Notes:
* When messing around with argv, [0] is the path of the executable, [1] is the first arg, [2] is blank
*/
void printHelpMsg() {
const std::string helpMsg =
"You are seeing this message because you either entered the \"-h\" flag, or entered incorrect flags. \n"
"Poetry Bot 2000 generates text based on text it is given. \n"
"-h, --help Display this message \n"
"-r, -rawText <filename> Run using text from file \n"
"-p, --parsedText <filename> Run using text imported earlier \n"
"-f, --exportToFile <filename> Export raw text to parsed text file instead of making poetry\n"
"-d, --debug Print the corpus as JSON\n";
std::cout << helpMsg << std::endl;
}
std::string printDebugMessage(WordVector words) {
std::string rval;
std::vector<Word*> wordsV = words.dumpWords();
for(int i = 0; i < wordsV.size(); i++) {
rval += wordsV[i]->toString() + "\n";
}
return rval;
}
int main(int argc, char **argv) {
const Options options(argc, argv);
WordVector words;
if(options.needsHelp()) {
printHelpMsg();
return 0;
} else if (options.useParsedText() && options.exportToFile()) {
std::cout << "Can't translate already parsed text." << std::endl;
return 1;
} else if(options.useRawText()) {
std::string file = options.getFileName();
RawTextParser parser;
parser.loadFile(file);
words = parser.parse();
} else if(options.useParsedText()) {
std::string file = options.getFileName();
ParsedTextParser parser;
parser.loadFile(file);
words = parser.parse();
}
if(options.debug()) {
printDebugMessage(words);
}
if(options.exportToFile()) {
FilePrinter printer(words);
printer.print(options.exportFileName());
}
PrettyPrinter printer(words);
std::cout << printer.print() << std::endl;
return 0;
}