mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 05:55:02 +03:00
beautify
This commit is contained in:
parent
f93a1db381
commit
7dc6ad4255
@ -27,16 +27,14 @@ namespace Moses
|
||||
boost::shared_lock<boost::shared_mutex> lock(m_cacheLock);
|
||||
#endif
|
||||
precomputedScores.clear();
|
||||
for (size_t i=0; i<maxAge; i++)
|
||||
{
|
||||
for (size_t i=0; i<maxAge; i++) {
|
||||
precomputedScores.push_back(decaying_score(i));
|
||||
}
|
||||
|
||||
if ( score_type == CBLM_SCORE_TYPE_HYPERBOLA
|
||||
|| score_type == CBLM_SCORE_TYPE_POWER
|
||||
|| score_type == CBLM_SCORE_TYPE_EXPONENTIAL
|
||||
|| score_type == CBLM_SCORE_TYPE_COSINE )
|
||||
{
|
||||
|| score_type == CBLM_SCORE_TYPE_COSINE ) {
|
||||
precomputedScores.push_back(decaying_score(maxAge));
|
||||
} else { // score_type = CBLM_SCORE_TYPE_XXXXXXXXX_REWARD
|
||||
precomputedScores.push_back(0.0);
|
||||
@ -48,11 +46,9 @@ namespace Moses
|
||||
std::cerr << "DynamicCacheBasedLanguageModel::SetParameter" << std::endl;
|
||||
if (key == "cblm-query-type") {
|
||||
query_type = Scan<size_t>(value);
|
||||
}
|
||||
else if (key == "cblm-score-type") {
|
||||
} else if (key == "cblm-score-type") {
|
||||
score_type = Scan<size_t>(value);
|
||||
}
|
||||
else if (key == "cblm-file") {
|
||||
} else if (key == "cblm-file") {
|
||||
m_initfiles = Scan<std::string>(value);
|
||||
} else {
|
||||
StatelessFeatureFunction::SetParameter(key, value);
|
||||
@ -100,8 +96,7 @@ namespace Moses
|
||||
it = m_cache.find(w);
|
||||
// VERBOSE(1,"cblm::Evaluate: cheching cache for w:|" << w << "|" << std::endl);
|
||||
|
||||
if (it != m_cache.end()) //found!
|
||||
{
|
||||
if (it != m_cache.end()) { //found!
|
||||
score += ((*it).second).second;
|
||||
VERBOSE(3,"cblm::Evaluate_Whole_String: found w:|" << w << "| actual score:|" << ((*it).second).second << "| score:|" <<
|
||||
score << "|" << std::endl);
|
||||
@ -126,8 +121,7 @@ score << "|" << std::endl);
|
||||
it = m_cache.find(w);
|
||||
|
||||
// VERBOSE(1,"cblm::Evaluate_All_Substrings: cheching cache for w:|" << w << "|" << std::endl);
|
||||
if (it != m_cache.end()) //found!
|
||||
{
|
||||
if (it != m_cache.end()) { //found!
|
||||
score += ((*it).second).second;
|
||||
VERBOSE(3,"cblm::Evaluate_All_Substrings: found w:|" << w << "| actual score:|" << ((*it).second).second << "| score:|" << score << "|" << std::endl);
|
||||
}
|
||||
@ -149,8 +143,7 @@ score << "|" << std::endl);
|
||||
#endif
|
||||
decaying_cache_t::const_iterator it;
|
||||
std::cout << "Content of the cache of Cache-Based Language Model" << std::endl;
|
||||
for ( it=m_cache.begin() ; it != m_cache.end(); it++ )
|
||||
{
|
||||
for ( it=m_cache.begin() ; it != m_cache.end(); it++ ) {
|
||||
std::cout << "word:|" << (*it).first << "| age:|" << ((*it).second).first << "| score:|" << ((*it).second).second << "|" << std::endl;
|
||||
}
|
||||
}
|
||||
@ -164,16 +157,12 @@ score << "|" << std::endl);
|
||||
|
||||
int age;
|
||||
float score;
|
||||
for ( it=m_cache.begin() ; it != m_cache.end(); it++ )
|
||||
{
|
||||
for ( it=m_cache.begin() ; it != m_cache.end(); it++ ) {
|
||||
age=((*it).second).first + 1;
|
||||
if (age > 1000)
|
||||
{
|
||||
if (age > 1000) {
|
||||
m_cache.erase(it);
|
||||
it--;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
score = decaying_score(age);
|
||||
decaying_cache_value_t p (age, score);
|
||||
(*it).second = p;
|
||||
@ -186,8 +175,7 @@ score << "|" << std::endl);
|
||||
#ifdef WITH_THREADS
|
||||
boost::shared_lock<boost::shared_mutex> lock(m_cacheLock);
|
||||
#endif
|
||||
for (size_t j=0; j<words.size(); j++)
|
||||
{
|
||||
for (size_t j=0; j<words.size(); j++) {
|
||||
words[j] = Trim(words[j]);
|
||||
VERBOSE(3,"CacheBasedLanguageModel::Update word[" << j << "]:"<< words[j] << " age:" << age << " decaying_score(age):" << decaying_score(age) << std::endl);
|
||||
decaying_cache_value_t p (age,decaying_score(age));
|
||||
@ -199,8 +187,7 @@ score << "|" << std::endl);
|
||||
|
||||
void DynamicCacheBasedLanguageModel::Insert(std::string &entries)
|
||||
{
|
||||
if (entries != "")
|
||||
{
|
||||
if (entries != "") {
|
||||
VERBOSE(1,"entries:|" << entries << "|" << std::endl);
|
||||
std::vector<std::string> elements = TokenizeMultiCharSeparator(entries, "||");
|
||||
VERBOSE(1,"elements.size() after:|" << elements.size() << "|" << std::endl);
|
||||
@ -225,8 +212,7 @@ score << "|" << std::endl);
|
||||
|
||||
void DynamicCacheBasedLanguageModel::Execute(std::vector<std::string> commands)
|
||||
{
|
||||
for (size_t j=0; j<commands.size(); j++)
|
||||
{
|
||||
for (size_t j=0; j<commands.size(); j++) {
|
||||
Execute_Single_Command(commands[j]);
|
||||
}
|
||||
IFVERBOSE(2) Print();
|
||||
@ -235,23 +221,16 @@ score << "|" << std::endl);
|
||||
void DynamicCacheBasedLanguageModel::Execute_Single_Command(std::string command)
|
||||
{
|
||||
VERBOSE(1,"CacheBasedLanguageModel::Execute_Single_Command(std::string command:|" << command << "|" << std::endl);
|
||||
if (command == "clear")
|
||||
{
|
||||
if (command == "clear") {
|
||||
VERBOSE(1,"CacheBasedLanguageModel Execute command:|"<< command << "|. Cache cleared." << std::endl);
|
||||
Clear();
|
||||
}
|
||||
else if (command == "settype_wholestring")
|
||||
{
|
||||
} else if (command == "settype_wholestring") {
|
||||
VERBOSE(1,"CacheBasedLanguageModel Execute command:|"<< command << "|. Query type set to " << CBLM_QUERY_TYPE_WHOLESTRING << " (CBLM_QUERY_TYPE_WHOLESTRING)." << std::endl);
|
||||
SetQueryType(CBLM_QUERY_TYPE_WHOLESTRING);
|
||||
}
|
||||
else if (command == "settype_allsubstrings")
|
||||
{
|
||||
} else if (command == "settype_allsubstrings") {
|
||||
VERBOSE(1,"CacheBasedLanguageModel Execute command:|"<< command << "|. Query type set to " << CBLM_QUERY_TYPE_ALLSUBSTRINGS << " (CBLM_QUERY_TYPE_ALLSUBSTRINGS)." << std::endl);
|
||||
SetQueryType(CBLM_QUERY_TYPE_ALLSUBSTRINGS);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
VERBOSE(1,"CacheBasedLanguageModel Execute command:|"<< command << "| is unknown. Skipped." << std::endl);
|
||||
}
|
||||
}
|
||||
@ -280,8 +259,7 @@ score << "|" << std::endl);
|
||||
|
||||
void DynamicCacheBasedLanguageModel::Load(std::vector<std::string> files)
|
||||
{
|
||||
for(size_t j = 0; j < files.size(); ++j)
|
||||
{
|
||||
for(size_t j = 0; j < files.size(); ++j) {
|
||||
Load_Single_File(files[j]);
|
||||
}
|
||||
}
|
||||
@ -320,15 +298,15 @@ score << "|" << std::endl);
|
||||
IFVERBOSE(2) Print();
|
||||
}
|
||||
|
||||
void DynamicCacheBasedLanguageModel::SetQueryType(size_t type) {
|
||||
void DynamicCacheBasedLanguageModel::SetQueryType(size_t type)
|
||||
{
|
||||
#ifdef WITH_THREADS
|
||||
boost::shared_lock<boost::shared_mutex> read_lock(m_cacheLock);
|
||||
#endif
|
||||
|
||||
query_type = type;
|
||||
if ( query_type != CBLM_QUERY_TYPE_WHOLESTRING
|
||||
&& query_type != CBLM_QUERY_TYPE_ALLSUBSTRINGS )
|
||||
{
|
||||
&& query_type != CBLM_QUERY_TYPE_ALLSUBSTRINGS ) {
|
||||
VERBOSE(2, "This query type " << query_type << " is unknown. Instead used " << CBLM_QUERY_TYPE_ALLSUBSTRINGS << "." << std::endl);
|
||||
query_type = CBLM_QUERY_TYPE_ALLSUBSTRINGS;
|
||||
}
|
||||
@ -336,7 +314,8 @@ score << "|" << std::endl);
|
||||
|
||||
};
|
||||
|
||||
void DynamicCacheBasedLanguageModel::SetScoreType(size_t type) {
|
||||
void DynamicCacheBasedLanguageModel::SetScoreType(size_t type)
|
||||
{
|
||||
#ifdef WITH_THREADS
|
||||
boost::shared_lock<boost::shared_mutex> read_lock(m_cacheLock);
|
||||
#endif
|
||||
@ -347,15 +326,15 @@ score << "|" << std::endl);
|
||||
&& score_type != CBLM_SCORE_TYPE_COSINE
|
||||
&& score_type != CBLM_SCORE_TYPE_HYPERBOLA_REWARD
|
||||
&& score_type != CBLM_SCORE_TYPE_POWER_REWARD
|
||||
&& score_type != CBLM_SCORE_TYPE_EXPONENTIAL_REWARD )
|
||||
{
|
||||
&& score_type != CBLM_SCORE_TYPE_EXPONENTIAL_REWARD ) {
|
||||
VERBOSE(2, "This score type " << score_type << " is unknown. Instead used " << CBLM_SCORE_TYPE_HYPERBOLA << "." << std::endl);
|
||||
score_type = CBLM_SCORE_TYPE_HYPERBOLA;
|
||||
}
|
||||
VERBOSE(2, "CacheBasedLanguageModel ScoreType: " << score_type << std::endl);
|
||||
};
|
||||
|
||||
void DynamicCacheBasedLanguageModel::SetMaxAge(unsigned int age) {
|
||||
void DynamicCacheBasedLanguageModel::SetMaxAge(unsigned int age)
|
||||
{
|
||||
#ifdef WITH_THREADS
|
||||
boost::shared_lock<boost::shared_mutex> read_lock(m_cacheLock);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user