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


C++ Sentence::Read方法代码示例

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


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

示例1: fault

    void
    execute(xmlrpc_c::paramList const& paramList,
            xmlrpc_c::value *   const  retvalP) {

        const params_t params = paramList.getStruct(0);
        paramList.verifyEnd(1);
        params_t::const_iterator si = params.find("text");
        if (si == params.end()) {
            throw xmlrpc_c::fault(
                "Missing source text",
                xmlrpc_c::fault::CODE_PARSE);
        }
        const string source(
            (xmlrpc_c::value_string(si->second)));

        cerr << "Input: " << source << endl;
        si = params.find("align");
        bool addAlignInfo = (si != params.end());
        si = params.find("sg");
        bool addGraphInfo = (si != params.end());
        si = params.find("topt");
        bool addTopts = (si != params.end());
        si = params.find("report-all-factors");
        bool reportAllFactors = (si != params.end());
        si = params.find("nbest");
        int nbest_size = (si == params.end()) ? 0 : int(xmlrpc_c::value_int(si->second));
        si = params.find("nbest-distinct");
        bool nbest_distinct = (si != params.end());

        vector<float> multiModelWeights;
        si = params.find("lambda");
        if (si != params.end()) {
            xmlrpc_c::value_array multiModelArray = xmlrpc_c::value_array(si->second);
            vector<xmlrpc_c::value> multiModelValueVector(multiModelArray.vectorValueValue());
            for (size_t i=0; i < multiModelValueVector.size(); i++) {
                multiModelWeights.push_back(xmlrpc_c::value_double(multiModelValueVector[i]));
            }
        }

        const StaticData &staticData = StaticData::Instance();

        if (addGraphInfo) {
            (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(true);
        }

        if (multiModelWeights.size() > 0) {
            PhraseDictionaryMultiModel* pdmm = (PhraseDictionaryMultiModel*) staticData.GetPhraseDictionaries()[0]; //TODO: only works if multimodel is first phrase table
            pdmm->SetTemporaryMultiModelWeightsVector(multiModelWeights);
        }

        stringstream out, graphInfo, transCollOpts;
        map<string, xmlrpc_c::value> retData;

        if (staticData.IsChart()) {
            TreeInput tinput;
            const vector<FactorType> &inputFactorOrder =
                staticData.GetInputFactorOrder();
            stringstream in(source + "\n");
            tinput.Read(in,inputFactorOrder);
            ChartManager manager(tinput);
            manager.ProcessSentence();
            const ChartHypothesis *hypo = manager.GetBestHypothesis();
            outputChartHypo(out,hypo);
        } else {
            Sentence sentence;
            const vector<FactorType> &inputFactorOrder =
                staticData.GetInputFactorOrder();
            stringstream in(source + "\n");
            sentence.Read(in,inputFactorOrder);
            size_t lineNumber = 0; // TODO: Include sentence request number here?
            Manager manager(lineNumber, sentence, staticData.GetSearchAlgorithm());
            manager.ProcessSentence();
            const Hypothesis* hypo = manager.GetBestHypothesis();

            vector<xmlrpc_c::value> alignInfo;
            outputHypo(out,hypo,addAlignInfo,alignInfo,reportAllFactors);
            if (addAlignInfo) {
                retData.insert(pair<string, xmlrpc_c::value>("align", xmlrpc_c::value_array(alignInfo)));
            }

            if(addGraphInfo) {
                insertGraphInfo(manager,retData);
                (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(false);
            }
            if (addTopts) {
                insertTranslationOptions(manager,retData);
            }
            if (nbest_size>0) {
                outputNBest(manager, retData, nbest_size, nbest_distinct, reportAllFactors);
            }
        }
        pair<string, xmlrpc_c::value>
        text("text", xmlrpc_c::value_string(out.str()));
        retData.insert(text);
        cerr << "Output: " << out.str() << endl;
        *retvalP = xmlrpc_c::value_struct(retData);
    }
开发者ID:junfeiguo,项目名称:mosesdecoder,代码行数:97,代码来源:mosesserver.cpp


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