From c9da89242048c2138d0e63188c824196c8ff621e Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 2 Dec 2023 18:38:34 -0500 Subject: Red/blue bottom, purple top --- generator/generator.cpp | 135 ++++++++++++++++++++++++++++++++++++++++++++++++ generator/generator.h | 8 +++ 2 files changed, 143 insertions(+) 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() { } } + // Red/Blue Bottom + std::unordered_map> meronyms_by_holonym; + { + std::list lines(readFile(wordNetPath_ + "wn_mm.pl")); + hatkirby::progress ppgs("Reading member meronymy...", lines.size()); + for (auto line : lines) { + ppgs.update(); + + std::regex relation("^mm\\((1\\d{8}),(1\\d{8})\\)\\."); + std::smatch relation_data; + if (!std::regex_search(line, relation_data, relation)) { + continue; + } + + int lookup1 = std::stoi(relation_data[1]); + int lookup2 = std::stoi(relation_data[2]); + + if (synset_by_wnid_.count(lookup1) && synset_by_wnid_.count(lookup2)) { + for (size_t word_id1 : synsets_.at(synset_by_wnid_.at(lookup1))) { + for (size_t word_id2 : synsets_.at(synset_by_wnid_.at(lookup2))) { + meronyms_by_holonym[word_id1].insert(word_id2); + } + } + } + } + } + + { + std::list lines(readFile(wordNetPath_ + "wn_mp.pl")); + hatkirby::progress ppgs("Reading part meronymy...", lines.size()); + for (auto line : lines) { + ppgs.update(); + + std::regex relation("^mp\\((1\\d{8}),(1\\d{8})\\)\\."); + std::smatch relation_data; + if (!std::regex_search(line, relation_data, relation)) { + continue; + } + + int lookup1 = std::stoi(relation_data[1]); + int lookup2 = std::stoi(relation_data[2]); + + if (synset_by_wnid_.count(lookup1) && synset_by_wnid_.count(lookup2)) { + for (size_t word_id1 : synsets_.at(synset_by_wnid_.at(lookup1))) { + for (size_t word_id2 : synsets_.at(synset_by_wnid_.at(lookup2))) { + meronyms_by_holonym[word_id1].insert(word_id2); + } + } + } + } + } + + { + std::list lines(readFile(wordNetPath_ + "wn_ms.pl")); + hatkirby::progress ppgs("Reading substance meronymy...", lines.size()); + for (auto line : lines) { + ppgs.update(); + + std::regex relation("^ms\\((1\\d{8}),(1\\d{8})\\)\\."); + std::smatch relation_data; + if (!std::regex_search(line, relation_data, relation)) { + continue; + } + + int lookup1 = std::stoi(relation_data[1]); + int lookup2 = std::stoi(relation_data[2]); + + if (synset_by_wnid_.count(lookup1) && synset_by_wnid_.count(lookup2)) { + for (size_t word_id1 : synsets_.at(synset_by_wnid_.at(lookup1))) { + for (size_t word_id2 : synsets_.at(synset_by_wnid_.at(lookup2))) { + meronyms_by_holonym[word_id1].insert(word_id2); + } + } + } + } + } + + { + hatkirby::progress ppgs("Generating red/blue bottom puzzles...", + meronyms_by_holonym.size()); + + for (const auto& [holonym_id, meronym_ids] : meronyms_by_holonym) { + ppgs.update(); + + for (size_t meronym_id : meronym_ids) { + const Word& holonym_word = words_.at(holonym_id); + const Word& meronym_word = words_.at(meronym_id); + + Form& holonym_form = forms_.at(holonym_word.base_form_id); + Form& meronym_form = forms_.at(meronym_word.base_form_id); + + holonym_form.puzzles[kBlueBottom].insert(meronym_form.id); + meronym_form.puzzles[kRedBottom].insert(holonym_form.id); + } + } + } + + // Purple Top + { + hatkirby::progress ppgs("Generating purple top puzzles...", + pronunciations_by_rhyme_.size()); + + for (const auto& [rhyme, pronunciation_ids] : pronunciations_by_rhyme_) { + ppgs.update(); + + for (size_t p_id1 : pronunciation_ids) { + const Pronunciation& p1 = pronunciations_.at(p_id1); + if (p1.prerhyme.empty()) { + continue; + } + + for (size_t p_id2 : pronunciation_ids) { + const Pronunciation& p2 = pronunciations_.at(p_id2); + if (p2.prerhyme.empty()) { + continue; + } + + if (p1.prerhyme != p2.prerhyme) { + for (size_t f_id1 : p1.form_ids) { + for (size_t f_id2 : p2.form_ids) { + if (f_id1 != f_id2) { + Form& form1 = forms_.at(f_id1); + form1.puzzles[kPurpleTop].insert(f_id2); + } + } + } + } + } + } + } + } + // Count up all of the generated puzzles. int total_puzzles = 0; int reusable_words = 0; @@ -555,6 +687,9 @@ void generator::run() { std::cout << "Black bottoms: " << per_puzzle_type[kBlackBottom] << std::endl; std::cout << "Black double bottoms: " << per_puzzle_type[kDoubleBlackBottom] << std::endl; + std::cout << "Red bottoms: " << per_puzzle_type[kRedBottom] << std::endl; + std::cout << "Blue bottoms: " << per_puzzle_type[kBlueBottom] << std::endl; + std::cout << "Purple tops: " << per_puzzle_type[kPurpleTop] << std::endl; } size_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 { kBlackMiddle = 5, kBlackBottom = 6, kDoubleBlackBottom = 7, + kRedTop = 8, + kRedMiddle = 9, + kRedBottom = 10, + kBlueTop = 11, + kBlueMiddle = 12, + kBlueBottom = 13, + kPurpleTop = 14, + kPurpleMiddle = 15, }; class generator { -- cgit 1.4.1