From 43e74c07a195738ce44c0f9628bc9795f623b2e0 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 4 Jan 2017 10:54:11 -0500 Subject: Forked repository to make fruity --- CMakeLists.txt | 10 ++--- fruity.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ owo.cpp | 58 ------------------------- 3 files changed, 137 insertions(+), 63 deletions(-) create mode 100644 fruity.cpp delete mode 100644 owo.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 805e684..84e43d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required (VERSION 3.1) -project (owo) +project (fruity) add_subdirectory(vendor/verbly) add_subdirectory(vendor/libtwittercpp) add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) include_directories(vendor/verbly/lib vendor/libtwittercpp/src vendor/yaml-cpp/include) -add_executable(owo owo.cpp) -set_property(TARGET owo PROPERTY CXX_STANDARD 11) -set_property(TARGET owo PROPERTY CXX_STANDARD_REQUIRED ON) -target_link_libraries(owo verbly twitter++ yaml-cpp) +add_executable(fruity fruity.cpp) +set_property(TARGET fruity PROPERTY CXX_STANDARD 11) +set_property(TARGET fruity PROPERTY CXX_STANDARD_REQUIRED ON) +target_link_libraries(fruity verbly twitter++ yaml-cpp) diff --git a/fruity.cpp b/fruity.cpp new file mode 100644 index 0000000..b88bde7 --- /dev/null +++ b/fruity.cpp @@ -0,0 +1,132 @@ +#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::data database {config["verbly_datafile"].as()}; + + verbly::noun fruit = database.nouns().with_wnid(113134947).run().front(); // fruit + verbly::noun plants = database.nouns().with_wnid(100017222).run().front(); // plant + verbly::noun drugs = database.nouns().with_wnid(103247620).run().front(); // drug + verbly::noun animals = database.nouns().with_wnid(100015388).run().front(); // animal + + for (;;) + { + std::cout << "Generating tweet" << std::endl; + + auto n1 = database.nouns().full_hyponym_of(fruit).random().limit(1).run(); + auto n1w = n1.front(); + auto n1hq = database.nouns().hypernym_of(n1w).limit(1).run(); + auto n1h = n1hq.front(); + + std::list tokens; + + int choice = std::uniform_int_distribution(0,2)(random_engine); + if (choice == 0) + { + auto descriptor = database.adjectives().is_pertainymic().random().limit(1).run(); + tokens.push_back(descriptor.front().base_form()); + } else if (choice == 1) + { + auto descriptor = database.adjectives().is_mannernymic().random().limit(1).run(); + tokens.push_back(descriptor.front().base_form()); + } + + auto plantThing = database.nouns(); + choice = std::uniform_int_distribution(0,4)(random_engine); + if (choice < 3) + { + if (choice == 0) + { + plantThing.full_hyponym_of(plants); + } else if (choice == 1) + { + plantThing.full_hyponym_of(drugs); + } else if (choice == 2) + { + plantThing.full_hyponym_of(animals); + } + + plantThing.is_not_proper().with_complexity(1).random().limit(1); + tokens.push_back(plantThing.run().front().base_form()); + } + + auto similar = database.nouns().full_hyponym_of(n1h).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run(); + if (!similar.empty()) + { + tokens.push_back(similar.front().base_form()); + } else { + auto different = database.nouns().full_hyponym_of(fruit).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run(); + tokens.push_back(different.front().base_form()); + } + + std::string fruitName = verbly::implode(std::begin(tokens), std::end(tokens), " "); + + std::ostringstream result; + result << n1.front().base_form(); + 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)); + } +} diff --git a/owo.cpp b/owo.cpp deleted file mode 100644 index f66e689..0000000 --- a/owo.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char** argv) -{ - if (argc != 2) - { - std::cout << "usage: owo [configfile]" << std::endl; - return -1; - } - - 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::data database {config["verbly_datafile"].as()}; - - verbly::noun bp = database.nouns().with_wnid(105220461).run().front(); // body part - verbly::noun pp = database.nouns().with_wnid(104723816).run().front(); // quality - verbly::noun cp = database.nouns().with_wnid(103051540).run().front(); // clothing - verbly::filter filt {bp, pp, cp}; - filt.set_orlogic(true); - - for (;;) - { - std::cout << "Generating tweet" << std::endl; - - auto ns = database.nouns().full_hyponym_of(filt).is_not_proper().random().limit(1).run(); - verbly::noun n = ns.front(); - - std::string result = "*notices ur " + n.base_form() + "* OwO whats this..?"; - result.resize(140); - - try - { - client.updateStatus(result); - } catch (const twitter::twitter_error& e) - { - std::cout << "Twitter error: " << e.what() << std::endl; - } - - std::cout << result << std::endl; - - std::this_thread::sleep_for(std::chrono::hours(1)); - } -} -- cgit 1.4.1