2010-07-18 03:23:09 +04:00
|
|
|
// $Id$
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (c) 2006 University of Edinburgh
|
|
|
|
All rights reserved.
|
|
|
|
|
2011-02-24 15:40:21 +03:00
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
2010-04-08 21:16:10 +04:00
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
2011-02-24 15:40:21 +03:00
|
|
|
* Redistributions of source code must retain the above copyright notice,
|
2010-04-08 21:16:10 +04:00
|
|
|
this list of conditions and the following disclaimer.
|
2011-02-24 15:40:21 +03:00
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2010-04-08 21:16:10 +04:00
|
|
|
and/or other materials provided with the distribution.
|
2011-02-24 15:40:21 +03:00
|
|
|
* 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
|
2010-04-08 21:16:10 +04:00
|
|
|
without specific prior written permission.
|
|
|
|
|
2011-02-24 15:40:21 +03:00
|
|
|
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
|
2010-04-08 21:16:10 +04:00
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
// example file on how to use moses library
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <vector>
|
2012-11-16 20:44:29 +04:00
|
|
|
#include <set>
|
2012-11-13 00:21:32 +04:00
|
|
|
#include "moses/TypeDef.h"
|
|
|
|
#include "moses/Sentence.h"
|
|
|
|
#include "moses/FactorTypeSet.h"
|
|
|
|
#include "moses/ChartTrellisPathList.h"
|
|
|
|
#include "moses/OutputCollector.h"
|
|
|
|
#include "moses/ChartHypothesis.h"
|
|
|
|
#include "moses/ChartTrellisPath.h"
|
2012-11-16 18:46:10 +04:00
|
|
|
#include "search/applied.hh"
|
2012-01-20 19:35:55 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
class FactorCollection;
|
2011-03-11 16:08:43 +03:00
|
|
|
class ChartTrellisPathList;
|
2012-12-07 17:28:11 +04:00
|
|
|
class ScoreComponentCollection;
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
|
2012-07-02 20:05:11 +04:00
|
|
|
namespace MosesChartCmd
|
|
|
|
{
|
|
|
|
|
2012-06-29 04:12:31 +04:00
|
|
|
/** Helper class that holds misc variables to write data out to command line.
|
|
|
|
*/
|
2010-04-08 21:16:10 +04:00
|
|
|
class IOWrapper
|
|
|
|
{
|
|
|
|
protected:
|
2012-12-03 18:57:33 +04:00
|
|
|
typedef std::vector<std::pair<Moses::Word, Moses::WordsRange> > ApplicationContext;
|
2011-01-26 16:15:13 +03:00
|
|
|
|
2011-02-24 15:40:21 +03:00
|
|
|
long m_translationId;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:40:21 +03:00
|
|
|
const std::vector<Moses::FactorType> &m_inputFactorOrder;
|
|
|
|
const std::vector<Moses::FactorType> &m_outputFactorOrder;
|
|
|
|
const Moses::FactorMask &m_inputFactorUsed;
|
2012-11-15 19:52:35 +04:00
|
|
|
std::ostream *m_outputSearchGraphStream;
|
|
|
|
std::ostream *m_detailedTranslationReportingStream;
|
|
|
|
std::ostream *m_alignmentInfoStream;
|
|
|
|
std::string m_inputFilePath;
|
|
|
|
std::istream *m_inputStream;
|
2011-01-26 16:15:13 +03:00
|
|
|
Moses::OutputCollector *m_detailOutputCollector;
|
2011-01-25 18:17:17 +03:00
|
|
|
Moses::OutputCollector *m_nBestOutputCollector;
|
|
|
|
Moses::OutputCollector *m_searchGraphOutputCollector;
|
|
|
|
Moses::OutputCollector *m_singleBestOutputCollector;
|
2012-11-15 19:52:35 +04:00
|
|
|
Moses::OutputCollector *m_alignmentInfoCollector;
|
|
|
|
|
2012-11-16 20:44:29 +04:00
|
|
|
typedef std::set< std::pair<size_t, size_t> > Alignments;
|
2012-11-16 22:25:17 +04:00
|
|
|
size_t OutputAlignmentNBest(Alignments &retAlign, const Moses::ChartTrellisNode &node, size_t startTarget);
|
2012-11-16 20:44:29 +04:00
|
|
|
size_t OutputAlignment(Alignments &retAlign, const Moses::ChartHypothesis *hypo, size_t startTarget);
|
|
|
|
void OutputAlignment(std::vector< std::set<size_t> > &retAlignmentsS2T, const Moses::AlignmentInfo &ai);
|
2012-12-03 18:57:33 +04:00
|
|
|
void OutputTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId);
|
|
|
|
void ReconstructApplicationContext(const Moses::ChartHypothesis &hypo,
|
|
|
|
const Moses::Sentence &sentence,
|
|
|
|
ApplicationContext &context);
|
|
|
|
void WriteApplicationContext(std::ostream &out,
|
|
|
|
const ApplicationContext &context);
|
2011-01-25 18:17:17 +03:00
|
|
|
|
2013-05-11 17:13:26 +04:00
|
|
|
void OutputAllFeatureScores(const Moses::ScoreComponentCollection &features
|
2013-05-29 21:16:15 +04:00
|
|
|
, std::ostream &out);
|
2012-12-07 17:28:11 +04:00
|
|
|
void OutputFeatureScores( std::ostream& out
|
2013-05-29 21:16:15 +04:00
|
|
|
, const Moses::ScoreComponentCollection &features
|
|
|
|
, const Moses::FeatureFunction *ff
|
|
|
|
, std::string &lastName );
|
2012-12-07 17:28:11 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
public:
|
2011-02-24 15:40:21 +03:00
|
|
|
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="");
|
|
|
|
~IOWrapper();
|
|
|
|
|
|
|
|
Moses::InputType* GetInput(Moses::InputType *inputType);
|
2012-10-11 20:11:42 +04:00
|
|
|
void OutputBestHypo(const Moses::ChartHypothesis *hypo, long translationId);
|
2012-11-16 18:46:10 +04:00
|
|
|
void OutputBestHypo(search::Applied applied, long translationId);
|
2012-10-11 20:11:42 +04:00
|
|
|
void OutputBestHypo(const std::vector<const Moses::Factor*>& mbrBestHypo, long translationId);
|
2012-11-16 18:46:10 +04:00
|
|
|
void OutputBestNone(long translationId);
|
2013-05-11 17:13:26 +04:00
|
|
|
void OutputNBestList(const Moses::ChartTrellisPathList &nBestList, long translationId);
|
|
|
|
void OutputNBestList(const std::vector<search::Applied> &nbest, long translationId);
|
2012-01-25 16:26:28 +04:00
|
|
|
void OutputDetailedTranslationReport(const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId);
|
2011-03-11 16:08:43 +03:00
|
|
|
void Backtrack(const Moses::ChartHypothesis *hypo);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-11-13 21:14:40 +04:00
|
|
|
void ResetTranslationId();
|
2011-02-24 15:40:21 +03:00
|
|
|
|
|
|
|
Moses::OutputCollector *GetSearchGraphOutputCollector() {
|
|
|
|
return m_searchGraphOutputCollector;
|
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2012-11-15 19:52:35 +04:00
|
|
|
void OutputAlignment(size_t translationId , const Moses::ChartHypothesis *hypo);
|
|
|
|
|
2011-01-25 18:17:17 +03:00
|
|
|
static void FixPrecision(std::ostream &, size_t size=3);
|
2010-04-08 21:16:10 +04:00
|
|
|
};
|
2012-07-02 20:05:11 +04:00
|
|
|
|
|
|
|
}
|