#include #include #include #include #include #include #include #include int main(int argc, char** argv) { if (argc != 2) { std::cout << "usage: fruity [configfile]" << std::endl; return -1; } std::random_device random_device; std::mt19937 random_engine{random_device()}; std::string configfile(argv[1]); YAML::Node config = YAML::LoadFile(configfile); twitter::auth auth; auth.setConsumerKey(config["consumer_key"].as()); auth.setConsumerSecret(config["consumer_secret"].as()); auth.setAccessKey(config["access_key"].as()); auth.setAccessSecret(config["access_secret"].as()); twitter::client client(auth); verbly::database database(config["verbly_datafile"].as()); verbly::filter fruitFilter = ( (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) && (verbly::notion::fullHypernyms %= ( (verbly::notion::wnid == 113134947) // fruit || (verbly::notion::wnid == 107705931)))); // edible fruit verbly::query fruitQuery = database.words(fruitFilter); verbly::query pertainymQuery = database.words( (verbly::notion::partOfSpeech == verbly::part_of_speech::adjective) && (verbly::word::antiPertainyms)); verbly::query antiMannernymQuery = database.words( (verbly::notion::partOfSpeech == verbly::part_of_speech::adjective) && (verbly::word::mannernyms)); for (;;) { std::cout << "Generating tweet" << std::endl; verbly::word fruit = fruitQuery.first(); verbly::word hyper = database.words(verbly::notion::hyponyms %= fruit).first(); std::list tokens; int choice = std::uniform_int_distribution(0,2)(random_engine); if (choice == 0) { verbly::word descriptor = pertainymQuery.first(); tokens.push_back(descriptor.getBaseForm()); } else if (choice == 1) { verbly::word descriptor = antiMannernymQuery.first(); tokens.push_back(descriptor.getBaseForm()); } verbly::filter thingFilter = ( (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) && (verbly::form::proper == false) && (verbly::form::complexity == 1)); choice = std::uniform_int_distribution(0,4)(random_engine); if (choice < 3) { if (choice == 0) { // plant thingFilter &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 100017222)); } else if (choice == 1) { // drug thingFilter &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 103247620)); } else if (choice == 2) { // animal thingFilter &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 100015388)); } verbly::word thing = database.words(thingFilter).first(); tokens.push_back(thing.getBaseForm()); } verbly::query similarQuery = database.words( (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) && (verbly::notion::fullHypernyms %= hyper) && (verbly::form::text != fruit.getBaseForm()) && (verbly::word::id != hyper.getId()) && (verbly::form::proper == false) && (verbly::form::complexity == 1)); std::vector similarResults = similarQuery.all(); if (!similarResults.empty()) { tokens.push_back(similarResults.front().getBaseForm()); } else { verbly::query differentQuery = database.words( fruitFilter && (verbly::form::text != fruit.getBaseForm()) && (verbly::word::id != hyper.getId()) && (verbly::form::proper == false) && (verbly::form::complexity == 1)); tokens.push_back(differentQuery.first().getBaseForm()); } std::string fruitName = verbly::implode(std::begin(tokens), std::end(tokens), " "); std::ostringstream result; result << fruit.getBaseForm(); result << "? "; choice = std::uniform_int_distribution(0,3)(random_engine); if (choice == 0) { result << "Oh, you mean "; result << fruitName; } else if (choice == 1) { result << "Don't you mean "; result << fruitName; result << "?"; } else if (choice == 2) { result << "You mean "; result << fruitName; result << "!"; } else if (choice == 3) { result << "Pfft, everyone just calls it "; result << fruitName; result << " now"; } std::string tweet = result.str(); tweet.resize(140); try { client.updateStatus(tweet); std::cout << tweet << std::endl; } catch (const twitter::twitter_error& e) { std::cout << "Twitter error: " << e.what() << std::endl; } std::this_thread::sleep_for(std::chrono::hours(1)); } }