diff options
author | pjwilliams <pjwilliams@1f5c12ca-751b-0410-a591-d2e778427230> | 2010-05-07 22:43:34 +0400 |
---|---|---|
committer | pjwilliams <pjwilliams@1f5c12ca-751b-0410-a591-d2e778427230> | 2010-05-07 22:43:34 +0400 |
commit | fd4851f15de3a1d3838f63d88c67ee23d7bb0180 (patch) | |
tree | accf3a1afd702e8785abc496d3938e0968ad4640 /moses-chart-cmd/src | |
parent | 01f4ca892a510139310b3c220965b028a2b71a60 (diff) |
Merge moses_chart's two IOWrapper constructors into one.
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@3238 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'moses-chart-cmd/src')
-rw-r--r-- | moses-chart-cmd/src/IOWrapper.cpp | 62 | ||||
-rw-r--r-- | moses-chart-cmd/src/IOWrapper.h | 10 |
2 files changed, 15 insertions, 57 deletions
diff --git a/moses-chart-cmd/src/IOWrapper.cpp b/moses-chart-cmd/src/IOWrapper.cpp index d6d9a687f..8a27ff439 100644 --- a/moses-chart-cmd/src/IOWrapper.cpp +++ b/moses-chart-cmd/src/IOWrapper.cpp @@ -48,49 +48,6 @@ using namespace std; using namespace Moses; using namespace MosesChart; -IOWrapper::IOWrapper( - const vector<FactorType> &inputFactorOrder - , const vector<FactorType> &outputFactorOrder - , const FactorMask &inputFactorUsed - , size_t nBestSize - , const string &nBestFilePath) -:m_inputFactorOrder(inputFactorOrder) -,m_outputFactorOrder(outputFactorOrder) -,m_inputFactorUsed(inputFactorUsed) -,m_inputFile(NULL) -,m_inputStream(&std::cin) -,m_nBestStream(NULL) -,m_outputSearchGraphStream(NULL) -{ - const StaticData &staticData = StaticData::Instance(); - - m_surpressSingleBestOutput = false; - if (nBestSize > 0) - { - if (nBestFilePath == "-") - { - m_nBestStream = &std::cout; - m_surpressSingleBestOutput = true; - } - else - { - std::ofstream *nBestFile = new std::ofstream; - m_nBestStream = nBestFile; - nBestFile->open(nBestFilePath.c_str()); - } - } - - // search graph output - if (staticData.GetOutputSearchGraph()) - { - string fileName = staticData.GetParam("output-search-graph")[0]; - std::ofstream *file = new std::ofstream; - m_outputSearchGraphStream = file; - file->open(fileName.c_str()); - } - -} - IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder , const std::vector<FactorType> &outputFactorOrder , const FactorMask &inputFactorUsed @@ -100,15 +57,22 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder :m_inputFactorOrder(inputFactorOrder) ,m_outputFactorOrder(outputFactorOrder) ,m_inputFactorUsed(inputFactorUsed) -,m_inputFilePath(inputFilePath) -,m_inputFile(new InputFileStream(inputFilePath)) ,m_nBestStream(NULL) ,m_outputSearchGraphStream(NULL) +,m_inputFilePath(inputFilePath) { const StaticData &staticData = StaticData::Instance(); + if (m_inputFilePath.empty()) + { + m_inputStream = &std::cin; + } + else + { + m_inputStream = new InputFileStream(inputFilePath); + } + m_surpressSingleBestOutput = false; - m_inputStream = m_inputFile; if (nBestSize > 0) { @@ -138,8 +102,10 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder IOWrapper::~IOWrapper() { - if (m_inputFile != NULL) - delete m_inputFile; + if (!m_inputFilePath.empty()) + { + delete m_inputStream; + } if (m_nBestStream != NULL && !m_surpressSingleBestOutput) { // outputting n-best to file, rather than stdout. need to close file and delete obj delete m_nBestStream; diff --git a/moses-chart-cmd/src/IOWrapper.h b/moses-chart-cmd/src/IOWrapper.h index 493365389..866a86a26 100644 --- a/moses-chart-cmd/src/IOWrapper.h +++ b/moses-chart-cmd/src/IOWrapper.h @@ -39,7 +39,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "TypeDef.h" #include "Sentence.h" #include "FactorTypeSet.h" -#include "InputFileStream.h" #include "TrellisPathList.h" #include "../../moses-chart/src/ChartHypothesis.h" @@ -64,22 +63,15 @@ protected: std::ostream *m_nBestStream, *m_outputSearchGraphStream; std::string m_inputFilePath; std::istream *m_inputStream; - Moses::InputFileStream *m_inputFile; bool m_surpressSingleBestOutput; public: IOWrapper(const std::vector<Moses::FactorType> &inputFactorOrder - , const std::vector<Moses::FactorType> &outputFactorOrder - , const Moses::FactorMask &inputFactorUsed - , size_t nBestSize - , const std::string &nBestFilePath); - - IOWrapper(const std::vector<Moses::FactorType> &inputFactorOrder , const std::vector<Moses::FactorType> &outputFactorOrder , const Moses::FactorMask &inputFactorUsed , size_t nBestSize , const std::string &nBestFilePath - , const std::string &inputFilePath); + , const std::string &inputFilePath=""); ~IOWrapper(); Moses::InputType* GetInput(Moses::InputType *inputType); |