From dda6e3d4e3dcfbfb2fc7ac66c976a1e032722df5 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 4 Jan 2017 11:30:28 -0500 Subject: Added "edible fruit" synset to fruit filter I noticed that things like "apple" weren't getting generated, and it turns out that they are not hyponyms of the "fruit" synset. --- fruity.cpp | 42 +++++++++++++++++++++++------------------- 1 file 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) 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 fruit1 = database.nouns().with_wnid(113134947).run().front(); // fruit + verbly::noun fruit2 = database.nouns().with_wnid(107705931).run().front(); // edible fruit + verbly::filter fruitFilter {fruit1, fruit2}; + fruitFilter.set_orlogic(true); + 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 n1 = database.nouns().full_hyponym_of(fruitFilter).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) { @@ -57,7 +61,7 @@ int main(int argc, char** argv) 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) @@ -72,26 +76,26 @@ int main(int argc, char** argv) { 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(); + auto different = database.nouns().full_hyponym_of(fruitFilter).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) { @@ -113,10 +117,10 @@ int main(int argc, char** argv) result << fruitName; result << " now"; } - + std::string tweet = result.str(); tweet.resize(140); - + try { client.updateStatus(tweet); -- cgit 1.4.1