/// Create a new *terminal* ItemToken. /// \param label (POS) Label of the new item. /// \param word Actual word of the new item. /// \param location Location of the new item (i.e. the number of terminals thus far). /// Used to construct the width 1 span of the new item. /// \param sentence The sentence in which this item appears. /// \return A pointer to the new ItemToken. /// \todo Assert location value? i.e. Make sure it's immediately /// after the last location, and that this location hasn't already /// been used. const ItemToken* Chart::add(Label label, Word word, unsigned location, const ID<Sentence>& sentence) { assert(!_locked); Debug::log(6) << "Chart::add() received terminal: "; Debug::log(6) << "label = " << label_string(label) << ", word = " << word_string(word) << ", location = " << location << "\n"; item_storage.push_back(ItemToken(label, word, location, sentence)); _terminals.push_back(&item_storage.back()); Debug::log(6) << "...Chart::add() constructed terminal\n"; return &item_storage.back(); }
int main(int argc, char ** argv) { int n, m; std::map<std::string, std::string> dict; scanf("%d %d", &n, &m); char word_a[MAX_WORD_LEN]; char word_b[MAX_WORD_LEN]; for (int i = 0 ; i < m ; ++ i) { scanf("%s %s", word_a, word_b); if (strlen(word_a) <= strlen(word_b)) continue; std::string word_a_string(word_a); std::string word_b_string(word_b); dict[word_a_string] = word_b_string; } for (int i = 0 ; i < n - 1 ; ++ i) { scanf("%s", word_a); std::string word_string(word_a); std::map<std::string, std::string>::iterator it = dict.find(word_string); if (it != dict.end()) printf("%s ", it->second.c_str()); else printf("%s ", word_a); } scanf("%s", word_a); std::string word_string(word_a); std::map<std::string, std::string>::iterator it = dict.find(word_string); if (it != dict.end()) printf("%s\n", it->second.c_str()); else printf("%s\n", word_a); }