about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-02-16 20:05:08 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-02-16 20:05:08 -0500
commit262c4458c5933b70f0dee6fce533630b71c3a184 (patch)
tree681ab23dd1fd73e0648a30421bdd65a69bef0485
parentaf20d60f42cc2046090c41cafc7f3d651cd0997d (diff)
downloadwordplay-262c4458c5933b70f0dee6fce533630b71c3a184.tar.gz
wordplay-262c4458c5933b70f0dee6fce533630b71c3a184.tar.bz2
wordplay-262c4458c5933b70f0dee6fce533630b71c3a184.zip
Updated verbly (new API)
m---------vendor/libtwittercpp0
m---------vendor/verbly0
-rw-r--r--wordplay.cpp110
3 files changed, 54 insertions, 56 deletions
diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp
Subproject d783c17151a98466e304b1e5f33bfca0be885fd Subproject df906121dd862c0f704e44f28ee079158c431c4
diff --git a/vendor/verbly b/vendor/verbly
Subproject 1f898f3bd66c29672275c2c884b17ba662ced62 Subproject 49d6f0387f7b7cc3c6a51ef8fcdf519da98487f
diff --git a/wordplay.cpp b/wordplay.cpp index c7015ee..af4fca2 100644 --- a/wordplay.cpp +++ b/wordplay.cpp
@@ -18,71 +18,66 @@ int main(int argc, char** argv)
18 18
19 std::string configfile(argv[1]); 19 std::string configfile(argv[1]);
20 YAML::Node config = YAML::LoadFile(configfile); 20 YAML::Node config = YAML::LoadFile(configfile);
21 21
22 twitter::auth auth; 22 twitter::auth auth;
23 auth.setConsumerKey(config["consumer_key"].as<std::string>()); 23 auth.setConsumerKey(config["consumer_key"].as<std::string>());
24 auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); 24 auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
25 auth.setAccessKey(config["access_key"].as<std::string>()); 25 auth.setAccessKey(config["access_key"].as<std::string>());
26 auth.setAccessSecret(config["access_secret"].as<std::string>()); 26 auth.setAccessSecret(config["access_secret"].as<std::string>());
27 27
28 twitter::client client(auth); 28 twitter::client client(auth);
29 29
30 verbly::data database(config["verbly_datafile"].as<std::string>()); 30 verbly::database database(config["verbly_datafile"].as<std::string>());
31 31
32 // Blacklist ethnic slurs
33 verbly::filter cleanFilter =
34 !(verbly::word::usageDomains %= (verbly::notion::wnid == 106718862));
35
36 verbly::filter nounFilter =
37 cleanFilter
38 && (verbly::notion::partOfSpeech == verbly::part_of_speech::noun)
39 && (verbly::notion::hypernyms %= cleanFilter);
40
41 verbly::query<verbly::word> adjectiveQuery = database.words(
42 (verbly::notion::partOfSpeech == verbly::part_of_speech::adjective)
43 && (verbly::pronunciation::rhymes %= nounFilter)
44 && (verbly::word::synonyms));
45
32 for (;;) 46 for (;;)
33 { 47 {
34 // Generate the most amazing jokes you've ever heard 48 verbly::word adjective = adjectiveQuery.first();
35 auto adjq = database.adjectives().has_rhyming_noun().has_synonyms().random().limit(1).run(); 49
36 if (adjq.empty()) 50 verbly::word noun = database.words(
37 { 51 nounFilter
38 continue; 52 && (verbly::pronunciation::rhymes %= adjective)).first();
39 } 53
40 54 verbly::word hypernym = database.words(
41 verbly::adjective rhmadj = adjq.front(); 55 cleanFilter
42 56 && (verbly::notion::hyponyms %= noun)).first();
43 auto nounq = database.nouns().rhymes_with(rhmadj).is_hyponym().random().limit(1).run(); 57
44 if (nounq.empty()) 58 verbly::word synonym = database.words(
45 { 59 (verbly::word::synonyms %= adjective)).first();
46 continue; 60
47 } 61 verbly::token action = verbly::token::separator("\n", {
48 62 verbly::token::punctuation("?", {
49 verbly::noun rhmnoun = nounq.front(); 63 "What do you call",
50 64 verbly::token::definiteArticle(synonym),
51 auto hypq = database.nouns().hypernym_of(rhmnoun).random().limit(1).run(); 65 hypernym
52 if (hypq.empty()) 66 }),
53 { 67 verbly::token::capitalize(
54 continue; 68 verbly::token::punctuation("!", {
55 } 69 verbly::token::definiteArticle(adjective),
56 70 noun
57 verbly::noun hyp = hypq.front(); 71 }))
58 72 });
59 auto synq = database.adjectives().synonym_of(rhmadj).random().limit(1).run(); 73
60 if (synq.empty()) 74 std::string result = action.compile();
61 { 75 std::cout << result << std::endl;
62 continue; 76
63 }
64
65 verbly::adjective syn = synq.front();
66
67 std::stringstream result;
68 if (syn.starts_with_vowel_sound())
69 {
70 result << "What do you call an " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl;
71 } else {
72 result << "What do you call a " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl;
73 }
74
75 if (rhmadj.starts_with_vowel_sound())
76 {
77 result << "An " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl;
78 } else {
79 result << "A " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl;
80 }
81
82 try 77 try
83 { 78 {
84 client.updateStatus(result.str()); 79 client.updateStatus(result);
85 80
86 std::cout << "Tweeted!" << std::endl; 81 std::cout << "Tweeted!" << std::endl;
87 } catch (const twitter::twitter_error& e) 82 } catch (const twitter::twitter_error& e)
88 { 83 {
@@ -90,7 +85,10 @@ int main(int argc, char** argv)
90 } 85 }
91 86
92 std::cout << "Waiting..." << std::endl; 87 std::cout << "Waiting..." << std::endl;
93 88
94 std::this_thread::sleep_for(std::chrono::hours(1)); 89 std::this_thread::sleep_for(std::chrono::hours(1));
90
91 std::cout << std::endl;
95 } 92 }
96} 93}
94