mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
standardize GetIOWrapper().
This commit is contained in:
parent
65bd64ca6a
commit
2f290f1d6d
@ -123,7 +123,7 @@ int main(int argc, char* argv[])
|
||||
UTIL_THROW_IF2(!staticData.IsChart(), "Must be SCFG model");
|
||||
|
||||
// set up read/writing class
|
||||
IOWrapperChart *ioWrapper = GetIOWrapper(staticData);
|
||||
IOWrapperChart *ioWrapper = IOWrapperChart::GetIOWrapper(staticData);
|
||||
|
||||
// check on weights
|
||||
const ScoreComponentCollection& weights = staticData.GetAllWeights();
|
||||
@ -188,32 +188,3 @@ int main(int argc, char* argv[])
|
||||
#endif
|
||||
}
|
||||
|
||||
IOWrapperChart *GetIOWrapper(const StaticData &staticData)
|
||||
{
|
||||
IOWrapperChart *ioWrapper;
|
||||
const std::vector<FactorType> &inputFactorOrder = staticData.GetInputFactorOrder()
|
||||
,&outputFactorOrder = staticData.GetOutputFactorOrder();
|
||||
FactorMask inputFactorUsed(inputFactorOrder);
|
||||
|
||||
// io
|
||||
if (staticData.GetParam("input-file").size() == 1) {
|
||||
VERBOSE(2,"IO from File" << endl);
|
||||
string filePath = staticData.GetParam("input-file")[0];
|
||||
|
||||
ioWrapper = new IOWrapperChart(inputFactorOrder, outputFactorOrder, inputFactorUsed
|
||||
, staticData.GetNBestSize()
|
||||
, staticData.GetNBestFilePath()
|
||||
, filePath);
|
||||
} else {
|
||||
VERBOSE(1,"IO from STDOUT/STDIN" << endl);
|
||||
ioWrapper = new IOWrapperChart(inputFactorOrder, outputFactorOrder, inputFactorUsed
|
||||
, staticData.GetNBestSize()
|
||||
, staticData.GetNBestFilePath());
|
||||
}
|
||||
ioWrapper->ResetTranslationId();
|
||||
|
||||
IFVERBOSE(1)
|
||||
PrintUserTime("Created input-output object");
|
||||
|
||||
return ioWrapper;
|
||||
}
|
||||
|
@ -36,10 +36,4 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "moses/StaticData.h"
|
||||
|
||||
namespace MosesChartCmd
|
||||
{
|
||||
class IOWrapperChart;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]);
|
||||
MosesChartCmd::IOWrapperChart *GetIOWrapper(const Moses::StaticData &staticData);
|
||||
|
@ -116,7 +116,7 @@ int main(int argc, char** argv)
|
||||
srand(time(NULL));
|
||||
|
||||
// set up read/writing class
|
||||
IOWrapper* ioWrapper = GetIOWrapper(staticData);
|
||||
IOWrapper* ioWrapper = IOWrapper::GetIOWrapper(staticData);
|
||||
if (!ioWrapper) {
|
||||
cerr << "Error; Failed to create IO object" << endl;
|
||||
exit(1);
|
||||
|
@ -633,29 +633,7 @@ void IOWrapper::OutputLatticeMBRNBestList(const vector<LatticeMBRSolution>& solu
|
||||
OutputLatticeMBRNBest(*m_nBestStream, solutions,translationId);
|
||||
}
|
||||
|
||||
bool ReadInput(IOWrapper &ioWrapper, InputTypeEnum inputType, InputType*& source)
|
||||
{
|
||||
if (source) delete source;
|
||||
switch(inputType) {
|
||||
case SentenceInput:
|
||||
source = ioWrapper.GetInput(new Sentence);
|
||||
break;
|
||||
case ConfusionNetworkInput:
|
||||
source = ioWrapper.GetInput(new ConfusionNet);
|
||||
break;
|
||||
case WordLatticeInput:
|
||||
source = ioWrapper.GetInput(new WordLattice);
|
||||
break;
|
||||
default:
|
||||
TRACE_ERR("Unknown input type: " << inputType << "\n");
|
||||
source = NULL;
|
||||
}
|
||||
return (source ? true : false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
IOWrapper *GetIOWrapper(const StaticData &staticData)
|
||||
IOWrapper *IOWrapper::GetIOWrapper(const StaticData &staticData)
|
||||
{
|
||||
IOWrapper *ioWrapper;
|
||||
const std::vector<FactorType> &inputFactorOrder = staticData.GetInputFactorOrder()
|
||||
@ -680,5 +658,26 @@ IOWrapper *GetIOWrapper(const StaticData &staticData)
|
||||
return ioWrapper;
|
||||
}
|
||||
|
||||
|
||||
bool ReadInput(IOWrapper &ioWrapper, InputTypeEnum inputType, InputType*& source)
|
||||
{
|
||||
if (source) delete source;
|
||||
switch(inputType) {
|
||||
case SentenceInput:
|
||||
source = ioWrapper.GetInput(new Sentence);
|
||||
break;
|
||||
case ConfusionNetworkInput:
|
||||
source = ioWrapper.GetInput(new ConfusionNet);
|
||||
break;
|
||||
case WordLatticeInput:
|
||||
source = ioWrapper.GetInput(new WordLattice);
|
||||
break;
|
||||
default:
|
||||
TRACE_ERR("Unknown input type: " << inputType << "\n");
|
||||
source = NULL;
|
||||
}
|
||||
return (source ? true : false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -95,6 +95,8 @@ protected:
|
||||
Moses::OutputCollector *m_latticeSamplesCollector;
|
||||
|
||||
public:
|
||||
static IOWrapper *GetIOWrapper(const Moses::StaticData &staticData);
|
||||
|
||||
IOWrapper(const std::vector<Moses::FactorType> &inputFactorOrder
|
||||
, const std::vector<Moses::FactorType> &outputFactorOrder
|
||||
, const Moses::FactorMask &inputFactorUsed
|
||||
@ -147,7 +149,6 @@ public:
|
||||
|
||||
};
|
||||
|
||||
IOWrapper *GetIOWrapper(const Moses::StaticData &staticData);
|
||||
bool ReadInput(IOWrapper &ioWrapper, Moses::InputTypeEnum inputType, Moses::InputType*& source);
|
||||
void OutputLanguageModelOrder(std::ostream &out, const Moses::Hypothesis *hypo, Moses::Manager &manager);
|
||||
void OutputBestSurface(std::ostream &out, const Moses::Hypothesis *hypo, const std::vector<Moses::FactorType> &outputFactorOrder, char reportSegmentation, bool reportAllFactors);
|
||||
|
@ -1016,5 +1016,35 @@ void IOWrapperChart::OutputAlignment(vector< set<size_t> > &retAlignmentsS2T, co
|
||||
}
|
||||
}
|
||||
|
||||
IOWrapperChart *IOWrapperChart::GetIOWrapper(const StaticData &staticData)
|
||||
{
|
||||
IOWrapperChart *ioWrapper;
|
||||
const std::vector<FactorType> &inputFactorOrder = staticData.GetInputFactorOrder()
|
||||
,&outputFactorOrder = staticData.GetOutputFactorOrder();
|
||||
FactorMask inputFactorUsed(inputFactorOrder);
|
||||
|
||||
// io
|
||||
if (staticData.GetParam("input-file").size() == 1) {
|
||||
VERBOSE(2,"IO from File" << endl);
|
||||
string filePath = staticData.GetParam("input-file")[0];
|
||||
|
||||
ioWrapper = new IOWrapperChart(inputFactorOrder, outputFactorOrder, inputFactorUsed
|
||||
, staticData.GetNBestSize()
|
||||
, staticData.GetNBestFilePath()
|
||||
, filePath);
|
||||
} else {
|
||||
VERBOSE(1,"IO from STDOUT/STDIN" << endl);
|
||||
ioWrapper = new IOWrapperChart(inputFactorOrder, outputFactorOrder, inputFactorUsed
|
||||
, staticData.GetNBestSize()
|
||||
, staticData.GetNBestFilePath());
|
||||
}
|
||||
ioWrapper->ResetTranslationId();
|
||||
|
||||
IFVERBOSE(1)
|
||||
PrintUserTime("Created input-output object");
|
||||
|
||||
return ioWrapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -113,6 +113,8 @@ protected:
|
||||
, std::string &lastName );
|
||||
|
||||
public:
|
||||
static IOWrapperChart *GetIOWrapper(const Moses::StaticData &staticData);
|
||||
|
||||
IOWrapperChart(const std::vector<Moses::FactorType> &inputFactorOrder
|
||||
, const std::vector<Moses::FactorType> &outputFactorOrder
|
||||
, const Moses::FactorMask &inputFactorUsed
|
||||
|
Loading…
Reference in New Issue
Block a user