diff options
Diffstat (limited to 'fefisms.cpp')
-rw-r--r-- | fefisms.cpp | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/fefisms.cpp b/fefisms.cpp index 44e69b4..701b330 100644 --- a/fefisms.cpp +++ b/fefisms.cpp | |||
@@ -1,41 +1,40 @@ | |||
1 | #include <verbly.h> | 1 | #include "fefisms.h" |
2 | #include <twitter.h> | ||
3 | #include <yaml-cpp/yaml.h> | 2 | #include <yaml-cpp/yaml.h> |
4 | #include <iostream> | 3 | #include <iostream> |
5 | #include <chrono> | 4 | #include <chrono> |
6 | #include <random> | ||
7 | #include <thread> | 5 | #include <thread> |
8 | 6 | ||
9 | int main(int argc, char** argv) | 7 | fefisms::fefisms( |
8 | std::string configFile, | ||
9 | std::mt19937& rng) : | ||
10 | rng_(rng) | ||
10 | { | 11 | { |
11 | std::random_device random_device; | 12 | // Load the config file. |
12 | std::mt19937 random_engine{random_device()}; | 13 | YAML::Node config = YAML::LoadFile(configFile); |
13 | |||
14 | if (argc != 2) | ||
15 | { | ||
16 | std::cout << "usage: fefisms [configfile]" << std::endl; | ||
17 | return -1; | ||
18 | } | ||
19 | 14 | ||
20 | std::string configfile(argv[1]); | 15 | // Set up the verbly database. |
21 | YAML::Node config = YAML::LoadFile(configfile); | 16 | database_ = std::unique_ptr<verbly::database>( |
17 | new verbly::database(config["verbly_datafile"].as<std::string>())); | ||
22 | 18 | ||
19 | // Set up the Twitter client. | ||
23 | twitter::auth auth; | 20 | twitter::auth auth; |
24 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); | 21 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); |
25 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); | 22 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); |
26 | auth.setAccessKey(config["access_key"].as<std::string>()); | 23 | auth.setAccessKey(config["access_key"].as<std::string>()); |
27 | auth.setAccessSecret(config["access_secret"].as<std::string>()); | 24 | auth.setAccessSecret(config["access_secret"].as<std::string>()); |
28 | 25 | ||
29 | twitter::client client(auth); | 26 | client_ = std::unique_ptr<twitter::client>(new twitter::client(auth)); |
30 | 27 | } | |
31 | verbly::database database(config["verbly_datafile"].as<std::string>()); | ||
32 | 28 | ||
29 | void fefisms::run() const | ||
30 | { | ||
33 | verbly::filter formFilter = | 31 | verbly::filter formFilter = |
34 | (verbly::form::complexity == 1) | 32 | (verbly::form::complexity == 1) |
35 | && (verbly::form::proper == false); | 33 | && (verbly::form::proper == false); |
36 | 34 | ||
35 | // Blacklist ethnic slurs | ||
37 | verbly::filter cleanFilter = | 36 | verbly::filter cleanFilter = |
38 | !(verbly::word::usageDomains %= (verbly::notion::wnid == 106718862)); // Blacklist ethnic slurs | 37 | !(verbly::word::usageDomains %= (verbly::notion::wnid == 106718862)); |
39 | 38 | ||
40 | for (;;) | 39 | for (;;) |
41 | { | 40 | { |
@@ -45,18 +44,18 @@ int main(int argc, char** argv) | |||
45 | 44 | ||
46 | verbly::inflection nounInfl = verbly::inflection::base; | 45 | verbly::inflection nounInfl = verbly::inflection::base; |
47 | verbly::inflection hypoInfl = verbly::inflection::base; | 46 | verbly::inflection hypoInfl = verbly::inflection::base; |
48 | 47 | ||
49 | if (std::bernoulli_distribution(1.0/2.0)(random_engine)) | 48 | if (std::bernoulli_distribution(1.0/2.0)(rng_)) |
50 | { | 49 | { |
51 | hypoInfl = verbly::inflection::plural; | 50 | hypoInfl = verbly::inflection::plural; |
52 | } | 51 | } |
53 | 52 | ||
54 | if (std::bernoulli_distribution(1.0/2.0)(random_engine)) | 53 | if (std::bernoulli_distribution(1.0/2.0)(rng_)) |
55 | { | 54 | { |
56 | nounInfl = verbly::inflection::plural; | 55 | nounInfl = verbly::inflection::plural; |
57 | } | 56 | } |
58 | 57 | ||
59 | verbly::word noun = database.words( | 58 | verbly::word noun = database_->words( |
60 | (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) | 59 | (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) |
61 | && (verbly::word::forms(nounInfl) %= formFilter) | 60 | && (verbly::word::forms(nounInfl) %= formFilter) |
62 | && cleanFilter | 61 | && cleanFilter |
@@ -64,13 +63,13 @@ int main(int argc, char** argv) | |||
64 | (verbly::word::forms(hypoInfl) %= formFilter) | 63 | (verbly::word::forms(hypoInfl) %= formFilter) |
65 | && cleanFilter)).first(); | 64 | && cleanFilter)).first(); |
66 | 65 | ||
67 | verbly::word hyponym = database.words( | 66 | verbly::word hyponym = database_->words( |
68 | (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) | 67 | (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) |
69 | && (verbly::notion::hypernyms %= noun) | 68 | && (verbly::notion::hypernyms %= noun) |
70 | && cleanFilter | 69 | && cleanFilter |
71 | && (verbly::word::forms(hypoInfl) %= formFilter)).first(); | 70 | && (verbly::word::forms(hypoInfl) %= formFilter)).first(); |
72 | 71 | ||
73 | if (std::bernoulli_distribution(1.0/2.0)(random_engine)) | 72 | if (std::bernoulli_distribution(1.0/2.0)(rng_)) |
74 | { | 73 | { |
75 | utterance << verbly::token(noun, nounInfl); | 74 | utterance << verbly::token(noun, nounInfl); |
76 | utterance << verbly::token(hyponym, hypoInfl); | 75 | utterance << verbly::token(hyponym, hypoInfl); |
@@ -86,7 +85,7 @@ int main(int argc, char** argv) | |||
86 | { | 85 | { |
87 | std::cout << "Tweeting..." << std::endl; | 86 | std::cout << "Tweeting..." << std::endl; |
88 | 87 | ||
89 | client.updateStatus(action); | 88 | client_->updateStatus(action); |
90 | 89 | ||
91 | std::cout << "Success!" << std::endl; | 90 | std::cout << "Success!" << std::endl; |
92 | std::cout << "Waiting..." << std::endl; | 91 | std::cout << "Waiting..." << std::endl; |
@@ -100,4 +99,3 @@ int main(int argc, char** argv) | |||
100 | std::cout << std::endl; | 99 | std::cout << std::endl; |
101 | } | 100 | } |
102 | } | 101 | } |
103 | |||