diff options
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | CMakeLists.txt | 9 | ||||
| -rw-r--r-- | chemist.cpp | 63 | ||||
| -rw-r--r-- | data.txt | 59 | ||||
| m--------- | vendor/libtwittercpp | 0 | ||||
| m--------- | vendor/twitcurl | 0 | ||||
| m--------- | vendor/verbly | 0 |
7 files changed, 84 insertions, 50 deletions
| diff --git a/.gitmodules b/.gitmodules index 08a42de..2d58700 100644 --- a/.gitmodules +++ b/.gitmodules | |||
| @@ -7,3 +7,6 @@ | |||
| 7 | [submodule "vendor/yaml-cpp"] | 7 | [submodule "vendor/yaml-cpp"] |
| 8 | path = vendor/yaml-cpp | 8 | path = vendor/yaml-cpp |
| 9 | url = https://github.com/jbeder/yaml-cpp | 9 | url = https://github.com/jbeder/yaml-cpp |
| 10 | [submodule "vendor/libtwittercpp"] | ||
| 11 | path = vendor/libtwittercpp | ||
| 12 | url = https://github.com/hatkirby/libtwittercpp | ||
| diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d19b9..49b0d2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -3,15 +3,12 @@ project (chemist) | |||
| 3 | 3 | ||
| 4 | set(CMAKE_BUILD_TYPE Debug) | 4 | set(CMAKE_BUILD_TYPE Debug) |
| 5 | 5 | ||
| 6 | find_package(PkgConfig) | ||
| 7 | pkg_check_modules(sqlite3 sqlite3 REQUIRED) | ||
| 8 | |||
| 9 | add_subdirectory(vendor/twitcurl/libtwitcurl) | ||
| 10 | add_subdirectory(vendor/verbly) | 6 | add_subdirectory(vendor/verbly) |
| 11 | add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) | 7 | add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) |
| 8 | add_subdirectory(vendor/libtwittercpp) | ||
| 12 | 9 | ||
| 13 | include_directories(vendor/twitcurl/libtwitcurl ${sqlite3_INCLUDE_DIR} vendor/verbly/lib vendor/yaml-cpp/include) | 10 | include_directories(vendor/verbly/lib vendor/yaml-cpp/include vendor/libtwittercpp/src) |
| 14 | add_executable(chemist chemist.cpp) | 11 | add_executable(chemist chemist.cpp) |
| 15 | set_property(TARGET chemist PROPERTY CXX_STANDARD 11) | 12 | set_property(TARGET chemist PROPERTY CXX_STANDARD 11) |
| 16 | set_property(TARGET chemist PROPERTY CXX_STANDARD_REQUIRED ON) | 13 | set_property(TARGET chemist PROPERTY CXX_STANDARD_REQUIRED ON) |
| 17 | target_link_libraries(chemist verbly ${sqlite3_LIBRARIES} yaml-cpp twitcurl curl) | 14 | target_link_libraries(chemist verbly twitter++ yaml-cpp) |
| diff --git a/chemist.cpp b/chemist.cpp index fbf83a8..8b00d12 100644 --- a/chemist.cpp +++ b/chemist.cpp | |||
| @@ -1,23 +1,24 @@ | |||
| 1 | #include <yaml-cpp/yaml.h> | 1 | #include <yaml-cpp/yaml.h> |
| 2 | #include <iostream> | 2 | #include <iostream> |
| 3 | #include <cstdlib> | ||
| 4 | #include <ctime> | ||
| 5 | #include <sstream> | 3 | #include <sstream> |
| 6 | #include <twitcurl.h> | ||
| 7 | #include <verbly.h> | 4 | #include <verbly.h> |
| 8 | #include <unistd.h> | 5 | #include <fstream> |
| 6 | #include <twitter.h> | ||
| 7 | #include <random> | ||
| 8 | #include <chrono> | ||
| 9 | #include <thread> | ||
| 9 | 10 | ||
| 10 | int main(int argc, char** argv) | 11 | int main(int argc, char** argv) |
| 11 | { | 12 | { |
| 12 | srand(time(NULL)); | ||
| 13 | |||
| 14 | YAML::Node config = YAML::LoadFile("config.yml"); | 13 | YAML::Node config = YAML::LoadFile("config.yml"); |
| 15 | 14 | ||
| 16 | twitCurl twitter; | 15 | twitter::auth auth; |
| 17 | twitter.getOAuth().setConsumerKey(config["consumer_key"].as<std::string>()); | 16 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); |
| 18 | twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as<std::string>()); | 17 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); |
| 19 | twitter.getOAuth().setOAuthTokenKey(config["access_key"].as<std::string>()); | 18 | auth.setAccessKey(config["access_key"].as<std::string>()); |
| 20 | twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as<std::string>()); | 19 | auth.setAccessSecret(config["access_secret"].as<std::string>()); |
| 20 | |||
| 21 | twitter::client client(auth); | ||
| 21 | 22 | ||
| 22 | std::map<std::string, std::vector<std::string>> groups; | 23 | std::map<std::string, std::vector<std::string>> groups; |
| 23 | std::ifstream datafile("data.txt"); | 24 | std::ifstream datafile("data.txt"); |
| @@ -51,6 +52,9 @@ int main(int argc, char** argv) | |||
| 51 | } | 52 | } |
| 52 | } | 53 | } |
| 53 | 54 | ||
| 55 | std::random_device random_device; | ||
| 56 | std::mt19937 random_engine{random_device()}; | ||
| 57 | |||
| 54 | verbly::data database {"data.sqlite3"}; | 58 | verbly::data database {"data.sqlite3"}; |
| 55 | for (;;) | 59 | for (;;) |
| 56 | { | 60 | { |
| @@ -77,6 +81,9 @@ int main(int argc, char** argv) | |||
| 77 | if (canontkn == "NOUN") | 81 | if (canontkn == "NOUN") |
| 78 | { | 82 | { |
| 79 | result = database.nouns().is_not_proper().random().limit(1).with_complexity(1).run().front().singular_form(); | 83 | result = database.nouns().is_not_proper().random().limit(1).with_complexity(1).run().front().singular_form(); |
| 84 | } else if (canontkn == "ATTRIBUTE") | ||
| 85 | { | ||
| 86 | result = database.nouns().random().limit(1).full_hyponym_of(database.nouns().with_wnid(100024264).limit(1).run().front()).run().front().singular_form(); | ||
| 80 | } else if (canontkn == "ADJECTIVE") | 87 | } else if (canontkn == "ADJECTIVE") |
| 81 | { | 88 | { |
| 82 | result = database.adjectives().with_complexity(1).random().limit(1).run().front().base_form(); | 89 | result = database.adjectives().with_complexity(1).random().limit(1).run().front().base_form(); |
| @@ -85,7 +92,9 @@ int main(int argc, char** argv) | |||
| 85 | result = database.verbs().random().limit(1).run().front().ing_form(); | 92 | result = database.verbs().random().limit(1).run().front().ing_form(); |
| 86 | } else if (canontkn == "YEAR") | 93 | } else if (canontkn == "YEAR") |
| 87 | { | 94 | { |
| 88 | result = std::to_string(rand() % 100 + 1916); | 95 | std::uniform_int_distribution<int> yeardist(1916,2015); |
| 96 | int year = yeardist(random_engine); | ||
| 97 | result = std::to_string(year); | ||
| 89 | } else if (canontkn == "REGION") | 98 | } else if (canontkn == "REGION") |
| 90 | { | 99 | { |
| 91 | auto hem1 = database.nouns().with_singular_form("eastern hemisphere").limit(1).run().front(); | 100 | auto hem1 = database.nouns().with_singular_form("eastern hemisphere").limit(1).run().front(); |
| @@ -103,9 +112,14 @@ int main(int argc, char** argv) | |||
| 103 | { | 112 | { |
| 104 | auto bp = database.nouns().with_singular_form("body part").limit(1).run().front(); | 113 | auto bp = database.nouns().with_singular_form("body part").limit(1).run().front(); |
| 105 | result = database.nouns().full_hyponym_of({bp}).with_complexity(1).random().limit(1).run().front().singular_form(); | 114 | result = database.nouns().full_hyponym_of({bp}).with_complexity(1).random().limit(1).run().front().singular_form(); |
| 115 | } else if (canontkn == "\\N") | ||
| 116 | { | ||
| 117 | result = "\n"; | ||
| 106 | } else { | 118 | } else { |
| 107 | auto group = groups[canontkn]; | 119 | auto group = groups[canontkn]; |
| 108 | result = group[rand() % group.size()]; | 120 | std::uniform_int_distribution<int> groupdist(0, group.size()-1); |
| 121 | int groupind = groupdist(random_engine); | ||
| 122 | result = group[groupind]; | ||
| 109 | } | 123 | } |
| 110 | 124 | ||
| 111 | if (modifier == "indefinite") | 125 | if (modifier == "indefinite") |
| @@ -144,18 +158,19 @@ int main(int argc, char** argv) | |||
| 144 | } | 158 | } |
| 145 | 159 | ||
| 146 | action.resize(140); | 160 | action.resize(140); |
| 147 | 161 | ||
| 148 | std::string replyMsg; | 162 | try |
| 149 | if (twitter.statusUpdate(action)) | ||
| 150 | { | 163 | { |
| 151 | twitter.getLastWebResponse(replyMsg); | 164 | client.updateStatus(action); |
| 152 | std::cout << "Twitter message: " << replyMsg << std::endl; | 165 | |
| 153 | } else { | 166 | std::cout << "Tweeted!" << std::endl; |
| 154 | twitter.getLastCurlError(replyMsg); | 167 | } catch (const twitter::twitter_error& e) |
| 155 | std::cout << "Curl error: " << replyMsg << std::endl; | 168 | { |
| 169 | std::cout << "Twitter error: " << e.what() << std::endl; | ||
| 156 | } | 170 | } |
| 157 | 171 | ||
| 158 | std::cout << "Waiting" << std::endl; | 172 | std::cout << "Waiting..." << std::endl; |
| 159 | sleep(60 * 60); | 173 | |
| 174 | std::this_thread::sleep_for(std::chrono::hours(1)); | ||
| 160 | } | 175 | } |
| 161 | } | 176 | } |
| diff --git a/data.txt b/data.txt index 8535d4e..77179de 100644 --- a/data.txt +++ b/data.txt | |||
| @@ -1,27 +1,27 @@ | |||
| 1 | MAIN | 1 | MAIN |
| 2 | {PRIMARY} {SECONDARY} | 2 | {NAME} ({CLASS}){\n}{PRIMARY}{\n}{SECONDARY} |
| 3 | 3 | ||
| 4 | PRIMARY | 4 | PRIMARY |
| 5 | {NAME} is {CLASS:indefinite} commonly used to treat {SYNDROME}. | 5 | Used to treat {SYNDROME} |
| 6 | {NAME} is {CLASS:indefinite} primarily used for {SYNDROME}. | 6 | Treats the {adjective} symptoms of {SYNDROME} |
| 7 | {NAME} is {CLASS:indefinite} prescribed for {SYNDROME}. | 7 | Cures {SYNDROME} |
| 8 | {NAME} is {CLASS:indefinite} approved for treatment of {SYNDROME}, and {SYNDROME}. | 8 | Approved to treat {SYNDROME} and {SYNDROME} |
| 9 | {NAME} is {CLASS:indefinite} used for {SYNDROME} and {SYNDROME}. | 9 | Prescribed for {SYNDROME} |
| 10 | {NAME} is {CLASS:indefinite} used with {EXISTENT} to treat {syndrome}. | 10 | Used with {EXISTENT} to treat {SYNDROME} |
| 11 | {NAME} is {CLASS:indefinite} used in cases of {EXISTENT} overdose. | 11 | Used recreationally as {CLASS:indefinite} |
| 12 | {NAME} is {CLASS:indefinite} used recreationally as {CLASS:indefinite}. | 12 | Used recreationally for {verbing} |
| 13 | {NAME} is {CLASS:indefinite} used recreationally for {verbing}. | ||
| 14 | 13 | ||
| 15 | SECONDARY | 14 | SECONDARY |
| 16 | Developed due to the Great {Noun} Epidemic of {year} in {Region}. | 15 | Developed after {year} {Noun} Pandemic |
| 17 | Frequently prescribed off-label for {SYNDROME}. | 16 | Often used off-label for {SYNDROME} |
| 18 | Sometimes used for {SYNDROME} because of its {verbing} effect. | 17 | Notable for its {adjective} effect |
| 19 | Illegal to own in the US because of its {verbing} effect. | 18 | Controlled in the US due to its {adjective} effect |
| 20 | Developed in {year} to replace {EXISTENT}. | 19 | Developed in {year} to replace {EXISTENT} |
| 21 | Overtook {EXISTENT} due to its {adjective} effect. | 20 | May cause {ADJECTIVE} feelings |
| 22 | Synthesized by {FamousName} in {year} in a {verbing} accident. | 21 | Obsoleted by {EXISTENT} |
| 23 | Used mainly in {year}, before {EXISTENT} became popular. | 22 | Contraindicated by {SYNDROME} |
| 24 | Only legal in {Region} because of its {verbing} effect. | 23 | Contraindicated by {EXISTENT} |
| 24 | Decreases the {adjective} effects of {EXISTENT} | ||
| 25 | 25 | ||
| 26 | SYNDROME | 26 | SYNDROME |
| 27 | irritable {noun} syndrome | 27 | irritable {noun} syndrome |
| @@ -40,6 +40,16 @@ congenital {noun} disease | |||
| 40 | {FamousName}'s disease | 40 | {FamousName}'s disease |
| 41 | {adjective} fever | 41 | {adjective} fever |
| 42 | hypo{noun}ism | 42 | hypo{noun}ism |
| 43 | {EXISTENT} overdose | ||
| 44 | {CLASS} overdose | ||
| 45 | {CLASS} discontinuation syndrome | ||
| 46 | {noun} syndrome | ||
| 47 | low {ATTRIBUTE} | ||
| 48 | |||
| 49 | CLASSIFIER | ||
| 50 | {CLASS:indefinite} | ||
| 51 | {NAME} | ||
| 52 | {EXISTENT} | ||
| 43 | 53 | ||
| 44 | CLASS | 54 | CLASS |
| 45 | analgesic | 55 | analgesic |
| @@ -84,6 +94,7 @@ SSRI | |||
| 84 | anxiolytic | 94 | anxiolytic |
| 85 | antipanic agent | 95 | antipanic agent |
| 86 | tricyclic | 96 | tricyclic |
| 97 | tetracyclic | ||
| 87 | MAOI | 98 | MAOI |
| 88 | SNRI | 99 | SNRI |
| 89 | antiandrogen | 100 | antiandrogen |
| @@ -95,6 +106,7 @@ antiviral drug | |||
| 95 | stimulant | 106 | stimulant |
| 96 | depressant | 107 | depressant |
| 97 | aphrodisiac | 108 | aphrodisiac |
| 109 | {EXISTENT} prodrug | ||
| 98 | 110 | ||
| 99 | EXISTENT | 111 | EXISTENT |
| 100 | fluoxetine | 112 | fluoxetine |
| @@ -153,6 +165,10 @@ Viagra | |||
| 153 | heroin | 165 | heroin |
| 154 | morphine | 166 | morphine |
| 155 | crystal meth | 167 | crystal meth |
| 168 | mirtazapine | ||
| 169 | Remeron | ||
| 170 | Luvox | ||
| 171 | fluvoxamine | ||
| 156 | 172 | ||
| 157 | NAME | 173 | NAME |
| 158 | {PRENAME}{NAMEMID}{NAMEIFX} | 174 | {PRENAME}{NAMEMID}{NAMEIFX} |
| @@ -196,6 +212,7 @@ Me | |||
| 196 | Dibu | 212 | Dibu |
| 197 | Des | 213 | Des |
| 198 | Ha | 214 | Ha |
| 215 | Mir | ||
| 199 | 216 | ||
| 200 | NAMEMID | 217 | NAMEMID |
| 201 | pipra | 218 | pipra |
| @@ -228,6 +245,7 @@ va | |||
| 228 | piva | 245 | piva |
| 229 | flu | 246 | flu |
| 230 | oxy | 247 | oxy |
| 248 | taz | ||
| 231 | {NAMEMID}{NAMEMID} | 249 | {NAMEMID}{NAMEMID} |
| 232 | {NAMEMID}{NAMEMID} | 250 | {NAMEMID}{NAMEMID} |
| 233 | 251 | ||
| @@ -257,4 +275,5 @@ rone | |||
| 257 | ine | 275 | ine |
| 258 | caine | 276 | caine |
| 259 | rane | 277 | rane |
| 260 | ide \ No newline at end of file | 278 | ide |
| 279 | epine \ No newline at end of file | ||
| diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000 | |||
| Subproject febadca7d4e0460aa78f95b53b5e36e51fd2f97 | |||
| diff --git a/vendor/twitcurl b/vendor/twitcurl deleted file mode 160000 | |||
| Subproject 6659e86de7481e50977b7569c75138f7f69ad3c | |||
| diff --git a/vendor/verbly b/vendor/verbly | |||
| Subproject 965a3206df834f846f2c560438c80a707dcee4c | Subproject 6c2aca03c89b37e136ab4c7ea58b485dadc85bc | ||
