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.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/dialogue.cpp b/dialogue.cpp new file mode 100644 index 0000000..dd34ee5 --- /dev/null +++ b/dialogue.cpp
@@ -0,0 +1,122 @@
1#include "vendor/csv.h"
2#include "identifier.h"
3#include "histogram.h"
4#include <rawr.h>
5#include <cstdlib>
6#include <ctime>
7#include <map>
8#include <string>
9#include <iostream>
10#include <sstream>
11
12
13
14using speakerstore = identifier<std::string>;
15using speaker_id = speakerstore::key_type;
16
17
18struct speaker_data {
19
20 std::string name;
21 histogram<speaker_id> nextSpeaker;
22 rawr chain;
23
24};
25
26
27
28
29int main(int, char**)
30{
31 srand(time(NULL));
32 rand(); rand(); rand(); rand();
33
34 speakerstore speakers;
35 std::map<speaker_id, speaker_data> speakerData;
36 histogram<speaker_id> allSpeakers;
37
38
39
40 io::CSVReader<2,io::trim_chars<' ', '\t'>,io::double_quote_escape<',', '"'>> in("../dialogue.csv");
41 std::string speaker;
42 std::string line;
43
44 bool hadPrev = false;
45 speaker_id prevSpeaker;
46
47 while (in.read_row(speaker, line))
48 {
49 speaker_id spId = speakers.add(speaker);
50 speaker_data& myData = speakerData[spId];
51 myData.name = speaker;
52
53 allSpeakers.add(spId);
54
55 if (hadPrev && prevSpeaker != spId)
56 {
57 speaker_data& psd = speakerData[prevSpeaker];
58 psd.nextSpeaker.add(spId);
59 }
60
61 myData.chain.addCorpus(line);
62
63 hadPrev = true;
64 prevSpeaker = spId;
65 }
66
67 for (auto& sp : speakerData)
68 {
69 sp.second.chain.compile(4);
70 sp.second.nextSpeaker.compile();
71 }
72
73 std::cout << "Speakers:" << std::endl;
74 for (auto& sp : speakerData)
75 {
76 std::cout << " " << sp.second.name << std::endl;
77 }
78 std::cout << std::endl;
79
80 allSpeakers.compile();
81
82 for (;;)
83 {
84 speaker_id curSpeaker = allSpeakers.next();
85
86 std::ostringstream theEnd;
87
88 for (int i = 0; i < 5; i++)
89 {
90 speaker_data& curSd = speakerData.at(curSpeaker);
91
92 //std::ostringstream thisLine;
93
94 if (curSd.name != "")
95 {
96 theEnd << curSd.name << ": ";
97 }
98
99 theEnd << curSd.chain.randomSentence(1);
100
101 /*if (i > 0 && theEnd.str().length() + thisLine.str().length() > 280)
102 {
103 break;
104 }*/
105
106 theEnd << std::endl;
107 //theEnd << thisLine.str();
108
109 curSpeaker = curSd.nextSpeaker.next();
110 }
111
112 std::string output = theEnd.str();
113 output.resize(280);
114 output = output.substr(0, output.find_last_of('\n'));
115 std::cout << output;
116
117 std::cout << std::endl;
118 std::cout << std::endl;
119
120 getc(stdin);
121 }
122}