summary refs log tree commit diff stats
path: root/generator
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-12-02 18:38:34 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2023-12-02 18:38:34 -0500
commitc9da89242048c2138d0e63188c824196c8ff621e (patch)
tree6d6b73dd34929df242da4339a658f4692920c27c /generator
parent123887d73dbab74f784e6ca41a6b33ce8c5c5e52 (diff)
downloadlingo-randomizer-c9da89242048c2138d0e63188c824196c8ff621e.tar.gz
lingo-randomizer-c9da89242048c2138d0e63188c824196c8ff621e.tar.bz2
lingo-randomizer-c9da89242048c2138d0e63188c824196c8ff621e.zip
Red/blue bottom, purple top
Diffstat (limited to 'generator')
-rw-r--r--generator/generator.cpp135
-rw-r--r--generator/generator.h8
2 files changed, 143 insertions, 0 deletions
diff --git a/generator/generator.cpp b/generator/generator.cpp index 1c3b5c4..aaf546c 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp
@@ -530,6 +530,138 @@ void generator::run() {
530 } 530 }
531 } 531 }
532 532
533 // Red/Blue Bottom
534 std::unordered_map<size_t, std::set<size_t>> meronyms_by_holonym;
535 {
536 std::list<std::string> lines(readFile(wordNetPath_ + "wn_mm.pl"));
537 hatkirby::progress ppgs("Reading member meronymy...", lines.size());
538 for (auto line : lines) {
539 ppgs.update();
540
541 std::regex relation("^mm\\((1\\d{8}),(1\\d{8})\\)\\.");
542 std::smatch relation_data;
543 if (!std::regex_search(line, relation_data, relation)) {
544 continue;
545 }
546
547 int lookup1 = std::stoi(relation_data[1]);
548 int lookup2 = std::stoi(relation_data[2]);
549
550 if (synset_by_wnid_.count(lookup1) && synset_by_wnid_.count(lookup2)) {
551 for (size_t word_id1 : synsets_.at(synset_by_wnid_.at(lookup1))) {
552 for (size_t word_id2 : synsets_.at(synset_by_wnid_.at(lookup2))) {
553 meronyms_by_holonym[word_id1].insert(word_id2);
554 }
555 }
556 }
557 }
558 }
559
560 {
561 std::list<std::string> lines(readFile(wordNetPath_ + "wn_mp.pl"));
562 hatkirby::progress ppgs("Reading part meronymy...", lines.size());
563 for (auto line : lines) {
564 ppgs.update();
565
566 std::regex relation("^mp\\((1\\d{8}),(1\\d{8})\\)\\.");
567 std::smatch relation_data;
568 if (!std::regex_search(line, relation_data, relation)) {
569 continue;
570 }
571
572 int lookup1 = std::stoi(relation_data[1]);
573 int lookup2 = std::stoi(relation_data[2]);
574
575 if (synset_by_wnid_.count(lookup1) && synset_by_wnid_.count(lookup2)) {
576 for (size_t word_id1 : synsets_.at(synset_by_wnid_.at(lookup1))) {
577 for (size_t word_id2 : synsets_.at(synset_by_wnid_.at(lookup2))) {
578 meronyms_by_holonym[word_id1].insert(word_id2);
579 }
580 }
581 }
582 }
583 }
584
585 {
586 std::list<std::string> lines(readFile(wordNetPath_ + "wn_ms.pl"));
587 hatkirby::progress ppgs("Reading substance meronymy...", lines.size());
588 for (auto line : lines) {
589 ppgs.update();
590
591 std::regex relation("^ms\\((1\\d{8}),(1\\d{8})\\)\\.");
592 std::smatch relation_data;
593 if (!std::regex_search(line, relation_data, relation)) {
594 continue;
595 }
596
597 int lookup1 = std::stoi(relation_data[1]);
598 int lookup2 = std::stoi(relation_data[2]);
599
600 if (synset_by_wnid_.count(lookup1) && synset_by_wnid_.count(lookup2)) {
601 for (size_t word_id1 : synsets_.at(synset_by_wnid_.at(lookup1))) {
602 for (size_t word_id2 : synsets_.at(synset_by_wnid_.at(lookup2))) {
603 meronyms_by_holonym[word_id1].insert(word_id2);
604 }
605 }
606 }
607 }
608 }
609
610 {
611 hatkirby::progress ppgs("Generating red/blue bottom puzzles...",
612 meronyms_by_holonym.size());
613
614 for (const auto& [holonym_id, meronym_ids] : meronyms_by_holonym) {
615 ppgs.update();
616
617 for (size_t meronym_id : meronym_ids) {
618 const Word& holonym_word = words_.at(holonym_id);
619 const Word& meronym_word = words_.at(meronym_id);
620
621 Form& holonym_form = forms_.at(holonym_word.base_form_id);
622 Form& meronym_form = forms_.at(meronym_word.base_form_id);
623
624 holonym_form.puzzles[kBlueBottom].insert(meronym_form.id);
625 meronym_form.puzzles[kRedBottom].insert(holonym_form.id);
626 }
627 }
628 }
629
630 // Purple Top
631 {
632 hatkirby::progress ppgs("Generating purple top puzzles...",
633 pronunciations_by_rhyme_.size());
634
635 for (const auto& [rhyme, pronunciation_ids] : pronunciations_by_rhyme_) {
636 ppgs.update();
637
638 for (size_t p_id1 : pronunciation_ids) {
639 const Pronunciation& p1 = pronunciations_.at(p_id1);
640 if (p1.prerhyme.empty()) {
641 continue;
642 }
643
644 for (size_t p_id2 : pronunciation_ids) {
645 const Pronunciation& p2 = pronunciations_.at(p_id2);
646 if (p2.prerhyme.empty()) {
647 continue;
648 }
649
650 if (p1.prerhyme != p2.prerhyme) {
651 for (size_t f_id1 : p1.form_ids) {
652 for (size_t f_id2 : p2.form_ids) {
653 if (f_id1 != f_id2) {
654 Form& form1 = forms_.at(f_id1);
655 form1.puzzles[kPurpleTop].insert(f_id2);
656 }
657 }
658 }
659 }
660 }
661 }
662 }
663 }
664
533 // Count up all of the generated puzzles. 665 // Count up all of the generated puzzles.
534 int total_puzzles = 0; 666 int total_puzzles = 0;
535 int reusable_words = 0; 667 int reusable_words = 0;
@@ -555,6 +687,9 @@ void generator::run() {
555 std::cout << "Black bottoms: " << per_puzzle_type[kBlackBottom] << std::endl; 687 std::cout << "Black bottoms: " << per_puzzle_type[kBlackBottom] << std::endl;
556 std::cout << "Black double bottoms: " << per_puzzle_type[kDoubleBlackBottom] 688 std::cout << "Black double bottoms: " << per_puzzle_type[kDoubleBlackBottom]
557 << std::endl; 689 << std::endl;
690 std::cout << "Red bottoms: " << per_puzzle_type[kRedBottom] << std::endl;
691 std::cout << "Blue bottoms: " << per_puzzle_type[kBlueBottom] << std::endl;
692 std::cout << "Purple tops: " << per_puzzle_type[kPurpleTop] << std::endl;
558} 693}
559 694
560size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { 695size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) {
diff --git a/generator/generator.h b/generator/generator.h index fc66789..f89bab9 100644 --- a/generator/generator.h +++ b/generator/generator.h
@@ -19,6 +19,14 @@ enum PuzzleType {
19 kBlackMiddle = 5, 19 kBlackMiddle = 5,
20 kBlackBottom = 6, 20 kBlackBottom = 6,
21 kDoubleBlackBottom = 7, 21 kDoubleBlackBottom = 7,
22 kRedTop = 8,
23 kRedMiddle = 9,
24 kRedBottom = 10,
25 kBlueTop = 11,
26 kBlueMiddle = 12,
27 kBlueBottom = 13,
28 kPurpleTop = 14,
29 kPurpleMiddle = 15,
22}; 30};
23 31
24class generator { 32class generator {