2006-07-04 22:04:38 +04:00
|
|
|
// $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 "Sentence.h"
|
2008-10-09 03:51:26 +04:00
|
|
|
#include "FactorTypeSet.h"
|
|
|
|
#include "FactorCollection.h"
|
|
|
|
#include "Hypothesis.h"
|
|
|
|
#include "TrellisPathList.h"
|
|
|
|
#include "InputFileStream.h"
|
|
|
|
#include "InputType.h"
|
2009-08-07 20:47:54 +04:00
|
|
|
#include "WordLattice.h"
|
2006-07-04 22:04:38 +04:00
|
|
|
|
2008-08-05 04:24:45 +04:00
|
|
|
class IOWrapper
|
2006-07-04 22:04:38 +04:00
|
|
|
{
|
|
|
|
protected:
|
2006-11-22 02:06:30 +03:00
|
|
|
long m_translationId;
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
const std::vector<Moses::FactorType> &m_inputFactorOrder;
|
|
|
|
const std::vector<Moses::FactorType> &m_outputFactorOrder;
|
|
|
|
const Moses::FactorMask &m_inputFactorUsed;
|
2008-03-01 02:08:58 +03:00
|
|
|
std::ostream *m_nBestStream
|
2008-03-18 00:34:19 +03:00
|
|
|
,*m_outputWordGraphStream,*m_outputSearchGraphStream;
|
2006-11-22 02:06:30 +03:00
|
|
|
std::string m_inputFilePath;
|
|
|
|
std::istream *m_inputStream;
|
2008-10-09 03:51:26 +04:00
|
|
|
Moses::InputFileStream *m_inputFile;
|
2007-01-08 17:46:48 +03:00
|
|
|
bool m_surpressSingleBestOutput;
|
2006-08-12 01:04:38 +04:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
void Initialization(const std::vector<Moses::FactorType> &inputFactorOrder
|
|
|
|
, const std::vector<Moses::FactorType> &outputFactorOrder
|
|
|
|
, const Moses::FactorMask &inputFactorUsed
|
2008-03-01 02:08:58 +03:00
|
|
|
, size_t nBestSize
|
|
|
|
, const std::string &nBestFilePath);
|
|
|
|
|
2006-07-04 22:04:38 +04:00
|
|
|
public:
|
2008-10-09 03:51:26 +04:00
|
|
|
IOWrapper(const std::vector<Moses::FactorType> &inputFactorOrder
|
|
|
|
, const std::vector<Moses::FactorType> &outputFactorOrder
|
|
|
|
, const Moses::FactorMask &inputFactorUsed
|
2006-07-04 22:04:38 +04:00
|
|
|
, size_t nBestSize
|
|
|
|
, const std::string &nBestFilePath);
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
IOWrapper(const std::vector<Moses::FactorType> &inputFactorOrder
|
|
|
|
, const std::vector<Moses::FactorType> &outputFactorOrder
|
|
|
|
, const Moses::FactorMask &inputFactorUsed
|
2006-11-22 02:06:30 +03:00
|
|
|
, size_t nBestSize
|
|
|
|
, const std::string &nBestFilePath
|
2008-03-18 00:34:19 +03:00
|
|
|
, const std::string &infilePath);
|
2008-08-05 04:24:45 +04:00
|
|
|
~IOWrapper();
|
2006-07-29 02:11:20 +04:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
Moses::InputType* GetInput(Moses::InputType *inputType);
|
|
|
|
void OutputBestHypo(const Moses::Hypothesis *hypo, long translationId, bool reportSegmentation, bool reportAllFactors);
|
|
|
|
void OutputBestHypo(const std::vector<const Moses::Factor*>& mbrBestHypo, long translationId, bool reportSegmentation, bool reportAllFactors);
|
2010-02-03 20:04:05 +03:00
|
|
|
void OutputBestHypo(const std::vector<Moses::Word>& mbrBestHypo, long /*translationId*/, bool reportSegmentation, bool reportAllFactors);
|
2008-10-09 03:51:26 +04:00
|
|
|
void OutputNBestList(const Moses::TrellisPathList &nBestList, long translationId);
|
|
|
|
void Backtrack(const Moses::Hypothesis *hypo);
|
2006-07-29 02:11:20 +04:00
|
|
|
|
2006-11-22 02:06:30 +03:00
|
|
|
void ResetTranslationId() { m_translationId = 0; }
|
2006-07-29 02:11:20 +04:00
|
|
|
|
2008-03-01 02:08:58 +03:00
|
|
|
std::ostream &GetOutputWordGraphStream()
|
|
|
|
{
|
|
|
|
return *m_outputWordGraphStream;
|
|
|
|
}
|
2008-03-18 00:34:19 +03:00
|
|
|
std::ostream &GetOutputSearchGraphStream()
|
|
|
|
{
|
|
|
|
return *m_outputSearchGraphStream;
|
|
|
|
}
|
2006-11-22 02:06:30 +03:00
|
|
|
};
|
2009-08-07 20:47:54 +04:00
|
|
|
|
|
|
|
IOWrapper *GetIODevice(const Moses::StaticData &staticData);
|
|
|
|
bool ReadInput(IOWrapper &ioWrapper, Moses::InputTypeEnum inputType, Moses::InputType*& source);
|
|
|
|
void OutputSurface(std::ostream &out, const Moses::Hypothesis *hypo, const std::vector<Moses::FactorType> &outputFactorOrder ,bool reportSegmentation, bool reportAllFactors);
|
2009-08-31 16:55:33 +04:00
|
|
|
void OutputNBest(std::ostream& out, const Moses::TrellisPathList &nBestList, const std::vector<Moses::FactorType>&, long translationId);
|