about summary refs log tree commit diff stats
path: root/furries.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-03-09 23:30:14 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-03-09 23:30:14 -0500
commit41decb9a671e4d0fbbe12533372435ec6ede2246 (patch)
tree35cd3c7bc9ba623a62aefc7492ed6a5fd157e40d /furries.cpp
parent4d8fd1c470c5f2c190f082683321b40a566cf1c9 (diff)
downloadfurries-41decb9a671e4d0fbbe12533372435ec6ede2246.tar.gz
furries-41decb9a671e4d0fbbe12533372435ec6ede2246.tar.bz2
furries-41decb9a671e4d0fbbe12533372435ec6ede2246.zip
Started verbly rewrite
verbly is intended to be a general use natural language generation library. Here, I'm using it to simply generate random verbs or adjectives. A schema for the sqlite database is provided, and for testing I manually added data. A generator program is being written that will generate a database from WordNet, VerbNet, PropBank, and AGID data.
Diffstat (limited to 'furries.cpp')
-rw-r--r--furries.cpp243
1 files changed, 96 insertions, 147 deletions
diff --git a/furries.cpp b/furries.cpp index 15c4657..2d0fb23 100644 --- a/furries.cpp +++ b/furries.cpp
@@ -1,16 +1,85 @@
1#include <yaml-cpp/yaml.h> 1#include <yaml-cpp/yaml.h>
2#include <iostream> 2#include <iostream>
3#include <mysql/mysql.h>
4#include <cstdlib> 3#include <cstdlib>
5#include <ctime> 4#include <ctime>
6#include <sstream> 5#include <sstream>
7#include <twitcurl.h> 6#include <twitcurl.h>
7#include "verbly/verbly.h"
8 8
9int db_error(MYSQL* driver, const char* error) 9class fill_blanks {
10{ 10 private:
11 std::cout << error << ": " << mysql_error(driver) << std::endl; 11 verbly::data& database;
12 return 1; 12
13} 13 public:
14 fill_blanks(verbly::data& database) : database(database)
15 {
16
17 }
18
19 void visit(std::unique_ptr<verbly::token>& it)
20 {
21 switch (it->token_type())
22 {
23 case verbly::type::utterance:
24 {
25 auto& action = *dynamic_cast<verbly::utterance_token*>(it.get());
26 for (auto& tkn : action)
27 {
28 if (!tkn->complete())
29 {
30 visit(tkn);
31
32 break;
33 }
34 }
35
36 break;
37 }
38
39 case verbly::type::fillin:
40 {
41 auto& tkn = *dynamic_cast<verbly::fillin_token*>(it.get());
42 switch (tkn.fillin_type())
43 {
44 case verbly::fillin_type::participle_phrase:
45 {
46 const verbly::verb& v = database.verbs().random(true).limit(1).run().front();
47 /*verbly::utterance_token phrase = verbly::random(v.frames).make_utterance();
48 while (std::begin(phrase)->token_type() != verbly::type::verb)
49 {
50 phrase.erase(std::begin(phrase));
51 }
52
53 *std::begin(phrase) = verbly::verb_token(v).conjugate(verbly::conjugation::present_participle);
54 *it = phrase;*/
55 auto avt = std::make_unique<verbly::verb_token>(v);
56 avt->conjugate(verbly::conjugation::present_participle);
57 it = std::move(avt);
58
59 break;
60 }
61
62 case verbly::fillin_type::adjective:
63 {
64 const verbly::adjective& adj = database.adjectives().random(true).limit(1).run().front();
65 it = std::make_unique<verbly::string_token>(adj.value);
66
67 break;
68 }
69
70 default:
71 {
72 it = std::make_unique<verbly::string_token>("*the reality of the situation*");
73
74 break;
75 }
76 }
77
78 break;
79 }
80 }
81 }
82};
14 83
15int main(int argc, char** argv) 84int main(int argc, char** argv)
16{ 85{
@@ -21,13 +90,7 @@ int main(int argc, char** argv)
21 const char* user = config["user"].as<std::string>().c_str(); 90 const char* user = config["user"].as<std::string>().c_str();
22 const char* pass = config["pass"].as<std::string>().c_str(); 91 const char* pass = config["pass"].as<std::string>().c_str();
23 const char* db = config["db"].as<std::string>().c_str(); 92 const char* db = config["db"].as<std::string>().c_str();
24 93
25 MYSQL* driver = mysql_init(NULL);
26 if (!mysql_real_connect(driver, host, user, pass, db, 0, NULL, 0))
27 {
28 return db_error(driver, "Error connecting to database");
29 }
30
31 twitCurl twitter; 94 twitCurl twitter;
32 twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>()); 95 twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>());
33 twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>()); 96 twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>());
@@ -38,141 +101,29 @@ int main(int argc, char** argv)
38 { 101 {
39 std::cout << "Generating tweet" << std::endl; 102 std::cout << "Generating tweet" << std::endl;
40 103
41 std::stringstream output; 104 std::vector<verbly::utterance_token> forms;
42 output << "the furries are "; 105 forms.push_back({
43 106 new verbly::string_token("the furries are"),
44 //if (rand() % 2 == 0) 107 new verbly::fillin_token(verbly::fillin_type::participle_phrase)
45 { 108 });
46 // Adverb(s) + Adjective 109 forms.push_back({
47 while (rand() % 4 == 0) 110 new verbly::string_token("the furries are"),
48 { 111 new verbly::fillin_token(verbly::fillin_type::adjective)
49 const char* getadverb = "SELECT ss1.word FROM wn_pertainym INNER JOIN wn_synset AS ss1 ON wn_pertainym.synset_id_1 = ss1.synset_id AND wn_pertainym.wnum_1 = ss1.w_num INNER JOIN wn_synset AS ss2 ON wn_pertainym.synset_id_2 = ss2.synset_id AND wn_pertainym.wnum_2 = ss2.w_num WHERE ss1.ss_type = 'r' ORDER BY RAND() LIMIT 1"; 112 });
50 if (mysql_query(driver, getadverb)) return db_error(driver, "Query failed");
51 MYSQL_RES* getadverb2 = mysql_use_result(driver); if (getadverb2 == NULL) return db_error(driver, "Query failed");
52 MYSQL_ROW getadverb3 = mysql_fetch_row(getadverb2); if (getadverb3 == NULL) return db_error(driver, "Query failed");
53 output << getadverb3[0] << " ";
54 mysql_free_result(getadverb2);
55 }
56
57 const char* getword = "SELECT word FROM wn_synset WHERE ss_type = 'a' OR ss_type = 's' ORDER BY RAND() LIMIT 1";
58 if (mysql_query(driver, getword)) return db_error(driver, "Query failed");
59 MYSQL_RES* getword2 = mysql_use_result(driver); if (getword2 == NULL) return db_error(driver, "Query failed");
60 MYSQL_ROW getword3 = mysql_fetch_row(getword2); if (getword3 == NULL) return db_error(driver, "Query failed");
61 output << getword3[0];
62 mysql_free_result(getword2);
63 } /*else {
64 // Verb phrase
65 const char* getword = "SELECT word FROM wn_synset WHERE ss_type = 'a ' OR ss_type = 's' ORDER BY RAND() LIMIT 1";
66 if (mysql_query(driver, getword)) return db_error(driver, "Query failed");
67 MYSQL_RES* getword2 = mysql_use_result(driver); if (getword2 == NULL) return db_error(driver, "Query failed");
68 MYSQL_ROW getword3 = mysql_fetch_row(getword2); if (getword3 == NULL) return db_error(driver, "Query failed");
69 }
70 113
71 114 verbly::data database {"data.sqlite3"};
72 115 fill_blanks yeah {database};
73 116 std::unique_ptr<verbly::token> action = std::make_unique<verbly::utterance_token>(forms[rand() % forms.size()]);
74 if (rand() % 2 == 0) 117 while (!action->complete())
75 { 118 {
76 std::stringstream ispart; 119 yeah.visit(action);
77 ispart << "SELECT wn_verb_frame.f_num FROM wn_participle INNER JOIN wn_verb_frame ON wn_verb_frame.synset_id_1 = synset_id_2 AND (wn_verb_frame.w_num = wnum_2 OR wn_verb_frame.w_num = 0) WHERE wn_participle.synset_id_1 = " << wordssid << " AND wn_participle.wnum_1 = " << wordnum;
78 if (mysql_query(driver, ispart.str().c_str())) return db_error(driver, "Query failed");
79 MYSQL_RES* ispart2 = mysql_use_result(driver); if (ispart2 == NULL) return db_error(driver, "Query failed");
80 MYSQL_ROW ispart3 = mysql_fetch_row(ispart2);
81 mysql_free_result(ispart2);
82
83 if (ispart3 != NULL)
84 {
85 int frame = atoi(ispart3[0]);
86 std::cout << "frame " << frame << std::endl;
87
88 if (frame == 4 || frame == 22)
89 {
90 // the furries are ----ing *prepositional phrase*
91 // ex: the furries are laughing over there
92 } else if (frame == 5)
93 {
94 // the furries are ----ing something *adj/n*
95 // ex: the furries are regarding life inconsequential
96 } else if (frame == 6 || frame == 7)
97 {
98 // the furries are ----ing *adj/n*
99 // ex: the furries are turning gay
100 } else if (frame == 8 || frame == 9 || frame == 10 || frame == 11)
101 {
102 // the furries are ----ing something/somebody
103 // ex: the furries are holding hostages
104 } else if (frame == 12 || frame == 27)
105 {
106 // the furries are ----ing to somebody
107 // ex: the furries are appealing to God
108 } else if (frame == 13)
109 {
110 // the furries are ----ing on something
111 // ex: the furries are lecturing on heterosexuality
112 } else if (frame == 14)
113 {
114 // the furries are ----ing somebody something
115 // ex: the furries are reading your mom the menu
116 } else if (frame == 15)
117 {
118 // the furries are ----ing something to somebody
119 // ex: the furries are pitching a product to Apple
120 } else if (frame == 16)
121 {
122 // the furries are ----ing something from somebody
123 // ex: the furries are separating your money from you
124 } else if (frame == 17)
125 {
126 // the furries are ----ing somebody with something
127 // ex: the furries are injecting me with solemnity
128 } else if (frame == 18)
129 {
130 // the furries are ----ing somebody of something
131 // ex: the furries are depriving me of hope
132 } else if (frame == 19)
133 {
134 // the furries are ----ing something on somebody
135 // ex: the furries are forcing pervision on us
136 } else if (frame == 20 || frame == 21)
137 {
138 // the furries are ----ing somebody/something *prepositional phrase*
139 // ex: the furries are leaving us behind
140 } else if (frame == 24)
141 {
142 // the furries are ----ing somebody to INF
143 // ex: the furries are getting us to eat
144 } else if (frame == 25)
145 {
146 // the furries are ----ing somebody INF
147 // ex: the furries are making us procreate
148 } else if (frame == 26)
149 {
150 // the furries are ----ing that CLAUSE
151 // ex: the furries are understaing that life is precious
152 } else if (frame == 28)
153 {
154 // the furries are ----ing to INF
155 // ex: the furries are beginning to understand
156 } else if (frame == 29)
157 {
158 // the furries are ----ing whether to INF
159 // ex: the furries are deciding whether to hallucinate
160 } else if (frame == 30)
161 {
162 // the furries are ----ing somebody into V-ing something
163 // ex: the furries are tempting me into consecrating a magnet
164 } else if (frame == 31)
165 {
166 // the furries are ----ing something with something
167 // ex: the furries are replacing existence with solidarity
168 }
169 }
170 } 120 }
171 */
172 121
173 std::string result = output.str(); 122 std::string result = action->compile();
174 result.resize(140); 123 result.resize(140);
175 124
125 std::cout << result << std::endl;
126 /*
176 std::string replyMsg; 127 std::string replyMsg;
177 if (twitter.statusUpdate(result)) 128 if (twitter.statusUpdate(result))
178 { 129 {
@@ -181,11 +132,9 @@ int main(int argc, char** argv)
181 } else { 132 } else {
182 twitter.getLastCurlError(replyMsg); 133 twitter.getLastCurlError(replyMsg);
183 std::cout << "Curl error: " << replyMsg << std::endl; 134 std::cout << "Curl error: " << replyMsg << std::endl;
184 } 135 }*/
185 136
186 std::cout << "Waiting" << std::endl; 137 std::cout << "Waiting" << std::endl;
187 sleep(60 * 60 * 3); 138 sleep(/*60 * 60 * */ 3);
188 } 139 }
189
190 mysql_close(driver);
191} 140}