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


C++ PhraseTable::translateSentence方法代码示例

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


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

示例1: main

int main(int argc, char **argv) {
    Lexicon* src_lex = new Lexicon();
    Lexicon* dst_lex = new Lexicon();
    Lexicon* unt_lex = new Lexicon();

    int prune = 30;
    // n beste Übersetzungen
    int n = 10;
    // Parameter überprüfen


    string help = string("usage: ") + string(argv[0]) + string(" [-n 10] [-p 30] <config> <table.gz> <text>");
    if(argc < 4 || argc % 2 == 1) {
        cerr << help << endl;
        return 1;
    }
    for(int i = 1; i < argc; i++) {
        if(!string(argv[i]).compare("-n") && argc >= 6) {
            i++;
            n = atoi(argv[i]);
        } else {
            if(!string(argv[i]).compare("-p") && argc >= 6) {
                i++;
                prune = atoi(argv[i]);
            }
        }
    }

    if(n <= 0) {
        cerr << help << endl;
        return 1;
    }


    char *cnf_name = argv[argc-3];
    char *tbl_name = argv[argc-2];
    char *txt_name = argv[argc-1];

    if(getenv("LOG_D")) {
        cerr << "[main] Opening files ..." << endl;
    }

    // Dateien öffnen:
    ifstream f_cnf(cnf_name);
    if(!f_cnf.good()) {
        cerr << "ERROR: opening file '" << tbl_name << "' failed!" << endl << help << endl;
        return 1;
    }
    igzstream f_tbl(tbl_name);
    if(!f_tbl.good()) {
        cerr << "ERROR: opening file '" << tbl_name << "' failed!" << endl << help << endl;
        return 1;
    }
    ifstream f_txt(txt_name);
    if(!f_txt.good()) {
        cerr << "ERROR: opening file '" << txt_name << "' failed!" << endl << help << endl;
        return 1;
    }

    Config *cnf = new Config(&f_cnf);
    if(getenv("LOG_D")) {
        cerr << "[main] Generating PhraseTable ..." << endl;
    }
    PhraseTable* phraseTable = new PhraseTable(&f_tbl, src_lex, dst_lex, unt_lex, prune);
    string f_line;
    unt_lex->add("[wordKNOTfound]");
    unt_lex->add("[wordnotfound]");
    // für jeden Satz

    Astar *algo;
    while(getline(f_txt, f_line)){
        istringstream f_iss(f_line); // wir lesen ein
        vector<int> sentence;
        string currWord;
        while(f_iss >> currWord) {
            // einlesen
            int id = src_lex->get_id(currWord);
            if(id == -1){
                id = - (unt_lex->add(currWord));
            }
            sentence.push_back(id);
        }

        if(getenv("LOG_D")) {
            cerr << "[main] Translating sentence \"" << src_lex->sent2string(sentence) << "\" ..." << endl;
        }

        HypothesisNode *currTrans = phraseTable->translateSentence(sentence, cnf->lambda);
        Sentence trans;
        algo = new Astar(currTrans, prune);
        double transCost;
        Scores score;
        for(int i = 0; i < n && algo->getnext(trans, transCost, score); i++) {
            cout << dst_lex->sent2string(trans,unt_lex) << endl;
        }
        delete algo;
        algo = 0;
    }

    delete cnf;
//.........这里部分代码省略.........
开发者ID:CBiX,项目名称:fuckfrench,代码行数:101,代码来源:a4_decode_normal.cpp


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