From 55fc0f15396fc2d37edd5a64dff314ae30e3cbdd Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 5 Feb 2017 11:35:04 -0500 Subject: Updated verbly (new API) Also updated libtwitter++ --- fruity.cpp | 82 ++++++++++++++++++++++++++++++++++------------------ vendor/libtwittercpp | 2 +- vendor/verbly | 2 +- 3 files changed, 56 insertions(+), 30 deletions(-) diff --git a/fruity.cpp b/fruity.cpp index b4b5171..a189d7c 100644 --- a/fruity.cpp +++ b/fruity.cpp @@ -29,71 +29,97 @@ int main(int argc, char** argv) twitter::client client(auth); - verbly::data database {config["verbly_datafile"].as()}; + verbly::database database(config["verbly_datafile"].as()); - 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::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::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 + 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; - 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(); + 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) { - auto descriptor = database.adjectives().is_pertainymic().random().limit(1).run(); - tokens.push_back(descriptor.front().base_form()); + verbly::word descriptor = pertainymQuery.first(); + tokens.push_back(descriptor.getBaseForm()); } else if (choice == 1) { - auto descriptor = database.adjectives().is_mannernymic().random().limit(1).run(); - tokens.push_back(descriptor.front().base_form()); + verbly::word descriptor = antiMannernymQuery.first(); + tokens.push_back(descriptor.getBaseForm()); } - auto plantThing = database.nouns(); + 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) { - plantThing.full_hyponym_of(plants); + // plant + thingFilter &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 100017222)); } else if (choice == 1) { - plantThing.full_hyponym_of(drugs); + // drug + thingFilter &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 103247620)); } else if (choice == 2) { - plantThing.full_hyponym_of(animals); + // animal + thingFilter &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 100015388)); } - plantThing.is_not_proper().with_complexity(1).random().limit(1); - tokens.push_back(plantThing.run().front().base_form()); + verbly::word thing = database.words(thingFilter).first(); + tokens.push_back(thing.getBaseForm()); } - auto similar = database.nouns().full_hyponym_of(n1h).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run(); - if (!similar.empty()) + 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(similar.front().base_form()); + tokens.push_back(similarResults.front().getBaseForm()); } else { - 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()); + 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 << n1.front().base_form(); + result << fruit.getBaseForm(); result << "? "; choice = std::uniform_int_distribution(0,3)(random_engine); diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp index d90a1e7..df90612 160000 --- a/vendor/libtwittercpp +++ b/vendor/libtwittercpp @@ -1 +1 @@ -Subproject commit d90a1e74c77ba67f25a812609fd49d479bc464dd +Subproject commit df906121dd862c0f704e44f28ee079158c431c41 diff --git a/vendor/verbly b/vendor/verbly index 1f898f3..6cc23ba 160000 --- a/vendor/verbly +++ b/vendor/verbly @@ -1 +1 @@ -Subproject commit 1f898f3bd66c29672275c2c884b17ba662ced626 +Subproject commit 6cc23ba387d0813b801ba094709673a61bac889c -- cgit 1.4.1