예제 #1
0
파일: mosesserver.cpp 프로젝트: xfwu/moses
  void
  execute(xmlrpc_c::paramList const& paramList,
          xmlrpc_c::value *   const  retvalP) {
    const params_t params = paramList.getStruct(0);
    breakOutParams(params);
#if PT_UG
    Mmsapt* pdsa = reinterpret_cast<Mmsapt*>(PhraseDictionary::GetColl()[0]);
    pdsa->add(source_,target_,alignment_);
#else
    const PhraseDictionary* pdf = PhraseDictionary::GetColl()[0];
    PhraseDictionaryDynSuffixArray* 
      pdsa = (PhraseDictionaryDynSuffixArray*) pdf;
    cerr << "Inserting into address " << pdsa << endl;
    pdsa->insertSnt(source_, target_, alignment_);
#endif
    if(add2ORLM_) {
      //updateORLM();
    }
    XVERBOSE(1,"Done inserting\n");
    //PhraseDictionary* pdsa = (PhraseDictionary*) pdf->GetDictionary(*dummy);
    map<string, xmlrpc_c::value> retData;
    //*retvalP = xmlrpc_c::value_struct(retData);
#ifndef PT_UG
    pdf = 0;
#endif
    pdsa = 0;
    *retvalP = xmlrpc_c::value_string("Phrase table updated");
  }
예제 #2
0
파일: Log.cpp 프로젝트: ahmidou/aphid
void Log::print(const xmlrpc_c::paramList & params)
{
	for(unsigned i=0; i < params.size(); i++) {
		std::clog<<"param["<<i<<"]\n";
		printValues(params.getStruct(i));
	}
}
예제 #3
0
  void 
  CloseSession::
  execute(xmlrpc_c::paramList const& paramList,
	  xmlrpc_c::value *   const  retvalP)
  {
    typedef std::map<std::string, xmlrpc_c::value> params_t;
    paramList.verifyEnd(1); // ??? UG
    params_t const& params = paramList.getStruct(0);
    params_t::const_iterator si = params.find("session-id");
    if (si != params.end())
      {
	uint64_t session_id = xmlrpc_c::value_int(si->second);
	m_server.delete_session(session_id);
	*retvalP = xmlrpc_c::value_string("Session closed");
      }
  }
예제 #4
0
    void
    execute(xmlrpc_c::paramList const& paramList,
            xmlrpc_c::value *   const  retvalP) {
#ifdef WITH_DLIB
        const params_t params = paramList.getStruct(0);
        params_t::const_iterator si = params.find("model_name");
        if (si == params.end()) {
            throw xmlrpc_c::fault(
                "Missing name of model to be optimized (e.g. PhraseDictionaryMultiModelCounts0)",
                xmlrpc_c::fault::CODE_PARSE);
        }
        const string model_name = xmlrpc_c::value_string(si->second);
        PhraseDictionaryMultiModel* pdmm = (PhraseDictionaryMultiModel*) FindPhraseDictionary(model_name);

        si = params.find("phrase_pairs");
        if (si == params.end()) {
            throw xmlrpc_c::fault(
                "Missing list of phrase pairs",
                xmlrpc_c::fault::CODE_PARSE);
        }

        vector<pair<string, string> > phrase_pairs;

        xmlrpc_c::value_array phrase_pairs_array = xmlrpc_c::value_array(si->second);
        vector<xmlrpc_c::value> phrasePairValueVector(phrase_pairs_array.vectorValueValue());
        for (size_t i=0; i < phrasePairValueVector.size(); i++) {
            xmlrpc_c::value_array phrasePairArray = xmlrpc_c::value_array(phrasePairValueVector[i]);
            vector<xmlrpc_c::value> phrasePair(phrasePairArray.vectorValueValue());
            string L1 = xmlrpc_c::value_string(phrasePair[0]);
            string L2 = xmlrpc_c::value_string(phrasePair[1]);
            phrase_pairs.push_back(make_pair(L1,L2));
        }

        vector<float> weight_vector;
        weight_vector = pdmm->MinimizePerplexity(phrase_pairs);

        vector<xmlrpc_c::value> weight_vector_ret;
        for (size_t i=0; i < weight_vector.size(); i++) {
            weight_vector_ret.push_back(xmlrpc_c::value_double(weight_vector[i]));
        }
        *retvalP = xmlrpc_c::value_array(weight_vector_ret);
#else
        string errmsg = "Error: Perplexity minimization requires dlib (compilation option --with-dlib)";
        cerr << errmsg << endl;
        *retvalP = xmlrpc_c::value_string(errmsg);
#endif
    }
예제 #5
0
 void
 execute(xmlrpc_c::paramList const& paramList,
         xmlrpc_c::value *   const  retvalP) {
     const params_t params = paramList.getStruct(0);
     breakOutParams(params);
     const PhraseDictionary* pdf = StaticData::Instance().GetPhraseDictionaries()[0];
     PhraseDictionaryDynSuffixArray* pdsa = (PhraseDictionaryDynSuffixArray*) pdf;
     cerr << "Inserting into address " << pdsa << endl;
     pdsa->insertSnt(source_, target_, alignment_);
     if(add2ORLM_) {
         //updateORLM();
     }
     cerr << "Done inserting\n";
     //PhraseDictionary* pdsa = (PhraseDictionary*) pdf->GetDictionary(*dummy);
     map<string, xmlrpc_c::value> retData;
     //*retvalP = xmlrpc_c::value_struct(retData);
     pdf = 0;
     pdsa = 0;
     *retvalP = xmlrpc_c::value_string("Phrase table updated");
 }
예제 #6
0
    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);
    }
예제 #7
0
void METHOD_MESSAGE_SEND::execute(xmlrpc_c::paramList const & paramList,
                                  xmlrpc_c::value *   const   retvalPtr)
{
std::string cookie = paramList.getString(0);
std::vector<xmlrpc_c::value> logins(paramList.getArray(1));
std::map<std::string, xmlrpc_c::value> msgInfo(paramList.getStruct(2));
paramList.verifyEnd(3);

ADMIN_INFO adminInfo;

if (config->GetAdminInfo(cookie, &adminInfo))
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }

STG_MSG message;

std::map<std::string, xmlrpc_c::value>::iterator it;

if ((it = msgInfo.find("version")) == msgInfo.end())
    {
    message.header.ver = 1; // Default value
    }
else
    {
    message.header.ver = xmlrpc_c::value_int(it->second);
    }

if ((it = msgInfo.find("type")) == msgInfo.end())
    {
    message.header.type = 1; // default value
    }
else
    {
    message.header.type = xmlrpc_c::value_int(it->second);
    }

if ((it = msgInfo.find("repeat")) == msgInfo.end())
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }
message.header.repeat = xmlrpc_c::value_int(it->second);

if ((it = msgInfo.find("repeat_period")) == msgInfo.end())
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }
message.header.repeatPeriod = xmlrpc_c::value_int(it->second);

if ((it = msgInfo.find("show_time")) == msgInfo.end())
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }
message.header.showTime = xmlrpc_c::value_int(it->second);

if ((it = msgInfo.find("text")) == msgInfo.end())
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }
message.text = IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "CP1251");

message.header.creationTime = static_cast<int>(stgTime);
message.header.lastSendTime = 0;

std::vector<xmlrpc_c::value>::iterator lit;
for (lit = logins.begin(); lit != logins.end(); ++lit)
    {
    USER_PTR ui;
    if (users->FindByName(xmlrpc_c::value_string(*lit), &ui))
        {
        printfd(__FILE__, "METHOD_MESSAGE_SEND::execute(): 'User '%s' not found'\n", std::string(xmlrpc_c::value_string(*lit)).c_str());
        }
    else
        {
        ui->AddMessage(&message);
        }
    }

*retvalPtr = xmlrpc_c::value_boolean(true);
}