diff options
Diffstat (limited to 'infinite.cpp')
-rw-r--r-- | infinite.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/infinite.cpp b/infinite.cpp index 22de917..f79d201 100644 --- a/infinite.cpp +++ b/infinite.cpp | |||
@@ -433,6 +433,8 @@ class fill_blanks { | |||
433 | int main(int argc, char** argv) | 433 | int main(int argc, char** argv) |
434 | { | 434 | { |
435 | srand(time(NULL)); | 435 | srand(time(NULL)); |
436 | rand(); rand(); rand(); rand(); | ||
437 | |||
436 | Magick::InitializeMagick(nullptr); | 438 | Magick::InitializeMagick(nullptr); |
437 | 439 | ||
438 | int delay = 60 * 60; | 440 | int delay = 60 * 60; |
@@ -450,15 +452,17 @@ int main(int argc, char** argv) | |||
450 | { | 452 | { |
451 | std::cout << "Generating text..." << std::endl; | 453 | std::cout << "Generating text..." << std::endl; |
452 | 454 | ||
453 | std::vector<std::string> forms; | 455 | std::map<std::string, std::vector<std::string>> groups; |
454 | std::ifstream datafile("forms.txt"); | 456 | std::ifstream datafile("forms.txt"); |
455 | if (!datafile.is_open()) | 457 | if (!datafile.is_open()) |
456 | { | 458 | { |
457 | std::cout << "Could not find forms.txt" << std::endl; | 459 | std::cout << "Could not find forms.txt" << std::endl; |
458 | return 1; | 460 | return 1; |
459 | } | 461 | } |
460 | 462 | ||
463 | bool newgroup = true; | ||
461 | std::string line; | 464 | std::string line; |
465 | std::string curgroup; | ||
462 | while (getline(datafile, line)) | 466 | while (getline(datafile, line)) |
463 | { | 467 | { |
464 | if (line.back() == '\r') | 468 | if (line.back() == '\r') |
@@ -466,13 +470,24 @@ int main(int argc, char** argv) | |||
466 | line.pop_back(); | 470 | line.pop_back(); |
467 | } | 471 | } |
468 | 472 | ||
469 | forms.push_back(line); | 473 | if (newgroup) |
474 | { | ||
475 | curgroup = line; | ||
476 | newgroup = false; | ||
477 | } else { | ||
478 | if (line.empty()) | ||
479 | { | ||
480 | newgroup = true; | ||
481 | } else { | ||
482 | groups[curgroup].push_back(line); | ||
483 | } | ||
484 | } | ||
470 | } | 485 | } |
471 | 486 | ||
472 | datafile.close(); | 487 | datafile.close(); |
473 | 488 | ||
474 | verbly::data database {"data.sqlite3"}; | 489 | verbly::data database {"data.sqlite3"}; |
475 | std::string action = forms[rand() % forms.size()]; | 490 | std::string action = "{FORM}"; |
476 | int tknloc; | 491 | int tknloc; |
477 | while ((tknloc = action.find("{")) != std::string::npos) | 492 | while ((tknloc = action.find("{")) != std::string::npos) |
478 | { | 493 | { |
@@ -487,12 +502,15 @@ int main(int argc, char** argv) | |||
487 | if (canontkn == "NOUN") | 502 | if (canontkn == "NOUN") |
488 | { | 503 | { |
489 | result = database.nouns().is_not_proper().random().limit(1).with_complexity(1).run().front().singular_form(); | 504 | result = database.nouns().is_not_proper().random().limit(1).with_complexity(1).run().front().singular_form(); |
490 | } else if (canontkn == "PLURAL_NOUN") | 505 | // } else if (canontkn == "PLURAL_NOUN") |
491 | { | 506 | // { |
492 | result = database.nouns().is_not_proper().requires_plural_form().random().limit(1).with_complexity(1).run().front().plural_form(); | 507 | // result = database.nouns().is_not_proper().requires_plural_form().random().limit(1).with_complexity(1).run().front().plural_form(); |
493 | } else if (canontkn == "ADJECTIVE") | 508 | // } else if (canontkn == "ADJECTIVE") |
509 | // { | ||
510 | // result = database.adjectives().with_complexity(1).random().limit(1).run().front().base_form(); | ||
511 | } else if (canontkn == "SUPERLATIVE") | ||
494 | { | 512 | { |
495 | result = database.adjectives().with_complexity(1).random().limit(1).run().front().base_form(); | 513 | result = database.adjectives().requires_superlative_form().random().limit(1).run().front().superlative_form(); |
496 | } else if (canontkn == "VERB") | 514 | } else if (canontkn == "VERB") |
497 | { | 515 | { |
498 | result = database.verbs().random().limit(1).run().front().infinitive_form(); | 516 | result = database.verbs().random().limit(1).run().front().infinitive_form(); |
@@ -520,7 +538,7 @@ int main(int argc, char** argv) | |||
520 | } else if (canontkn == "ADVERB") | 538 | } else if (canontkn == "ADVERB") |
521 | { | 539 | { |
522 | result = database.adverbs().with_complexity(1).random().limit(1).run().front().base_form(); | 540 | result = database.adverbs().with_complexity(1).random().limit(1).run().front().base_form(); |
523 | } else if (canontkn == "SENTENCE") | 541 | } else if (canontkn == "VERBLY_SENTENCE") |
524 | { | 542 | { |
525 | fill_blanks yeah {database}; | 543 | fill_blanks yeah {database}; |
526 | verbly::token action{ | 544 | verbly::token action{ |
@@ -532,6 +550,10 @@ int main(int argc, char** argv) | |||
532 | yeah.visit(action); | 550 | yeah.visit(action); |
533 | } | 551 | } |
534 | result = action.compile(); | 552 | result = action.compile(); |
553 | } else { | ||
554 | auto group = groups[canontkn]; | ||
555 | result = group[rand() % group.size()]; | ||
556 | std::cout << canontkn << ": " << group.size() << std::endl; | ||
535 | } | 557 | } |
536 | 558 | ||
537 | std::string finalresult; | 559 | std::string finalresult; |
@@ -555,6 +577,8 @@ int main(int argc, char** argv) | |||
555 | 577 | ||
556 | action.replace(tknloc, action.find("}")-tknloc+1, finalresult); | 578 | action.replace(tknloc, action.find("}")-tknloc+1, finalresult); |
557 | } | 579 | } |
580 | |||
581 | std::cout << action << std::endl; | ||
558 | 582 | ||
559 | double zoom = 2.0; | 583 | double zoom = 2.0; |
560 | double target_w = 1280; | 584 | double target_w = 1280; |