diff --git a/moses/LM/Reloading.h b/moses/LM/Reloading.h index 7075cb429..88f8e8869 100644 --- a/moses/LM/Reloading.h +++ b/moses/LM/Reloading.h @@ -48,6 +48,32 @@ public: virtual void InitializeForInput(ttasksptr const& ttask) { VERBOSE(1, "ReloadingLM InitializeForInput" << std::endl); + // The context scope object for this translation task + // contains a map of translation task-specific data + boost::shared_ptr contextScope = ttask->GetScope(); + + // The key to the map is this object + void const* key = static_cast(this); + + // The value stored in the map is a string representing a phrase table + boost::shared_ptr value = contextScope->get(key); + + // Create a stream to read the phrase table data + stringstream strme(*(value.get())); + + ofstream tmp; + tmp.open(m_file.c_str()); + + // Read the phrase table data, one line at a time + string line; + while (getline(strme, line)) { + + tmp << line << "\n"; + + } + + tmp.close(); + LanguageModelKen::LoadModel(m_file, m_lazy ? util::LAZY : util::POPULATE_OR_READ); }; diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index 4e97cff6a..e1821a265 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -26,6 +26,7 @@ using Moses::FindPhraseDictionary; using Moses::Sentence; using Moses::TokenizeMultiCharSeparator; using Moses::FeatureFunction; +using Moses::Scan; boost::shared_ptr TranslationRequest:: @@ -352,6 +353,62 @@ parse_request(std::map const& params) } } + si = params.find("weights"); + if (si != params.end()) + { + + boost::unordered_map map; + { + const vector &ffs = FeatureFunction::GetFeatureFunctions(); + BOOST_FOREACH(FeatureFunction* const& ff, ffs) { + map[ff->GetScoreProducerDescription()] = ff; + } + } + + string allValues = xmlrpc_c::value_string(si->second); + + BOOST_FOREACH(string values, TokenizeMultiCharSeparator(allValues, "\t")) { + + vector record = TokenizeMultiCharSeparator(values, "="); + + if (record.size() == 2) { + string featureName = record[0]; + string featureWeights = record[1]; + + boost::unordered_map::iterator ffi = map.find(featureName); + + if (ffi != map.end()) { + FeatureFunction* ff = ffi->second; + + size_t prevNumWeights = ff->GetNumScoreComponents(); + + vector ffWeights; + BOOST_FOREACH(string weight, TokenizeMultiCharSeparator(featureWeights, " ")) { + ffWeights.push_back(Scan(weight)); + } + + if (ffWeights.size() == ff->GetNumScoreComponents()) { + + // XXX: This is NOT thread-safe + Moses::StaticData::InstanceNonConst().SetWeights(ff, ffWeights); + VERBOSE(1, "WARNING: THIS IS NOT THREAD-SAFE!\tUpdating weights for " << featureName << " to " << featureWeights << "\n"); + + } else { + TRACE_ERR("ERROR: Unable to update weights for " << featureName << " because " << ff->GetNumScoreComponents() << " weights are required but only " << ffWeights.size() << " were provided\n"); + } + + } else { + TRACE_ERR("ERROR: No FeatureFunction with name " << featureName << ", no weight update\n"); + } + + } else { + TRACE_ERR("WARNING: XML-RPC weights update was improperly formatted:\t" << values << "\n"); + } + + } + + } + // // biased sampling for suffix-array-based sampling phrase table? // if ((si = params.find("bias")) != params.end())