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
diff options
context:
space:
mode:
authorHieu Hoang <hieu@hoang.co.uk>2013-09-27 12:35:24 +0400
committerHieu Hoang <hieu@hoang.co.uk>2013-09-27 12:35:24 +0400
commit31ce9b510e9a06e998ddddfbe92f0192cf7656b8 (patch)
tree3bfd084ffb9eb72abe1a560cee0be3b5dc0ace7b /phrase-extract
parent13e1adf0002c00b84ff9735d5afddb7e0b73530e (diff)
beautify
Diffstat (limited to 'phrase-extract')
-rw-r--r--phrase-extract/PhraseExtractionOptions.h2
-rw-r--r--phrase-extract/SentenceAlignment.cpp18
-rw-r--r--phrase-extract/extract-main.cpp38
-rw-r--r--phrase-extract/extract-rules-main.cpp127
4 files changed, 91 insertions, 94 deletions
diff --git a/phrase-extract/PhraseExtractionOptions.h b/phrase-extract/PhraseExtractionOptions.h
index a410473f4..d70c2a117 100644
--- a/phrase-extract/PhraseExtractionOptions.h
+++ b/phrase-extract/PhraseExtractionOptions.h
@@ -109,7 +109,7 @@ public:
void initInstanceWeightsFile(const char* initInstanceWeightsFile) {
instanceWeightsFile = std::string(initInstanceWeightsFile);
}
- void initFlexScoreFlag(const bool initflexScoreFlag){
+ void initFlexScoreFlag(const bool initflexScoreFlag) {
flexScoreFlag=initflexScoreFlag;
}
diff --git a/phrase-extract/SentenceAlignment.cpp b/phrase-extract/SentenceAlignment.cpp
index 4420ec5ae..c3d71d525 100644
--- a/phrase-extract/SentenceAlignment.cpp
+++ b/phrase-extract/SentenceAlignment.cpp
@@ -124,15 +124,15 @@ bool SentenceAlignment::create( char targetString[], char sourceString[], char a
void SentenceAlignment::invertAlignment()
{
- alignedToS.resize(source.size());
- for (size_t targetPos = 0; targetPos < alignedToT.size(); ++targetPos) {
- const std::vector<int> &vec = alignedToT[targetPos];
- for (size_t i = 0; i < vec.size(); ++i) {
- int sourcePos = vec[i];
- alignedToS[sourcePos].push_back(targetPos);
- }
-
- }
+ alignedToS.resize(source.size());
+ for (size_t targetPos = 0; targetPos < alignedToT.size(); ++targetPos) {
+ const std::vector<int> &vec = alignedToT[targetPos];
+ for (size_t i = 0; i < vec.size(); ++i) {
+ int sourcePos = vec[i];
+ alignedToS[sourcePos].push_back(targetPos);
+ }
+
+ }
}
}
diff --git a/phrase-extract/extract-main.cpp b/phrase-extract/extract-main.cpp
index 1b545d136..0b21eb19a 100644
--- a/phrase-extract/extract-main.cpp
+++ b/phrase-extract/extract-main.cpp
@@ -300,7 +300,7 @@ int main(int argc, char* argv[])
}
if (sentence.create( englishString, foreignString, alignmentString, weightString, i, false)) {
if (options.placeholders.size()) {
- sentence.invertAlignment();
+ sentence.invertAlignment();
}
ExtractTask *task = new ExtractTask(i-1, sentence, options, extractFile , extractFileInv, extractFileOrientation, extractFileContext, extractFileContextInv);
task->Run();
@@ -863,10 +863,10 @@ void ExtractTask::writePhrasesToFile()
for(vector<string>::const_iterator phrase=m_extractedPhrasesOri.begin(); phrase!=m_extractedPhrasesOri.end(); phrase++) {
outextractFileOrientation<<phrase->data();
}
- for(vector<string>::const_iterator phrase=m_extractedPhrasesContext.begin();phrase!=m_extractedPhrasesContext.end();phrase++){
+ for(vector<string>::const_iterator phrase=m_extractedPhrasesContext.begin(); phrase!=m_extractedPhrasesContext.end(); phrase++) {
outextractFileContext<<phrase->data();
}
- for(vector<string>::const_iterator phrase=m_extractedPhrasesContextInv.begin();phrase!=m_extractedPhrasesContextInv.end();phrase++){
+ for(vector<string>::const_iterator phrase=m_extractedPhrasesContextInv.begin(); phrase!=m_extractedPhrasesContextInv.end(); phrase++) {
outextractFileContextInv<<phrase->data();
}
@@ -921,15 +921,14 @@ bool ExtractTask::checkPlaceholders (const SentenceAlignment &sentence, int star
const string &sourceWord = sentence.source[pos];
if (isPlaceholder(sourceWord)) {
if (sentence.alignedToS.at(pos).size() != 1) {
- return false;
- }
- else {
- // check it actually lines up to another placeholder
- int targetPos = sentence.alignedToS.at(pos).at(0);
- const string &otherWord = sentence.target[targetPos];
- if (!isPlaceholder(otherWord)) {
- return false;
- }
+ return false;
+ } else {
+ // check it actually lines up to another placeholder
+ int targetPos = sentence.alignedToS.at(pos).at(0);
+ const string &otherWord = sentence.target[targetPos];
+ if (!isPlaceholder(otherWord)) {
+ return false;
+ }
}
}
}
@@ -939,14 +938,13 @@ bool ExtractTask::checkPlaceholders (const SentenceAlignment &sentence, int star
if (isPlaceholder(targetWord)) {
if (sentence.alignedToT.at(pos).size() != 1) {
return false;
- }
- else {
- // check it actually lines up to another placeholder
- int sourcePos = sentence.alignedToT.at(pos).at(0);
- const string &otherWord = sentence.source[sourcePos];
- if (!isPlaceholder(otherWord)) {
- return false;
- }
+ } else {
+ // check it actually lines up to another placeholder
+ int sourcePos = sentence.alignedToT.at(pos).at(0);
+ const string &otherWord = sentence.source[sourcePos];
+ if (!isPlaceholder(otherWord)) {
+ return false;
+ }
}
}
}
diff --git a/phrase-extract/extract-rules-main.cpp b/phrase-extract/extract-rules-main.cpp
index c625c3582..f5f44316e 100644
--- a/phrase-extract/extract-rules-main.cpp
+++ b/phrase-extract/extract-rules-main.cpp
@@ -315,8 +315,8 @@ int main(int argc, char* argv[])
string fileNameExtractContext = fileNameExtract + ".context" + (options.gzOutput?".gz":"");
extractFileContext.Open(fileNameExtractContext.c_str());
if (!options.onlyDirectFlag) {
- string fileNameExtractContextInv = fileNameExtract + ".context.inv" + (options.gzOutput?".gz":"");
- extractFileContextInv.Open(fileNameExtractContextInv.c_str());
+ string fileNameExtractContextInv = fileNameExtract + ".context.inv" + (options.gzOutput?".gz":"");
+ extractFileContextInv.Open(fileNameExtractContextInv.c_str());
}
}
@@ -716,44 +716,43 @@ void ExtractTask::saveHieroPhrase( int startT, int endT, int startS, int endS
// context (words to left and right)
if (m_options.flexScoreFlag) {
- rule.sourceContextLeft = startS == 0 ? "<s>" : m_sentence.source[startS-1];
- rule.sourceContextRight = endS+1 == m_sentence.source.size() ? "<s>" : m_sentence.source[endS+1];
- rule.targetContextLeft = startT == 0 ? "<s>" : m_sentence.target[startT-1];
- rule.targetContextRight = endT+1 == m_sentence.target.size() ? "<s>" : m_sentence.target[endT+1];
- rule.sourceHoleString = "";
- rule.targetHoleString = "";
-
- HoleList::const_iterator iterHole;
- for (iterHole = holeColl.GetHoles().begin(); iterHole != holeColl.GetHoles().end(); ++iterHole) {
- const Hole &hole = *iterHole;
- rule.sourceHoleString += hole.GetLabel(0) + ": ";
-
- // rule starts with nonterminal; end of NT is considered left context
- if (hole.GetStart(0) == startS) {
- rule.sourceContextLeft = m_sentence.source[hole.GetEnd(0)];
- }
- // rule ends with nonterminal; start of NT is considered right context
- else if (hole.GetEnd(0) == endS) {
- rule.sourceContextRight = m_sentence.source[hole.GetStart(0)];
- }
+ rule.sourceContextLeft = startS == 0 ? "<s>" : m_sentence.source[startS-1];
+ rule.sourceContextRight = endS+1 == m_sentence.source.size() ? "<s>" : m_sentence.source[endS+1];
+ rule.targetContextLeft = startT == 0 ? "<s>" : m_sentence.target[startT-1];
+ rule.targetContextRight = endT+1 == m_sentence.target.size() ? "<s>" : m_sentence.target[endT+1];
+ rule.sourceHoleString = "";
+ rule.targetHoleString = "";
+
+ HoleList::const_iterator iterHole;
+ for (iterHole = holeColl.GetHoles().begin(); iterHole != holeColl.GetHoles().end(); ++iterHole) {
+ const Hole &hole = *iterHole;
+ rule.sourceHoleString += hole.GetLabel(0) + ": ";
+
+ // rule starts with nonterminal; end of NT is considered left context
+ if (hole.GetStart(0) == startS) {
+ rule.sourceContextLeft = m_sentence.source[hole.GetEnd(0)];
+ }
+ // rule ends with nonterminal; start of NT is considered right context
+ else if (hole.GetEnd(0) == endS) {
+ rule.sourceContextRight = m_sentence.source[hole.GetStart(0)];
+ }
- if (hole.GetStart(1) == startT) {
- rule.targetContextLeft = m_sentence.target[hole.GetEnd(1)];
- }
- else if (hole.GetEnd(1) == endT) {
- rule.targetContextRight = m_sentence.target[hole.GetStart(1)];
- }
+ if (hole.GetStart(1) == startT) {
+ rule.targetContextLeft = m_sentence.target[hole.GetEnd(1)];
+ } else if (hole.GetEnd(1) == endT) {
+ rule.targetContextRight = m_sentence.target[hole.GetStart(1)];
+ }
- for (int i = hole.GetStart(0); i <= hole.GetEnd(0); ++i) {
- rule.sourceHoleString += m_sentence.source[i] + " ";
- }
- rule.targetHoleString += hole.GetLabel(1) + ": ";
- for (int i = hole.GetStart(1); i <= hole.GetEnd(1); ++i) {
- rule.targetHoleString += m_sentence.target[i] + " ";
- }
+ for (int i = hole.GetStart(0); i <= hole.GetEnd(0); ++i) {
+ rule.sourceHoleString += m_sentence.source[i] + " ";
}
+ rule.targetHoleString += hole.GetLabel(1) + ": ";
+ for (int i = hole.GetStart(1); i <= hole.GetEnd(1); ++i) {
+ rule.targetHoleString += m_sentence.target[i] + " ";
+ }
+ }
}
-
+
addRuleToCollection( rule );
}
@@ -996,10 +995,10 @@ void ExtractTask::addRule( int startT, int endT, int startS, int endS, int count
// context (words to left and right)
if (m_options.flexScoreFlag) {
- rule.sourceContextLeft = startS == 0 ? "<s>" : m_sentence.source[startS-1];
- rule.sourceContextRight = endS+1 == m_sentence.source.size() ? "<s>" : m_sentence.source[endS+1];
- rule.targetContextLeft = startT == 0 ? "<s>" : m_sentence.target[startT-1];
- rule.targetContextRight = endT+1 == m_sentence.target.size() ? "<s>" : m_sentence.target[endT+1];
+ rule.sourceContextLeft = startS == 0 ? "<s>" : m_sentence.source[startS-1];
+ rule.sourceContextRight = endS+1 == m_sentence.source.size() ? "<s>" : m_sentence.source[endS+1];
+ rule.targetContextLeft = startT == 0 ? "<s>" : m_sentence.target[startT-1];
+ rule.targetContextRight = endT+1 == m_sentence.target.size() ? "<s>" : m_sentence.target[endT+1];
}
rule.alignment.erase(rule.alignment.size()-1);
@@ -1084,33 +1083,33 @@ void ExtractTask::writeRulesToFile()
}
if (m_options.flexScoreFlag) {
- for(int iContext=0;iContext<2;iContext++){
- outContext << rule->source << " ||| "
- << rule->target << " ||| "
- << rule->alignment << " ||| ";
- iContext ? outContext << "< " << rule->sourceContextLeft << "\n" : outContext << "> " << rule->sourceContextRight << "\n";
-
- if (!m_options.onlyDirectFlag) {
- outContextInv << rule->target << " ||| "
- << rule->source << " ||| "
- << rule->alignmentInv << " ||| ";
- iContext ? outContextInv << "< " << rule->targetContextLeft << "\n" : outContextInv << "> " << rule->targetContextRight << "\n";
- }
+ for(int iContext=0; iContext<2; iContext++) {
+ outContext << rule->source << " ||| "
+ << rule->target << " ||| "
+ << rule->alignment << " ||| ";
+ iContext ? outContext << "< " << rule->sourceContextLeft << "\n" : outContext << "> " << rule->sourceContextRight << "\n";
+
+ if (!m_options.onlyDirectFlag) {
+ outContextInv << rule->target << " ||| "
+ << rule->source << " ||| "
+ << rule->alignmentInv << " ||| ";
+ iContext ? outContextInv << "< " << rule->targetContextLeft << "\n" : outContextInv << "> " << rule->targetContextRight << "\n";
}
+ }
- if (rule->sourceHoleString != "") {
- outContext << rule->source << " ||| "
- << rule->target << " ||| "
- << rule->alignment << " ||| v "
- << rule->sourceHoleString << "\n";
- }
+ if (rule->sourceHoleString != "") {
+ outContext << rule->source << " ||| "
+ << rule->target << " ||| "
+ << rule->alignment << " ||| v "
+ << rule->sourceHoleString << "\n";
+ }
- if (!m_options.onlyDirectFlag and rule->targetHoleString != "") {
- outContextInv << rule->target << " ||| "
- << rule->source << " ||| "
- << rule->alignmentInv << " ||| v "
- << rule->targetHoleString << "\n";
- }
+ if (!m_options.onlyDirectFlag and rule->targetHoleString != "") {
+ outContextInv << rule->target << " ||| "
+ << rule->source << " ||| "
+ << rule->alignmentInv << " ||| v "
+ << rule->targetHoleString << "\n";
+ }
}
}
m_extractFile << out.str();