summary refs log tree commit diff stats
path: root/fruity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fruity.cpp')
-rw-r--r--fruity.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/fruity.cpp b/fruity.cpp index b88bde7..b4b5171 100644 --- a/fruity.cpp +++ b/fruity.cpp
@@ -14,39 +14,43 @@ int main(int argc, char** argv)
14 std::cout << "usage: fruity [configfile]" << std::endl; 14 std::cout << "usage: fruity [configfile]" << std::endl;
15 return -1; 15 return -1;
16 } 16 }
17 17
18 std::random_device random_device; 18 std::random_device random_device;
19 std::mt19937 random_engine{random_device()}; 19 std::mt19937 random_engine{random_device()};
20 20
21 std::string configfile(argv[1]); 21 std::string configfile(argv[1]);
22 YAML::Node config = YAML::LoadFile(configfile); 22 YAML::Node config = YAML::LoadFile(configfile);
23 23
24 twitter::auth auth; 24 twitter::auth auth;
25 auth.setConsumerKey(config["consumer_key"].as<std::string>()); 25 auth.setConsumerKey(config["consumer_key"].as<std::string>());
26 auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); 26 auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
27 auth.setAccessKey(config["access_key"].as<std::string>()); 27 auth.setAccessKey(config["access_key"].as<std::string>());
28 auth.setAccessSecret(config["access_secret"].as<std::string>()); 28 auth.setAccessSecret(config["access_secret"].as<std::string>());
29 29
30 twitter::client client(auth); 30 twitter::client client(auth);
31 31
32 verbly::data database {config["verbly_datafile"].as<std::string>()}; 32 verbly::data database {config["verbly_datafile"].as<std::string>()};
33 33
34 verbly::noun fruit = database.nouns().with_wnid(113134947).run().front(); // fruit 34 verbly::noun fruit1 = database.nouns().with_wnid(113134947).run().front(); // fruit
35 verbly::noun fruit2 = database.nouns().with_wnid(107705931).run().front(); // edible fruit
36 verbly::filter<verbly::noun> fruitFilter {fruit1, fruit2};
37 fruitFilter.set_orlogic(true);
38
35 verbly::noun plants = database.nouns().with_wnid(100017222).run().front(); // plant 39 verbly::noun plants = database.nouns().with_wnid(100017222).run().front(); // plant
36 verbly::noun drugs = database.nouns().with_wnid(103247620).run().front(); // drug 40 verbly::noun drugs = database.nouns().with_wnid(103247620).run().front(); // drug
37 verbly::noun animals = database.nouns().with_wnid(100015388).run().front(); // animal 41 verbly::noun animals = database.nouns().with_wnid(100015388).run().front(); // animal
38 42
39 for (;;) 43 for (;;)
40 { 44 {
41 std::cout << "Generating tweet" << std::endl; 45 std::cout << "Generating tweet" << std::endl;
42 46
43 auto n1 = database.nouns().full_hyponym_of(fruit).random().limit(1).run(); 47 auto n1 = database.nouns().full_hyponym_of(fruitFilter).random().limit(1).run();
44 auto n1w = n1.front(); 48 auto n1w = n1.front();
45 auto n1hq = database.nouns().hypernym_of(n1w).limit(1).run(); 49 auto n1hq = database.nouns().hypernym_of(n1w).limit(1).run();
46 auto n1h = n1hq.front(); 50 auto n1h = n1hq.front();
47 51
48 std::list<std::string> tokens; 52 std::list<std::string> tokens;
49 53
50 int choice = std::uniform_int_distribution<int>(0,2)(random_engine); 54 int choice = std::uniform_int_distribution<int>(0,2)(random_engine);
51 if (choice == 0) 55 if (choice == 0)
52 { 56 {
@@ -57,7 +61,7 @@ int main(int argc, char** argv)
57 auto descriptor = database.adjectives().is_mannernymic().random().limit(1).run(); 61 auto descriptor = database.adjectives().is_mannernymic().random().limit(1).run();
58 tokens.push_back(descriptor.front().base_form()); 62 tokens.push_back(descriptor.front().base_form());
59 } 63 }
60 64
61 auto plantThing = database.nouns(); 65 auto plantThing = database.nouns();
62 choice = std::uniform_int_distribution<int>(0,4)(random_engine); 66 choice = std::uniform_int_distribution<int>(0,4)(random_engine);
63 if (choice < 3) 67 if (choice < 3)
@@ -72,26 +76,26 @@ int main(int argc, char** argv)
72 { 76 {
73 plantThing.full_hyponym_of(animals); 77 plantThing.full_hyponym_of(animals);
74 } 78 }
75 79
76 plantThing.is_not_proper().with_complexity(1).random().limit(1); 80 plantThing.is_not_proper().with_complexity(1).random().limit(1);
77 tokens.push_back(plantThing.run().front().base_form()); 81 tokens.push_back(plantThing.run().front().base_form());
78 } 82 }
79 83
80 auto similar = database.nouns().full_hyponym_of(n1h).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run(); 84 auto similar = database.nouns().full_hyponym_of(n1h).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run();
81 if (!similar.empty()) 85 if (!similar.empty())
82 { 86 {
83 tokens.push_back(similar.front().base_form()); 87 tokens.push_back(similar.front().base_form());
84 } else { 88 } else {
85 auto different = database.nouns().full_hyponym_of(fruit).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run(); 89 auto different = database.nouns().full_hyponym_of(fruitFilter).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run();
86 tokens.push_back(different.front().base_form()); 90 tokens.push_back(different.front().base_form());
87 } 91 }
88 92
89 std::string fruitName = verbly::implode(std::begin(tokens), std::end(tokens), " "); 93 std::string fruitName = verbly::implode(std::begin(tokens), std::end(tokens), " ");
90 94
91 std::ostringstream result; 95 std::ostringstream result;
92 result << n1.front().base_form(); 96 result << n1.front().base_form();
93 result << "? "; 97 result << "? ";
94 98
95 choice = std::uniform_int_distribution<int>(0,3)(random_engine); 99 choice = std::uniform_int_distribution<int>(0,3)(random_engine);
96 if (choice == 0) 100 if (choice == 0)
97 { 101 {
@@ -113,10 +117,10 @@ int main(int argc, char** argv)
113 result << fruitName; 117 result << fruitName;
114 result << " now"; 118 result << " now";
115 } 119 }
116 120
117 std::string tweet = result.str(); 121 std::string tweet = result.str();
118 tweet.resize(140); 122 tweet.resize(140);
119 123
120 try 124 try
121 { 125 {
122 client.updateStatus(tweet); 126 client.updateStatus(tweet);