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:
authorhieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230>2006-11-22 02:06:30 +0300
committerhieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230>2006-11-22 02:06:30 +0300
commit7af5bb462e41ba3515c52994989da7d247636754 (patch)
tree008af155f58d7d99b9830a8a3cd41a51cb02e791 /moses-cmd
parent7e00b6ee8b796c5c82b47c24b4b1cc4e36dde963 (diff)
dismantle IODevoce framework
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@992 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'moses-cmd')
-rw-r--r--moses-cmd/moses-cmd.vcproj12
-rwxr-xr-xmoses-cmd/src/IOFile.cpp56
-rwxr-xr-xmoses-cmd/src/IOFile.h59
-rwxr-xr-xmoses-cmd/src/IOStream.cpp (renamed from moses-cmd/src/IOCommandLine.cpp)54
-rwxr-xr-xmoses-cmd/src/IOStream.h (renamed from moses-cmd/src/IOCommandLine.h)47
-rw-r--r--moses-cmd/src/Main.cpp33
-rw-r--r--moses-cmd/src/Main.h4
-rw-r--r--moses-cmd/src/Makefile.am2
8 files changed, 92 insertions, 175 deletions
diff --git a/moses-cmd/moses-cmd.vcproj b/moses-cmd/moses-cmd.vcproj
index 3288091b3..01c014b7f 100644
--- a/moses-cmd/moses-cmd.vcproj
+++ b/moses-cmd/moses-cmd.vcproj
@@ -181,11 +181,7 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
- RelativePath=".\src\IOCommandLine.cpp"
- >
- </File>
- <File
- RelativePath=".\src\IOFile.cpp"
+ RelativePath=".\src\IOStream.cpp"
>
</File>
<File
@@ -203,11 +199,7 @@
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
- RelativePath=".\src\IOCommandLine.h"
- >
- </File>
- <File
- RelativePath=".\src\IOFile.h"
+ RelativePath=".\src\IOStream.h"
>
</File>
<File
diff --git a/moses-cmd/src/IOFile.cpp b/moses-cmd/src/IOFile.cpp
deleted file mode 100755
index 469cd45db..000000000
--- a/moses-cmd/src/IOFile.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// $Id$
-
-/***********************************************************************
-Moses - factored phrase-based language decoder
-Copyright (c) 2006 University of Edinburgh
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the University of Edinburgh nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-***********************************************************************/
-
-// example file on how to use moses library
-
-#include "IOFile.h"
-#include "Sentence.h"
-using namespace std;
-
-IOFile::IOFile(const std::vector<FactorType> &inputFactorOrder
- , const std::vector<FactorType> &outputFactorOrder
- , const FactorMask &inputFactorUsed
- , FactorCollection &factorCollection
- , size_t nBestSize
- , const std::string &nBestFilePath
- , const std::string &inputFilePath)
-:IOCommandLine(inputFactorOrder, outputFactorOrder, inputFactorUsed, factorCollection, nBestSize, nBestFilePath)
-,m_inputFilePath(inputFilePath)
-,m_inputFile(inputFilePath)
-{
-}
-
-InputType* IOFile::GetInput(InputType* in)
-{
- return IODevice::GetInput(in,m_inputFile, m_inputFactorOrder, m_factorCollection);
-}
-
diff --git a/moses-cmd/src/IOFile.h b/moses-cmd/src/IOFile.h
deleted file mode 100755
index bb6ee792a..000000000
--- a/moses-cmd/src/IOFile.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// $Id$
-
-/***********************************************************************
-Moses - factored phrase-based language decoder
-Copyright (c) 2006 University of Edinburgh
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the University of Edinburgh nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-***********************************************************************/
-
-// example file on how to use moses library
-
-#pragma once
-
-#include <fstream>
-#include <vector>
-#include "TypeDef.h"
-#include "IOCommandLine.h"
-#include "InputFileStream.h"
-
-class IOFile : public IOCommandLine
-{
-protected:
- std::string m_inputFilePath;
- InputFileStream m_inputFile;
-public:
- IOFile(const std::vector<FactorType> &inputFactorOrder
- , const std::vector<FactorType> &outputFactorOrder
- , const FactorMask &inputFactorUsed
- , FactorCollection &factorCollection
- , size_t nBestSize
- , const std::string &nBestFilePath
- , const std::string &inputFilePath);
-
- InputType *GetInput(InputType*);
-};
-
diff --git a/moses-cmd/src/IOCommandLine.cpp b/moses-cmd/src/IOStream.cpp
index 3858a87cb..2e655066c 100755
--- a/moses-cmd/src/IOCommandLine.cpp
+++ b/moses-cmd/src/IOStream.cpp
@@ -35,16 +35,17 @@ POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
#include "TypeDef.h"
#include "Util.h"
-#include "IOCommandLine.h"
+#include "IOStream.h"
#include "Hypothesis.h"
#include "WordsRange.h"
#include "LatticePathList.h"
#include "StaticData.h"
#include "DummyScoreProducers.h"
+#include "InputFileStream.h"
using namespace std;
-IOCommandLine::IOCommandLine(
+IOStream::IOStream(
const vector<FactorType> &inputFactorOrder
, const vector<FactorType> &outputFactorOrder
, const FactorMask &inputFactorUsed
@@ -55,6 +56,8 @@ IOCommandLine::IOCommandLine(
,m_outputFactorOrder(outputFactorOrder)
,m_inputFactorUsed(inputFactorUsed)
,m_factorCollection(factorCollection)
+,m_inputFile(NULL)
+,m_inputStream(&std::cin)
{
if (nBestSize > 0)
{
@@ -62,9 +65,46 @@ IOCommandLine::IOCommandLine(
}
}
-InputType*IOCommandLine::GetInput(InputType* in)
+IOStream::IOStream(const std::vector<FactorType> &inputFactorOrder
+ , const std::vector<FactorType> &outputFactorOrder
+ , const FactorMask &inputFactorUsed
+ , FactorCollection &factorCollection
+ , size_t nBestSize
+ , const std::string &nBestFilePath
+ , const std::string &inputFilePath)
+:m_inputFactorOrder(inputFactorOrder)
+,m_outputFactorOrder(outputFactorOrder)
+,m_inputFactorUsed(inputFactorUsed)
+,m_factorCollection(factorCollection)
+,m_inputFilePath(inputFilePath)
+,m_inputFile(new InputFileStream(inputFilePath))
+{
+ m_inputStream = m_inputFile;
+
+ if (nBestSize > 0)
+ {
+ m_nBestFile.open(nBestFilePath.c_str());
+ }
+}
+
+IOStream::~IOStream()
+{
+ if (m_inputFile != NULL)
+ delete m_inputFile;
+}
+
+InputType*IOStream::GetInput(InputType* inputType)
{
- return IODevice::GetInput(in,std::cin,m_inputFactorOrder, m_factorCollection);
+ if(inputType->Read(*m_inputStream, m_inputFactorOrder, m_factorCollection))
+ {
+ inputType->SetTranslationId(m_translationId++);
+ return inputType;
+ }
+ else
+ {
+ delete inputType;
+ return NULL;
+ }
}
/***
@@ -111,7 +151,7 @@ void OutputSurface(std::ostream &out, const Hypothesis *hypo, const std::vector<
}
}
-void IOCommandLine::Backtrack(const Hypothesis *hypo){
+void IOStream::Backtrack(const Hypothesis *hypo){
if (hypo->GetPrevHypo() != NULL) {
VERBOSE(3,hypo->GetId() << " <= ");
@@ -119,7 +159,7 @@ void IOCommandLine::Backtrack(const Hypothesis *hypo){
}
}
-void IOCommandLine::SetOutput(const Hypothesis *hypo, long /*translationId*/, bool reportSegmentation, bool reportAllFactors)
+void IOStream::OutputBestHypo(const Hypothesis *hypo, long /*translationId*/, bool reportSegmentation, bool reportAllFactors)
{
if (hypo != NULL)
{
@@ -138,7 +178,7 @@ void IOCommandLine::SetOutput(const Hypothesis *hypo, long /*translationId*/, bo
cout << endl;
}
-void IOCommandLine::SetNBest(const LatticePathList &nBestList, long translationId)
+void IOStream::OutputNBestList(const LatticePathList &nBestList, long translationId)
{
bool labeledOutput = StaticData::Instance()->IsLabeledNBestList();
diff --git a/moses-cmd/src/IOCommandLine.h b/moses-cmd/src/IOStream.h
index 42026d003..a14c78041 100755
--- a/moses-cmd/src/IOCommandLine.h
+++ b/moses-cmd/src/IOStream.h
@@ -37,49 +37,50 @@ POSSIBILITY OF SUCH DAMAGE.
#include <fstream>
#include <vector>
#include "TypeDef.h"
-#include "IODevice.h"
#include "Sentence.h"
class FactorMask;
class FactorCollection;
+class Hypothesis;
+class LatticePathList;
+class InputFileStream;
-class IOCommandLine : public IODevice
+class IOStream
{
protected:
+ long m_translationId;
+
const std::vector<FactorType> &m_inputFactorOrder;
const std::vector<FactorType> &m_outputFactorOrder;
const FactorMask &m_inputFactorUsed;
FactorCollection &m_factorCollection;
std::ofstream m_nBestFile;
+ std::string m_inputFilePath;
+ std::istream *m_inputStream;
+ InputFileStream *m_inputFile;
public:
- IOCommandLine(const std::vector<FactorType> &inputFactorOrder
+ IOStream(const std::vector<FactorType> &inputFactorOrder
, const std::vector<FactorType> &outputFactorOrder
, const FactorMask &inputFactorUsed
, FactorCollection &factorCollection
, size_t nBestSize
, const std::string &nBestFilePath);
- InputType* GetInput(InputType*);
- void SetOutput(const Hypothesis *hypo, long translationId, bool reportSegmentation, bool reportAllFactors);
- void SetNBest(const LatticePathList &nBestList, long translationId);
- void Backtrack(const Hypothesis *hypo);
-};
+ IOStream(const std::vector<FactorType> &inputFactorOrder
+ , const std::vector<FactorType> &outputFactorOrder
+ , const FactorMask &inputFactorUsed
+ , FactorCollection &factorCollection
+ , size_t nBestSize
+ , const std::string &nBestFilePath
+ , const std::string &inputFilePath);
+ ~IOStream();
-#if 0
-// help fn
-inline Sentence *GetInput(std::istream &inputStream
- , const std::vector<FactorType> &factorOrder
- , FactorCollection &factorCollection)
-{
+ InputType* GetInput(InputType *inputType);
+ void OutputBestHypo(const Hypothesis *hypo, long translationId, bool reportSegmentation, bool reportAllFactors);
+ void OutputNBestList(const LatticePathList &nBestList, long translationId);
+ void Backtrack(const Hypothesis *hypo);
- return dynamic_cast<Sentence*>(GetInput(new Sentence(Input),inputStream,factorOrder,factorCollection));
-#if 0
- Sentence *rv=new Sentence(Input);
- if(rv->Read(inputStream,factorOrder,factorCollection))
- return rv;
- else {delete rv; return 0;}
-#endif
-}
+ void ResetTranslationId() { m_translationId = 0; }
-#endif
+};
diff --git a/moses-cmd/src/Main.cpp b/moses-cmd/src/Main.cpp
index 6a1143295..aaffde7f4 100644
--- a/moses-cmd/src/Main.cpp
+++ b/moses-cmd/src/Main.cpp
@@ -46,8 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "Util.h"
#include "LatticePathList.h"
#include "Timer.h"
-#include "IOCommandLine.h"
-#include "IOFile.h"
+#include "IOStream.h"
#include "Sentence.h"
#include "ConfusionNet.h"
#include "TranslationAnalysis.h"
@@ -61,10 +60,10 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace std;
-bool readInput(IODevice *inputOutput, int inputType, InputType*& source)
+bool readInput(IOStream &ioStream, int inputType, InputType*& source)
{
delete source;
- source=inputOutput->GetInput((inputType ?
+ source=ioStream.GetInput((inputType ?
static_cast<InputType*>(new ConfusionNet) :
static_cast<InputType*>(new Sentence(Input))));
return (source ? true : false);
@@ -91,7 +90,7 @@ int main(int argc, char* argv[])
return EXIT_FAILURE;
// set up read/writing class
- IODevice *ioDevice = GetIODevice(staticData);
+ IOStream *ioStream = GetIODevice(staticData);
// check on weights
vector<float> weights = staticData.GetAllWeights();
@@ -107,13 +106,13 @@ int main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if (ioDevice == NULL)
+ if (ioStream == NULL)
return EXIT_FAILURE;
// read each sentence & decode
InputType *source=0;
size_t lineCount = 0;
- while(readInput(ioDevice,staticData.GetInputType(),source))
+ while(readInput(*ioStream,staticData.GetInputType(),source))
{
// note: source is only valid within this while loop!
ResetUserTime();
@@ -123,7 +122,7 @@ int main(int argc, char* argv[])
staticData.InitializeBeforeSentenceProcessing(*source);
Manager manager(*source, staticData);
manager.ProcessSentence();
- ioDevice->SetOutput(manager.GetBestHypothesis(), source->GetTranslationId(),
+ ioStream->OutputBestHypo(manager.GetBestHypothesis(), source->GetTranslationId(),
staticData.GetReportSegmentation(),
staticData.GetReportAllFactors()
);
@@ -135,7 +134,7 @@ int main(int argc, char* argv[])
VERBOSE(2,"WRITING " << nBestSize << " TRANSLATION ALTERNATIVES TO " << staticData.GetNBestFilePath() << endl);
LatticePathList nBestList;
manager.CalcNBest(nBestSize, nBestList,staticData.OnlyDistinctNBest());
- ioDevice->SetNBest(nBestList, source->GetTranslationId());
+ ioStream->OutputNBestList(nBestList, source->GetTranslationId());
//RemoveAllInColl(nBestList);
}
@@ -150,26 +149,26 @@ int main(int argc, char* argv[])
}
- delete ioDevice;
+ delete ioStream;
PrintUserTime("End.");
return EXIT_SUCCESS;
}
-IODevice *GetIODevice(StaticData &staticData)
+IOStream *GetIODevice(StaticData &staticData)
{
- IODevice *ioDevice;
+ IOStream *ioStream;
const std::vector<FactorType> &inputFactorOrder = staticData.GetInputFactorOrder()
,&outputFactorOrder = staticData.GetOutputFactorOrder();
FactorMask inputFactorUsed(inputFactorOrder);
// io
- if (staticData.GetIOMethod() == IOMethodFile)
+ if (staticData.GetParam("input-file").size() == 1)
{
VERBOSE(2,"IO from File" << endl);
string filePath = staticData.GetParam("input-file")[0];
- ioDevice = new IOFile(inputFactorOrder, outputFactorOrder, inputFactorUsed
+ ioStream = new IOStream(inputFactorOrder, outputFactorOrder, inputFactorUsed
, staticData.GetFactorCollection()
, staticData.GetNBestSize()
, staticData.GetNBestFilePath()
@@ -178,14 +177,14 @@ IODevice *GetIODevice(StaticData &staticData)
else
{
VERBOSE(1,"IO from STDOUT/STDIN" << endl);
- ioDevice = new IOCommandLine(inputFactorOrder, outputFactorOrder, inputFactorUsed
+ ioStream = new IOStream(inputFactorOrder, outputFactorOrder, inputFactorUsed
, staticData.GetFactorCollection()
, staticData.GetNBestSize()
, staticData.GetNBestFilePath());
}
- ioDevice->ResetTranslationId();
+ ioStream->ResetTranslationId();
PrintUserTime("Created input-output object");
- return ioDevice;
+ return ioStream;
}
diff --git a/moses-cmd/src/Main.h b/moses-cmd/src/Main.h
index e898c9f93..1457bcd1b 100644
--- a/moses-cmd/src/Main.h
+++ b/moses-cmd/src/Main.h
@@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "StaticData.h"
-class IODevice;
+class IOStream;
int main(int argc, char* argv[]);
-IODevice *GetIODevice(StaticData &staticData);
+IOStream *GetIODevice(StaticData &staticData);
diff --git a/moses-cmd/src/Makefile.am b/moses-cmd/src/Makefile.am
index a2d0057db..7c15b360b 100644
--- a/moses-cmd/src/Makefile.am
+++ b/moses-cmd/src/Makefile.am
@@ -1,5 +1,5 @@
bin_PROGRAMS = moses
-moses_SOURCES = Main.cpp IOCommandLine.cpp IOFile.cpp TranslationAnalysis.cpp
+moses_SOURCES = Main.cpp IOStream.cpp TranslationAnalysis.cpp
AM_CPPFLAGS = -W -Wall -ffor-scope -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -I$(top_srcdir)/moses/src
moses_LDADD = -L$(top_srcdir)/moses/src -lmoses