diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2014-06-08 18:41:27 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2014-06-08 18:41:27 +0400 |
commit | 23ba0de2247e84db69759445a41c4c4f04840460 (patch) | |
tree | 0ace1b8a46aada207d2d6e71a14d61eafaa58ed5 /phrase-extract | |
parent | d979b24314944348cea2d7f8d8e00691c64abebb (diff) |
use standard c++ getline instead of old Moses SAFE_GETLINE
Diffstat (limited to 'phrase-extract')
-rw-r--r-- | phrase-extract/SentenceAlignment.cpp | 6 | ||||
-rw-r--r-- | phrase-extract/SentenceAlignment.h | 7 | ||||
-rw-r--r-- | phrase-extract/extract-main.cpp | 28 |
3 files changed, 23 insertions, 18 deletions
diff --git a/phrase-extract/SentenceAlignment.cpp b/phrase-extract/SentenceAlignment.cpp index c3d71d525..120c9154d 100644 --- a/phrase-extract/SentenceAlignment.cpp +++ b/phrase-extract/SentenceAlignment.cpp @@ -54,7 +54,11 @@ bool SentenceAlignment::processSourceSentence(const char * sourceString, int, bo return true; } -bool SentenceAlignment::create( char targetString[], char sourceString[], char alignmentString[], char weightString[], int sentenceID, bool boundaryRules) +bool SentenceAlignment::create(const char targetString[], + const char sourceString[], + const char alignmentString[], + const char weightString[], + int sentenceID, bool boundaryRules) { using namespace std; this->sentenceID = sentenceID; diff --git a/phrase-extract/SentenceAlignment.h b/phrase-extract/SentenceAlignment.h index 1df61cf02..576d3279e 100644 --- a/phrase-extract/SentenceAlignment.h +++ b/phrase-extract/SentenceAlignment.h @@ -43,8 +43,11 @@ public: virtual bool processSourceSentence(const char *, int, bool boundaryRules); - bool create(char targetString[], char sourceString[], - char alignmentString[], char weightString[], int sentenceID, bool boundaryRules); + bool create(const char targetString[], + const char sourceString[], + const char alignmentString[], + const char weightString[], + int sentenceID, bool boundaryRules); void invertAlignment(); diff --git a/phrase-extract/extract-main.cpp b/phrase-extract/extract-main.cpp index 5d58028d6..698599a10 100644 --- a/phrase-extract/extract-main.cpp +++ b/phrase-extract/extract-main.cpp @@ -32,10 +32,6 @@ using namespace MosesTraining; namespace MosesTraining { - -const long int LINE_MAX_LENGTH = 500000 ; - - // HPhraseVertex represents a point in the alignment matrix typedef pair <int, int> HPhraseVertex; @@ -277,20 +273,18 @@ int main(int argc, char* argv[]) int i = sentenceOffset; - while(true) { + string englishString, foreignString, alignmentString, weightString; + + while(getline(*eFileP, englishString)) { i++; if (i%10000 == 0) cerr << "." << flush; - char englishString[LINE_MAX_LENGTH]; - char foreignString[LINE_MAX_LENGTH]; - char alignmentString[LINE_MAX_LENGTH]; - char weightString[LINE_MAX_LENGTH]; - SAFE_GETLINE((*eFileP), englishString, LINE_MAX_LENGTH, '\n', __FILE__); - if (eFileP->eof()) break; - SAFE_GETLINE((*fFileP), foreignString, LINE_MAX_LENGTH, '\n', __FILE__); - SAFE_GETLINE((*aFileP), alignmentString, LINE_MAX_LENGTH, '\n', __FILE__); + + getline(*fFileP, foreignString); + getline(*aFileP, alignmentString); if (iwFileP) { - SAFE_GETLINE((*iwFileP), weightString, LINE_MAX_LENGTH, '\n', __FILE__); + getline(*iwFileP, weightString); } + SentenceAlignment sentence; // cout << "read in: " << englishString << " & " << foreignString << " & " << alignmentString << endl; //az: output src, tgt, and alingment line @@ -300,7 +294,11 @@ int main(int argc, char* argv[]) cout << "LOG: ALT: " << alignmentString << endl; cout << "LOG: PHRASES_BEGIN:" << endl; } - if (sentence.create( englishString, foreignString, alignmentString, weightString, i, false)) { + if (sentence.create( englishString.c_str(), + foreignString.c_str(), + alignmentString.c_str(), + weightString.c_str(), + i, false)) { if (options.placeholders.size()) { sentence.invertAlignment(); } |