summary refs log tree commit diff stats
path: root/dialogue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dialogue.cpp')
-rw-r--r--dialogue.cpp66
1 files changed, 47 insertions, 19 deletions
diff --git a/dialogue.cpp b/dialogue.cpp index 47a761d..1e95d2b 100644 --- a/dialogue.cpp +++ b/dialogue.cpp
@@ -2,19 +2,17 @@
2#include "identifier.h" 2#include "identifier.h"
3#include "histogram.h" 3#include "histogram.h"
4#include <rawr.h> 4#include <rawr.h>
5#include <cstdlib>
6#include <ctime>
7#include <map> 5#include <map>
8#include <string> 6#include <string>
9#include <iostream> 7#include <iostream>
10#include <sstream> 8#include <sstream>
11 9#include <random>
12 10#include <twitter.h>
11#include <yaml-cpp/yaml.h>
13 12
14using speakerstore = identifier<std::string>; 13using speakerstore = identifier<std::string>;
15using speaker_id = speakerstore::key_type; 14using speaker_id = speakerstore::key_type;
16 15
17
18struct speaker_data { 16struct speaker_data {
19 17
20 std::string name; 18 std::string name;
@@ -24,21 +22,39 @@ struct speaker_data {
24 22
25}; 23};
26 24
25int main(int argc, char** argv)
26{
27 if (argc != 2)
28 {
29 std::cout << "usage: garnet [configfile]" << std::endl;
30 return -1;
31 }
32
33 std::random_device randomDevice;
34 std::mt19937 rng(randomDevice());
27 35
36 std::string configfile(argv[1]);
37 YAML::Node config = YAML::LoadFile(configfile);
28 38
39 twitter::auth auth(
40 config["consumer_key"].as<std::string>(),
41 config["consumer_secret"].as<std::string>(),
42 config["access_key"].as<std::string>(),
43 config["access_secret"].as<std::string>());
29 44
30int main(int, char**) 45 twitter::client client(auth);
31{
32 srand(time(NULL));
33 rand(); rand(); rand(); rand();
34 46
35 speakerstore speakers; 47 speakerstore speakers;
36 std::map<speaker_id, speaker_data> speakerData; 48 std::map<speaker_id, speaker_data> speakerData;
37 histogram<speaker_id> allSpeakers; 49 histogram<speaker_id> allSpeakers;
38 50
51 using csv =
52 io::CSVReader<
53 2,
54 io::trim_chars<' ', '\t'>,
55 io::double_quote_escape<',', '"'>>;
39 56
40 57 csv in(config["transcript"].as<std::string>());
41 io::CSVReader<2,io::trim_chars<' ', '\t'>,io::double_quote_escape<',', '"'>> in("../dialogue.csv");
42 std::string speaker; 58 std::string speaker;
43 std::string line; 59 std::string line;
44 60
@@ -85,11 +101,10 @@ int main(int, char**)
85 { 101 {
86 std::set<speaker_id> pastSpeakers; 102 std::set<speaker_id> pastSpeakers;
87 103
88 104 speaker_id curSpeaker = allSpeakers.next(rng);
89 speaker_id curSpeaker = allSpeakers.next();
90 105
91 std::ostringstream theEnd; 106 std::ostringstream theEnd;
92 int maxLines = rand() % 4 + 3; 107 int maxLines = std::uniform_int_distribution<int>(3, 6)(rng);
93 108
94 for (int i = 0; i < maxLines; i++) 109 for (int i = 0; i < maxLines; i++)
95 { 110 {
@@ -102,7 +117,8 @@ int main(int, char**)
102 theEnd << curSd.name << ": "; 117 theEnd << curSd.name << ": ";
103 } 118 }
104 119
105 std::string curLine = curSd.chain.randomSentence(rand() % 30 + 1); 120 int maxL = std::uniform_int_distribution<int>(1, 30)(rng);
121 std::string curLine = curSd.chain.randomSentence(maxL, rng);
106 122
107 if (curSd.name == "" && 123 if (curSd.name == "" &&
108 curLine[0] != '[' && 124 curLine[0] != '[' &&
@@ -116,13 +132,16 @@ int main(int, char**)
116 132
117 theEnd << std::endl; 133 theEnd << std::endl;
118 134
119 speaker_id repeatSpeaker = *std::next(std::begin(pastSpeakers), rand() % pastSpeakers.size()); 135 int psi =
136 std::uniform_int_distribution<int>(0, pastSpeakers.size()-1)(rng);
137
138 speaker_id repeatSpeaker = *std::next(std::begin(pastSpeakers), psi);
120 if (repeatSpeaker != curSpeaker && 139 if (repeatSpeaker != curSpeaker &&
121 rand() % 3 == 0) 140 std::bernoulli_distribution(1.0 / 3.0)(rng))
122 { 141 {
123 curSpeaker = repeatSpeaker; 142 curSpeaker = repeatSpeaker;
124 } else { 143 } else {
125 curSpeaker = curSd.nextSpeaker.next(); 144 curSpeaker = curSd.nextSpeaker.next(rng);
126 } 145 }
127 } 146 }
128 147
@@ -131,9 +150,18 @@ int main(int, char**)
131 output = output.substr(0, output.find_last_of('\n')); 150 output = output.substr(0, output.find_last_of('\n'));
132 std::cout << output; 151 std::cout << output;
133 152
153 try
154 {
155 client.updateStatus(output);
156 } catch (const twitter::twitter_error& error)
157 {
158 std::cout << "Twitter error while tweeting: " << error.what()
159 << std::endl;
160 }
161
134 std::cout << std::endl; 162 std::cout << std::endl;
135 std::cout << std::endl; 163 std::cout << std::endl;
136 164
137 getc(stdin); 165 std::this_thread::sleep_for(std::chrono::hours(4));
138 } 166 }
139} 167}