当前位置: 首页>>代码示例>>C++>>正文


C++ Translator::addEntry方法代码示例

本文整理汇总了C++中Translator::addEntry方法的典型用法代码示例。如果您正苦于以下问题:C++ Translator::addEntry方法的具体用法?C++ Translator::addEntry怎么用?C++ Translator::addEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Translator的用法示例。


在下文中一共展示了Translator::addEntry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: intersection

Translator Translator::intersection(const Translator &first, const Translator &second){

    multimap <string, string> fst_dict = first.dictionary, snd_dict = second.dictionary;
    multimap <string, string>::iterator fst_it = fst_dict.begin(),
        fst_end = fst_dict.end(), snd_it, snd_curr_key, snd_end = snd_dict.end(),
        fst_stop, snd_stop;
    pair <multimap <string, string>::iterator, multimap<string, string>::iterator> key_range;
    string origin, mid;

    set <string> curr_translations;
    Word curr_entry;

    Translator intersection;

    while(fst_it != fst_end){

        origin = fst_it->first;

        snd_curr_key = snd_dict.find(origin);
        fst_stop = fst_dict.upper_bound(origin);

        if(snd_curr_key != snd_end){  // the key is on the second translator too

            curr_translations.clear();  // empty the translations for this key

            snd_stop = snd_dict.upper_bound(origin);

            for(; fst_it != fst_stop; ++fst_it){  // iterate over the A->B translations

                for(snd_it = snd_curr_key; snd_it != snd_stop; ++snd_it){  // iterate over the C->B

                    if(fst_it->second == snd_it->second){  // translations match

                        curr_translations.insert(fst_it->second);

                    }

                }

            }

            if(not curr_translations.empty()){

                curr_entry = Word(origin, curr_translations);

                intersection.addEntry(curr_entry);

            }

        }

        fst_it = fst_stop;
        
    }

    return intersection;

}
开发者ID:cronos2,项目名称:Translator,代码行数:58,代码来源:Translator.cpp

示例2: compose

Translator Translator::compose(const Translator &first, const Translator &second){

    multimap <string, string> fst_dict = first.dictionary, snd_dict = second.dictionary;
    multimap <string, string>::iterator fst_it = fst_dict.begin(),
        fst_end = fst_dict.end(), snd_it, stop;
    pair <multimap <string, string>::iterator, multimap<string, string>::iterator> key_range;
    string origin, mid;

    set <string> curr_translations;
    Word curr_entry;

    Translator composition;

    while(fst_it != fst_end){

        origin = fst_it->first;
        stop = fst_dict.upper_bound(origin);
        curr_translations.clear();  // empty the translations for this key

        for(; fst_it != stop; ++fst_it){

            mid = fst_it->second;

            key_range = snd_dict.equal_range(mid);

            for(snd_it = key_range.first; snd_it != key_range.second; ++snd_it){

                curr_translations.insert(snd_it->second);

            }

        }

        curr_entry = Word(origin, curr_translations);
        composition.addEntry(curr_entry);

    }

    return composition;

}
开发者ID:cronos2,项目名称:Translator,代码行数:41,代码来源:Translator.cpp


注:本文中的Translator::addEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。