From 2b152d09881559a0330b3ff923e03e715777c6c3 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 27 Feb 2019 20:45:17 -0500 Subject: Initial commit (by Pink!) --- dialogue.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 dialogue.cpp (limited to 'dialogue.cpp') diff --git a/dialogue.cpp b/dialogue.cpp new file mode 100644 index 0000000..dd34ee5 --- /dev/null +++ b/dialogue.cpp @@ -0,0 +1,122 @@ +#include "vendor/csv.h" +#include "identifier.h" +#include "histogram.h" +#include +#include +#include +#include +#include +#include +#include + + + +using speakerstore = identifier; +using speaker_id = speakerstore::key_type; + + +struct speaker_data { + + std::string name; + histogram nextSpeaker; + rawr chain; + +}; + + + + +int main(int, char**) +{ + srand(time(NULL)); + rand(); rand(); rand(); rand(); + + speakerstore speakers; + std::map speakerData; + histogram allSpeakers; + + + + io::CSVReader<2,io::trim_chars<' ', '\t'>,io::double_quote_escape<',', '"'>> in("../dialogue.csv"); + std::string speaker; + std::string line; + + bool hadPrev = false; + speaker_id prevSpeaker; + + while (in.read_row(speaker, line)) + { + speaker_id spId = speakers.add(speaker); + speaker_data& myData = speakerData[spId]; + myData.name = speaker; + + allSpeakers.add(spId); + + if (hadPrev && prevSpeaker != spId) + { + speaker_data& psd = speakerData[prevSpeaker]; + psd.nextSpeaker.add(spId); + } + + myData.chain.addCorpus(line); + + hadPrev = true; + prevSpeaker = spId; + } + + for (auto& sp : speakerData) + { + sp.second.chain.compile(4); + sp.second.nextSpeaker.compile(); + } + + std::cout << "Speakers:" << std::endl; + for (auto& sp : speakerData) + { + std::cout << " " << sp.second.name << std::endl; + } + std::cout << std::endl; + + allSpeakers.compile(); + + for (;;) + { + speaker_id curSpeaker = allSpeakers.next(); + + std::ostringstream theEnd; + + for (int i = 0; i < 5; i++) + { + speaker_data& curSd = speakerData.at(curSpeaker); + + //std::ostringstream thisLine; + + if (curSd.name != "") + { + theEnd << curSd.name << ": "; + } + + theEnd << curSd.chain.randomSentence(1); + + /*if (i > 0 && theEnd.str().length() + thisLine.str().length() > 280) + { + break; + }*/ + + theEnd << std::endl; + //theEnd << thisLine.str(); + + curSpeaker = curSd.nextSpeaker.next(); + } + + std::string output = theEnd.str(); + output.resize(280); + output = output.substr(0, output.find_last_of('\n')); + std::cout << output; + + std::cout << std::endl; + std::cout << std::endl; + + getc(stdin); + } +} -- cgit 1.4.1