Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/moses
diff options
context:
space:
mode:
authorMosesAdmin <moses-support-owner@mit.edu>2017-07-22 02:01:14 +0300
committerMosesAdmin <moses-support-owner@mit.edu>2017-07-22 02:01:14 +0300
commitb16e6a5219a206e11e8b5c05f4b7500a3729d9d3 (patch)
tree21f01349f38d239f900871924316940048f6aee4 /moses
parent6505d11cc651d30a821e1901e9c85e721c2489bd (diff)
daily automatic beautifier
Diffstat (limited to 'moses')
-rw-r--r--moses/TranslationModel/PhraseDictionaryCache.cpp157
-rw-r--r--moses/TranslationModel/PhraseDictionaryCache.h6
-rw-r--r--moses/TranslationModel/PhraseDictionaryDynamicCacheBased.cpp91
3 files changed, 129 insertions, 125 deletions
diff --git a/moses/TranslationModel/PhraseDictionaryCache.cpp b/moses/TranslationModel/PhraseDictionaryCache.cpp
index 604a42ee4..fd7979965 100644
--- a/moses/TranslationModel/PhraseDictionaryCache.cpp
+++ b/moses/TranslationModel/PhraseDictionaryCache.cpp
@@ -70,16 +70,17 @@ void PhraseDictionaryCache::SetParameter(const std::string& key, const std::stri
if (key == "cache-name") {
m_name = Scan<std::string>(value);
} else if (key == "input-factor") {
- m_inputFactorsVec = Tokenize<FactorType>(value,",");
+ m_inputFactorsVec = Tokenize<FactorType>(value,",");
} else if (key == "output-factor") {
- m_outputFactorsVec = Tokenize<FactorType>(value,",");
+ m_outputFactorsVec = Tokenize<FactorType>(value,",");
} else {
PhraseDictionary::SetParameter(key, value);
}
}
-void PhraseDictionaryCache::CleanUpAfterSentenceProcessing(const InputType& source) {
- Clear(source.GetTranslationId());
+void PhraseDictionaryCache::CleanUpAfterSentenceProcessing(const InputType& source)
+{
+ Clear(source.GetTranslationId());
}
void PhraseDictionaryCache::InitializeForInput(ttasksptr const& ttask)
@@ -87,21 +88,21 @@ void PhraseDictionaryCache::InitializeForInput(ttasksptr const& ttask)
#ifdef WITH_THREADS
boost::unique_lock<boost::shared_mutex> lock(m_cacheLock);
#endif
- long tID = ttask->GetSource()->GetTranslationId();
- TargetPhraseCollection::shared_ptr tpc;
- if (m_cacheTM.find(tID) == m_cacheTM.end()) return;
- for(cacheMap::const_iterator it=m_cacheTM.at(tID).begin(); it != m_cacheTM.at(tID).end(); it++) {
- tpc.reset(new TargetPhraseCollection(*(it->second).first));
- std::vector<const TargetPhrase*>::const_iterator it2 = tpc->begin();
-
- while (it2 != tpc->end()) {
- ((TargetPhrase*) *it2)->EvaluateInIsolation(it->first, GetFeaturesToApply());
- it2++;
- }
- }
- if (tpc) {
- tpc->NthElement(m_tableLimit); // sort the phrases for the decoder
- }
+ long tID = ttask->GetSource()->GetTranslationId();
+ TargetPhraseCollection::shared_ptr tpc;
+ if (m_cacheTM.find(tID) == m_cacheTM.end()) return;
+ for(cacheMap::const_iterator it=m_cacheTM.at(tID).begin(); it != m_cacheTM.at(tID).end(); it++) {
+ tpc.reset(new TargetPhraseCollection(*(it->second).first));
+ std::vector<const TargetPhrase*>::const_iterator it2 = tpc->begin();
+
+ while (it2 != tpc->end()) {
+ ((TargetPhrase*) *it2)->EvaluateInIsolation(it->first, GetFeaturesToApply());
+ it2++;
+ }
+ }
+ if (tpc) {
+ tpc->NthElement(m_tableLimit); // sort the phrases for the decoder
+ }
}
void PhraseDictionaryCache::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const
@@ -109,19 +110,19 @@ void PhraseDictionaryCache::GetTargetPhraseCollectionBatch(const InputPathList &
#ifdef WITH_THREADS
boost::shared_lock<boost::shared_mutex> read_lock(m_cacheLock);
#endif
- InputPathList::const_iterator iter;
- for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) {
- InputPath &inputPath = **iter;
- long tID = inputPath.ttask->GetSource()->GetTranslationId();
- if (m_cacheTM.find(tID) == m_cacheTM.end()) continue;
- const Phrase &source = inputPath.GetPhrase();
- TargetPhraseCollection::shared_ptr tpc;
- for(cacheMap::const_iterator it=m_cacheTM.at(tID).begin(); it != m_cacheTM.at(tID).end(); it++) {
- if (source.Compare(it->first)!=0) continue;
- tpc.reset(new TargetPhraseCollection(*(it->second).first));
- inputPath.SetTargetPhrases(*this, tpc, NULL);
- }
- }
+ InputPathList::const_iterator iter;
+ for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) {
+ InputPath &inputPath = **iter;
+ long tID = inputPath.ttask->GetSource()->GetTranslationId();
+ if (m_cacheTM.find(tID) == m_cacheTM.end()) continue;
+ const Phrase &source = inputPath.GetPhrase();
+ TargetPhraseCollection::shared_ptr tpc;
+ for(cacheMap::const_iterator it=m_cacheTM.at(tID).begin(); it != m_cacheTM.at(tID).end(); it++) {
+ if (source.Compare(it->first)!=0) continue;
+ tpc.reset(new TargetPhraseCollection(*(it->second).first));
+ inputPath.SetTargetPhrases(*this, tpc, NULL);
+ }
+ }
}
TargetPhraseCollection::shared_ptr PhraseDictionaryCache::GetTargetPhraseCollection(const Phrase &source, long tID) const
@@ -195,7 +196,7 @@ void PhraseDictionaryCache::Update(long tID, std::vector<std::string> entries)
VERBOSE(3,"pp[2]:|" << pp[2] << "|" << std::endl);
VERBOSE(3,"pp[3]:|" << pp[3] << "|" << std::endl);
Update(tID,pp[0], pp[1], pp[2], pp[3]);
- } else if (pp.size() > 2){
+ } else if (pp.size() > 2) {
VERBOSE(3,"pp[2]:|" << pp[2] << "|" << std::endl);
Update(tID,pp[0], pp[1], pp[2]);
} else {
@@ -204,15 +205,16 @@ void PhraseDictionaryCache::Update(long tID, std::vector<std::string> entries)
}
}
-Scores PhraseDictionaryCache::Conv2VecFloats(std::string& s){
- std::vector<float> n;
- if (s.empty())
- return n;
- std::istringstream iss(s);
- std::copy(std::istream_iterator<float>(iss),
- std::istream_iterator<float>(),
- std::back_inserter(n));
- return n;
+Scores PhraseDictionaryCache::Conv2VecFloats(std::string& s)
+{
+ std::vector<float> n;
+ if (s.empty())
+ return n;
+ std::istringstream iss(s);
+ std::copy(std::istream_iterator<float>(iss),
+ std::istream_iterator<float>(),
+ std::back_inserter(n));
+ return n;
}
void PhraseDictionaryCache::Update(long tID, std::string sourcePhraseString, std::string targetPhraseString, std::string scoreString, std::string waString)
@@ -277,12 +279,12 @@ void PhraseDictionaryCache::Update(long tID, Phrase sp, TargetPhrase tp, Scores
VERBOSE(3,"tp:|" << tp << "| NOT FOUND" << std::endl);
std::auto_ptr<TargetPhrase> targetPhrase(new TargetPhrase(tp));
Scores scoreVec;
- for (unsigned int i=0; i<scores.size(); i++){
- scoreVec.push_back(scores[i]);
+ for (unsigned int i=0; i<scores.size(); i++) {
+ scoreVec.push_back(scores[i]);
}
- if(scoreVec.size() != m_numScoreComponents){
- VERBOSE(1, "Scores does not match number of score components for phrase : "<< sp.ToString() <<" ||| " << tp.ToString() <<endl);
- VERBOSE(1, "I am ignoring this..." <<endl);
+ if(scoreVec.size() != m_numScoreComponents) {
+ VERBOSE(1, "Scores does not match number of score components for phrase : "<< sp.ToString() <<" ||| " << tp.ToString() <<endl);
+ VERBOSE(1, "I am ignoring this..." <<endl);
// std::cin.ignore();
}
targetPhrase->GetScoreBreakdown().Assign(this, scoreVec);
@@ -295,16 +297,16 @@ void PhraseDictionaryCache::Update(long tID, Phrase sp, TargetPhrase tp, Scores
m_entries++;
VERBOSE(3,"sp:|" << sp << "tp:|" << tp << "| INSERTED" << std::endl);
} else {
- Scores scoreVec;
- for (unsigned int i=0; i<scores.size(); i++){
- scoreVec.push_back(scores[i]);
- }
- if(scoreVec.size() != m_numScoreComponents){
- VERBOSE(1, "Scores does not match number of score components for phrase : "<< sp.ToString() <<" ||| " << tp.ToString() <<endl);
- VERBOSE(1, "I am ignoring this..." <<endl);
+ Scores scoreVec;
+ for (unsigned int i=0; i<scores.size(); i++) {
+ scoreVec.push_back(scores[i]);
+ }
+ if(scoreVec.size() != m_numScoreComponents) {
+ VERBOSE(1, "Scores does not match number of score components for phrase : "<< sp.ToString() <<" ||| " << tp.ToString() <<endl);
+ VERBOSE(1, "I am ignoring this..." <<endl);
// std::cin.ignore();
- }
- tp_ptr->GetScoreBreakdown().Assign(this, scoreVec);
+ }
+ tp_ptr->GetScoreBreakdown().Assign(this, scoreVec);
if (!waString.empty()) tp_ptr->SetAlignmentInfo(waString);
VERBOSE(3,"sp:|" << sp << "tp:|" << tp << "| UPDATED" << std::endl);
}
@@ -321,12 +323,12 @@ void PhraseDictionaryCache::Update(long tID, Phrase sp, TargetPhrase tp, Scores
std::auto_ptr<TargetPhrase> targetPhrase(new TargetPhrase(tp));
// scoreVec is a composition of decay_score and the feature scores
Scores scoreVec;
- for (unsigned int i=0; i<scores.size(); i++){
- scoreVec.push_back(scores[i]);
+ for (unsigned int i=0; i<scores.size(); i++) {
+ scoreVec.push_back(scores[i]);
}
- if(scoreVec.size() != m_numScoreComponents){
- VERBOSE(1, "Scores do not match number of score components for phrase : "<< sp <<" ||| " << tp <<endl);
- VERBOSE(1, "I am ignoring this..." <<endl);
+ if(scoreVec.size() != m_numScoreComponents) {
+ VERBOSE(1, "Scores do not match number of score components for phrase : "<< sp <<" ||| " << tp <<endl);
+ VERBOSE(1, "I am ignoring this..." <<endl);
// std::cin.ignore();
}
targetPhrase->GetScoreBreakdown().Assign(this, scoreVec);
@@ -364,8 +366,9 @@ void PhraseDictionaryCache::Execute_Single_Command(std::string command)
}
}
-void PhraseDictionaryCache::Clear(){
- for(sentCacheMap::iterator it=m_cacheTM.begin(); it!=m_cacheTM.end(); it++){
+void PhraseDictionaryCache::Clear()
+{
+ for(sentCacheMap::iterator it=m_cacheTM.begin(); it!=m_cacheTM.end(); it++) {
Clear(it->first);
}
}
@@ -378,9 +381,9 @@ void PhraseDictionaryCache::Clear(long tID)
if (m_cacheTM.find(tID) == m_cacheTM.end()) return;
cacheMap::iterator it;
for(it = m_cacheTM.at(tID).begin(); it!=m_cacheTM.at(tID).end(); it++) {
- (((*it).second).second)->clear();
- delete ((*it).second).second;
- ((*it).second).first.reset();
+ (((*it).second).second)->clear();
+ delete ((*it).second).second;
+ ((*it).second).first.reset();
}
m_cacheTM.at(tID).clear();
m_entries = 0;
@@ -407,17 +410,17 @@ void PhraseDictionaryCache::Print() const
boost::shared_lock<boost::shared_mutex> read_lock(m_cacheLock);
#endif
for(sentCacheMap::const_iterator itr = m_cacheTM.begin(); itr!=m_cacheTM.end(); itr++) {
- cacheMap::const_iterator it;
- for(it = (itr->second).begin(); it!=(itr->second).end(); it++) {
- std::string source = (it->first).ToString();
- TargetPhraseCollection::shared_ptr tpc = (it->second).first;
- TargetPhraseCollection::iterator itr;
- for(itr = tpc->begin(); itr != tpc->end(); itr++) {
- std::string target = (*itr)->ToString();
- std::cout << source << " ||| " << target << std::endl;
- }
- source.clear();
- }
+ cacheMap::const_iterator it;
+ for(it = (itr->second).begin(); it!=(itr->second).end(); it++) {
+ std::string source = (it->first).ToString();
+ TargetPhraseCollection::shared_ptr tpc = (it->second).first;
+ TargetPhraseCollection::iterator itr;
+ for(itr = tpc->begin(); itr != tpc->end(); itr++) {
+ std::string target = (*itr)->ToString();
+ std::cout << source << " ||| " << target << std::endl;
+ }
+ source.clear();
+ }
}
}
diff --git a/moses/TranslationModel/PhraseDictionaryCache.h b/moses/TranslationModel/PhraseDictionaryCache.h
index b6e54b8fa..6220badc6 100644
--- a/moses/TranslationModel/PhraseDictionaryCache.h
+++ b/moses/TranslationModel/PhraseDictionaryCache.h
@@ -118,9 +118,9 @@ public:
}
TargetPhraseCollection::shared_ptr
- GetTargetPhraseCollectionLEGACY(ttasksptr const& ttask,
- Phrase const& src) const{
- GetTargetPhraseCollection(src, ttask->GetSource()->GetTranslationId());
+ GetTargetPhraseCollectionLEGACY(ttasksptr const& ttask,
+ Phrase const& src) const {
+ GetTargetPhraseCollection(src, ttask->GetSource()->GetTranslationId());
}
diff --git a/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.cpp b/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.cpp
index e1f29b356..76b0202f3 100644
--- a/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.cpp
+++ b/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.cpp
@@ -147,9 +147,9 @@ void PhraseDictionaryDynamicCacheBased::SetParameter(const std::string& key, con
} else if (key == "cbtm-constant") {
m_constant = Scan<bool>(value);
} else if (key == "input-factor") {
- m_inputFactorsVec = Tokenize<FactorType>(value,",");
+ m_inputFactorsVec = Tokenize<FactorType>(value,",");
} else if (key == "output-factor") {
- m_outputFactorsVec = Tokenize<FactorType>(value,",");
+ m_outputFactorsVec = Tokenize<FactorType>(value,",");
} else {
PhraseDictionary::SetParameter(key, value);
}
@@ -523,7 +523,7 @@ void PhraseDictionaryDynamicCacheBased::Update(std::vector<std::string> entries,
VERBOSE(3,"pp[2]:|" << pp[2] << "|" << std::endl);
VERBOSE(3,"pp[3]:|" << pp[3] << "|" << std::endl);
Update(pp[0], pp[1], ageString, pp[2], pp[3]);
- } else if (pp.size() > 2){
+ } else if (pp.size() > 2) {
VERBOSE(3,"pp[2]:|" << pp[2] << "|" << std::endl);
Update(pp[0], pp[1], ageString, pp[2]);
} else {
@@ -532,15 +532,16 @@ void PhraseDictionaryDynamicCacheBased::Update(std::vector<std::string> entries,
}
}
-Scores PhraseDictionaryDynamicCacheBased::Conv2VecFloats(std::string& s){
- std::vector<float> n;
- if (s.empty())
- return n;
- std::istringstream iss(s);
- std::copy(std::istream_iterator<float>(iss),
- std::istream_iterator<float>(),
- std::back_inserter(n));
- return n;
+Scores PhraseDictionaryDynamicCacheBased::Conv2VecFloats(std::string& s)
+{
+ std::vector<float> n;
+ if (s.empty())
+ return n;
+ std::istringstream iss(s);
+ std::copy(std::istream_iterator<float>(iss),
+ std::istream_iterator<float>(),
+ std::back_inserter(n));
+ return n;
}
void PhraseDictionaryDynamicCacheBased::Update(std::string sourcePhraseString, std::string targetPhraseString, std::string ageString, std::string scoreString, std::string waString)
@@ -615,13 +616,13 @@ void PhraseDictionaryDynamicCacheBased::Update(Phrase sp, TargetPhrase tp, int a
std::auto_ptr<TargetPhrase> targetPhrase(new TargetPhrase(tp));
Scores scoreVec;
scoreVec.push_back(GetPreComputedScores(age)[0]);
- for (unsigned int i=0; i<scores.size(); i++){
- scoreVec.push_back(scores[i]);
+ for (unsigned int i=0; i<scores.size(); i++) {
+ scoreVec.push_back(scores[i]);
}
- if(scoreVec.size() != m_numScoreComponents){
- VERBOSE(1, "Scores does not match number of score components for phrase : "<< sp.ToString() <<" ||| " << tp.ToString() <<endl);
- VERBOSE(1, "Debugging: Press Enter to continue..." <<endl);
- std::cin.ignore();
+ if(scoreVec.size() != m_numScoreComponents) {
+ VERBOSE(1, "Scores does not match number of score components for phrase : "<< sp.ToString() <<" ||| " << tp.ToString() <<endl);
+ VERBOSE(1, "Debugging: Press Enter to continue..." <<endl);
+ std::cin.ignore();
}
targetPhrase->GetScoreBreakdown().Assign(this, scoreVec);
// targetPhrase->GetScoreBreakdown().Assign(this, GetPreComputedScores(age));
@@ -635,17 +636,17 @@ void PhraseDictionaryDynamicCacheBased::Update(Phrase sp, TargetPhrase tp, int a
m_entries++;
VERBOSE(3,"sp:|" << sp << "tp:|" << tp << "| INSERTED" << std::endl);
} else {
- Scores scoreVec;
- scoreVec.push_back(GetPreComputedScores(age)[0]);
- for (unsigned int i=0; i<scores.size(); i++){
- scoreVec.push_back(scores[i]);
- }
- if(scoreVec.size() != m_numScoreComponents){
- VERBOSE(1, "Scores does not match number of score components for phrase : "<< sp.ToString() <<" ||| " << tp.ToString() <<endl);
- VERBOSE(1, "Debugging: Press Enter to continue..." <<endl);
- std::cin.ignore();
- }
- tp_ptr->GetScoreBreakdown().Assign(this, scoreVec);
+ Scores scoreVec;
+ scoreVec.push_back(GetPreComputedScores(age)[0]);
+ for (unsigned int i=0; i<scores.size(); i++) {
+ scoreVec.push_back(scores[i]);
+ }
+ if(scoreVec.size() != m_numScoreComponents) {
+ VERBOSE(1, "Scores does not match number of score components for phrase : "<< sp.ToString() <<" ||| " << tp.ToString() <<endl);
+ VERBOSE(1, "Debugging: Press Enter to continue..." <<endl);
+ std::cin.ignore();
+ }
+ tp_ptr->GetScoreBreakdown().Assign(this, scoreVec);
// tp_ptr->GetScoreBreakdown().Assign(this, GetPreComputedScores(age));
if (!waString.empty()) tp_ptr->SetAlignmentInfo(waString);
ac->at(tp_pos) = age;
@@ -667,13 +668,13 @@ void PhraseDictionaryDynamicCacheBased::Update(Phrase sp, TargetPhrase tp, int a
// scoreVec is a composition of decay_score and the feature scores
Scores scoreVec;
scoreVec.push_back(GetPreComputedScores(age)[0]);
- for (unsigned int i=0; i<scores.size(); i++){
- scoreVec.push_back(scores[i]);
+ for (unsigned int i=0; i<scores.size(); i++) {
+ scoreVec.push_back(scores[i]);
}
- if(scoreVec.size() != m_numScoreComponents){
- VERBOSE(1, "Scores do not match number of score components for phrase : "<< sp <<" ||| " << tp <<endl);
- VERBOSE(1, "Debugging: Press Enter to continue..." <<endl);
- std::cin.ignore();
+ if(scoreVec.size() != m_numScoreComponents) {
+ VERBOSE(1, "Scores do not match number of score components for phrase : "<< sp <<" ||| " << tp <<endl);
+ VERBOSE(1, "Debugging: Press Enter to continue..." <<endl);
+ std::cin.ignore();
}
targetPhrase->GetScoreBreakdown().Assign(this, scoreVec);
if (!waString.empty()) targetPhrase->SetAlignmentInfo(waString);
@@ -788,16 +789,16 @@ void PhraseDictionaryDynamicCacheBased::Clear()
#endif
cacheMap::iterator it;
for(it = m_cacheTM.begin(); it!=m_cacheTM.end(); it++) {
- // clear age collection
- (boost::get<1>((*it).second))->clear();
- // clear score collection
- (boost::get<2>((*it).second))->clear();
- // delete age collection
- delete boost::get<1>((*it).second);
- // delete score collection
- delete boost::get<2>((*it).second);
- // reset the target phrase collection
- (boost::get<0>(it->second)).reset();
+ // clear age collection
+ (boost::get<1>((*it).second))->clear();
+ // clear score collection
+ (boost::get<2>((*it).second))->clear();
+ // delete age collection
+ delete boost::get<1>((*it).second);
+ // delete score collection
+ delete boost::get<2>((*it).second);
+ // reset the target phrase collection
+ (boost::get<0>(it->second)).reset();
}
m_cacheTM.clear();
m_entries = 0;