summary refs log tree commit diff stats
path: root/fruity.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-02-05 11:35:04 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-02-05 11:35:04 -0500
commit55fc0f15396fc2d37edd5a64dff314ae30e3cbdd (patch)
tree29897757a230940256903d9f271c1f428d186d2f /fruity.cpp
parentdda6e3d4e3dcfbfb2fc7ac66c976a1e032722df5 (diff)
downloadfruity-55fc0f15396fc2d37edd5a64dff314ae30e3cbdd.tar.gz
fruity-55fc0f15396fc2d37edd5a64dff314ae30e3cbdd.tar.bz2
fruity-55fc0f15396fc2d37edd5a64dff314ae30e3cbdd.zip
Updated verbly (new API)
Also updated libtwitter++
Diffstat (limited to 'fruity.cpp')
-rw-r--r--fruity.cpp82
1 files changed, 54 insertions, 28 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)
29 29
30 twitter::client client(auth); 30 twitter::client client(auth);
31 31
32 verbly::data database {config["verbly_datafile"].as<std::string>()}; 32 verbly::database database(config["verbly_datafile"].as<std::string>());
33 33
34 verbly::noun fruit1 = database.nouns().with_wnid(113134947).run().front(); // fruit 34 verbly::filter fruitFilter = (
35 verbly::noun fruit2 = database.nouns().with_wnid(107705931).run().front(); // edible fruit 35 (verbly::notion::partOfSpeech == verbly::part_of_speech::noun)
36 verbly::filter<verbly::noun> fruitFilter {fruit1, fruit2}; 36 && (verbly::notion::fullHypernyms %= (
37 fruitFilter.set_orlogic(true); 37 (verbly::notion::wnid == 113134947) // fruit
38 || (verbly::notion::wnid == 107705931)))); // edible fruit
38 39
39 verbly::noun plants = database.nouns().with_wnid(100017222).run().front(); // plant 40 verbly::query<verbly::word> fruitQuery = database.words(fruitFilter);
40 verbly::noun drugs = database.nouns().with_wnid(103247620).run().front(); // drug 41
41 verbly::noun animals = database.nouns().with_wnid(100015388).run().front(); // animal 42 verbly::query<verbly::word> pertainymQuery = database.words(
43 (verbly::notion::partOfSpeech == verbly::part_of_speech::adjective)
44 && (verbly::word::antiPertainyms));
45
46 verbly::query<verbly::word> antiMannernymQuery = database.words(
47 (verbly::notion::partOfSpeech == verbly::part_of_speech::adjective)
48 && (verbly::word::mannernyms));
42 49
43 for (;;) 50 for (;;)
44 { 51 {
45 std::cout << "Generating tweet" << std::endl; 52 std::cout << "Generating tweet" << std::endl;
46 53
47 auto n1 = database.nouns().full_hyponym_of(fruitFilter).random().limit(1).run(); 54 verbly::word fruit = fruitQuery.first();
48 auto n1w = n1.front(); 55 verbly::word hyper = database.words(verbly::notion::hyponyms %= fruit).first();
49 auto n1hq = database.nouns().hypernym_of(n1w).limit(1).run();
50 auto n1h = n1hq.front();
51 56
52 std::list<std::string> tokens; 57 std::list<std::string> tokens;
53 58
54 int choice = std::uniform_int_distribution<int>(0,2)(random_engine); 59 int choice = std::uniform_int_distribution<int>(0,2)(random_engine);
55 if (choice == 0) 60 if (choice == 0)
56 { 61 {
57 auto descriptor = database.adjectives().is_pertainymic().random().limit(1).run(); 62 verbly::word descriptor = pertainymQuery.first();
58 tokens.push_back(descriptor.front().base_form()); 63 tokens.push_back(descriptor.getBaseForm());
59 } else if (choice == 1) 64 } else if (choice == 1)
60 { 65 {
61 auto descriptor = database.adjectives().is_mannernymic().random().limit(1).run(); 66 verbly::word descriptor = antiMannernymQuery.first();
62 tokens.push_back(descriptor.front().base_form()); 67 tokens.push_back(descriptor.getBaseForm());
63 } 68 }
64 69
65 auto plantThing = database.nouns(); 70 verbly::filter thingFilter = (
71 (verbly::notion::partOfSpeech == verbly::part_of_speech::noun)
72 && (verbly::form::proper == false)
73 && (verbly::form::complexity == 1));
74
66 choice = std::uniform_int_distribution<int>(0,4)(random_engine); 75 choice = std::uniform_int_distribution<int>(0,4)(random_engine);
67 if (choice < 3) 76 if (choice < 3)
68 { 77 {
69 if (choice == 0) 78 if (choice == 0)
70 { 79 {
71 plantThing.full_hyponym_of(plants); 80 // plant
81 thingFilter &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 100017222));
72 } else if (choice == 1) 82 } else if (choice == 1)
73 { 83 {
74 plantThing.full_hyponym_of(drugs); 84 // drug
85 thingFilter &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 103247620));
75 } else if (choice == 2) 86 } else if (choice == 2)
76 { 87 {
77 plantThing.full_hyponym_of(animals); 88 // animal
89 thingFilter &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 100015388));
78 } 90 }
79 91
80 plantThing.is_not_proper().with_complexity(1).random().limit(1); 92 verbly::word thing = database.words(thingFilter).first();
81 tokens.push_back(plantThing.run().front().base_form()); 93 tokens.push_back(thing.getBaseForm());
82 } 94 }
83 95
84 auto similar = database.nouns().full_hyponym_of(n1h).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run(); 96 verbly::query<verbly::word> similarQuery = database.words(
85 if (!similar.empty()) 97 (verbly::notion::partOfSpeech == verbly::part_of_speech::noun)
98 && (verbly::notion::fullHypernyms %= hyper)
99 && (verbly::form::text != fruit.getBaseForm())
100 && (verbly::word::id != hyper.getId())
101 && (verbly::form::proper == false)
102 && (verbly::form::complexity == 1));
103 std::vector<verbly::word> similarResults = similarQuery.all();
104
105 if (!similarResults.empty())
86 { 106 {
87 tokens.push_back(similar.front().base_form()); 107 tokens.push_back(similarResults.front().getBaseForm());
88 } else { 108 } else {
89 auto different = database.nouns().full_hyponym_of(fruitFilter).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run(); 109 verbly::query<verbly::word> differentQuery = database.words(
90 tokens.push_back(different.front().base_form()); 110 fruitFilter
111 && (verbly::form::text != fruit.getBaseForm())
112 && (verbly::word::id != hyper.getId())
113 && (verbly::form::proper == false)
114 && (verbly::form::complexity == 1));
115
116 tokens.push_back(differentQuery.first().getBaseForm());
91 } 117 }
92 118
93 std::string fruitName = verbly::implode(std::begin(tokens), std::end(tokens), " "); 119 std::string fruitName = verbly::implode(std::begin(tokens), std::end(tokens), " ");
94 120
95 std::ostringstream result; 121 std::ostringstream result;
96 result << n1.front().base_form(); 122 result << fruit.getBaseForm();
97 result << "? "; 123 result << "? ";
98 124
99 choice = std::uniform_int_distribution<int>(0,3)(random_engine); 125 choice = std::uniform_int_distribution<int>(0,3)(random_engine);