2010-04-08 21:16:10 +04:00
|
|
|
#pragma once
|
2010-10-12 20:17:41 +04:00
|
|
|
// $Id$
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based, hierarchical and syntactic language decoder
|
|
|
|
Copyright (C) 2009 Hieu Hoang
|
2011-02-24 16:57:11 +03:00
|
|
|
|
2010-10-12 20:17:41 +04:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2011-02-24 16:57:11 +03:00
|
|
|
|
2010-10-12 20:17:41 +04:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2011-02-24 16:57:11 +03:00
|
|
|
|
2010-10-12 20:17:41 +04:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include "Word.h"
|
|
|
|
#include "Phrase.h"
|
2012-05-18 22:09:04 +04:00
|
|
|
#include "SourcePhrase.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
2011-02-24 16:57:11 +03:00
|
|
|
class PhraseDictionary;
|
|
|
|
class TargetPhrase;
|
|
|
|
class LMList;
|
|
|
|
class Phrase;
|
|
|
|
class WordPenaltyProducer;
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace OnDiskPt
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef std::pair<UINT64, UINT64> AlignPair;
|
|
|
|
typedef std::vector<AlignPair> AlignType;
|
|
|
|
|
2012-05-15 19:17:06 +04:00
|
|
|
class Vocab;
|
|
|
|
|
2012-06-29 04:12:31 +04:00
|
|
|
/** A target phrase, with the score breakdowns, alignment info and assorted other information it need.
|
|
|
|
* Readable and writeable to disk
|
|
|
|
*/
|
2010-04-08 21:16:10 +04:00
|
|
|
class TargetPhrase: public Phrase
|
|
|
|
{
|
2011-02-24 16:57:11 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const TargetPhrase&);
|
2010-04-08 21:16:10 +04:00
|
|
|
protected:
|
2011-02-24 16:57:11 +03:00
|
|
|
AlignType m_align;
|
2012-09-20 00:48:10 +04:00
|
|
|
PhrasePtr m_sourcePhrase;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2012-11-14 21:14:46 +04:00
|
|
|
std::vector<float> m_scores;
|
2011-02-24 16:57:11 +03:00
|
|
|
UINT64 m_filePos;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 16:57:11 +03:00
|
|
|
size_t WriteAlignToMemory(char *mem) const;
|
|
|
|
size_t WriteScoresToMemory(char *mem) const;
|
|
|
|
|
|
|
|
UINT64 ReadAlignFromFile(std::fstream &fileTPColl);
|
|
|
|
UINT64 ReadScoresFromFile(std::fstream &fileTPColl);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
public:
|
2012-11-14 21:14:46 +04:00
|
|
|
TargetPhrase()
|
|
|
|
{}
|
2011-02-24 16:57:11 +03:00
|
|
|
TargetPhrase(size_t numScores);
|
2012-11-14 21:14:46 +04:00
|
|
|
TargetPhrase(const TargetPhrase ©);
|
2011-02-24 16:57:11 +03:00
|
|
|
virtual ~TargetPhrase();
|
|
|
|
|
2012-09-20 00:48:10 +04:00
|
|
|
void SetSourcePhrase(PhrasePtr p) {
|
|
|
|
m_sourcePhrase = p;
|
2012-05-18 22:09:04 +04:00
|
|
|
}
|
2012-09-20 00:48:10 +04:00
|
|
|
const PhrasePtr GetSourcePhrase() const {
|
2012-11-14 21:14:46 +04:00
|
|
|
return m_sourcePhrase;
|
|
|
|
}
|
|
|
|
const std::vector<float> &GetScores() const{
|
|
|
|
return m_scores;
|
2012-05-18 22:09:04 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 00:48:10 +04:00
|
|
|
void SetLHS(WordPtr lhs);
|
2011-02-24 16:57:11 +03:00
|
|
|
|
|
|
|
void Create1AlignFromString(const std::string &align1Str);
|
2012-04-29 10:11:30 +04:00
|
|
|
void CreateAlignFromString(const std::string &align1Str);
|
2011-02-24 16:57:11 +03:00
|
|
|
void SetScore(float score, size_t ind);
|
|
|
|
|
|
|
|
const AlignType &GetAlign() const {
|
|
|
|
return m_align;
|
|
|
|
}
|
|
|
|
void SortAlign();
|
|
|
|
|
|
|
|
char *WriteToMemory(OnDiskWrapper &onDiskWrapper, size_t &memUsed) const;
|
|
|
|
char *WriteOtherInfoToMemory(OnDiskWrapper &onDiskWrapper, size_t &memUsed) const;
|
|
|
|
void Save(OnDiskWrapper &onDiskWrapper);
|
|
|
|
|
|
|
|
UINT64 GetFilePos() const {
|
|
|
|
return m_filePos;
|
|
|
|
}
|
|
|
|
float GetScore(size_t ind) const {
|
|
|
|
return m_scores[ind];
|
|
|
|
}
|
|
|
|
|
|
|
|
Moses::TargetPhrase *ConvertToMoses(const std::vector<Moses::FactorType> &inputFactors
|
|
|
|
, const std::vector<Moses::FactorType> &outputFactors
|
|
|
|
, const Vocab &vocab
|
|
|
|
, const Moses::PhraseDictionary &phraseDict
|
|
|
|
, const std::vector<float> &weightT
|
|
|
|
, const Moses::WordPenaltyProducer* wpProducer
|
|
|
|
, const Moses::LMList &lmList) const;
|
|
|
|
UINT64 ReadOtherInfoFromFile(UINT64 filePos, std::fstream &fileTPColl);
|
2012-06-16 00:44:45 +04:00
|
|
|
UINT64 ReadFromFile(std::fstream &fileTP);
|
2011-02-24 16:57:11 +03:00
|
|
|
|
2012-05-15 19:35:00 +04:00
|
|
|
virtual void DebugPrint(std::ostream &out, const Vocab &vocab) const;
|
2012-05-15 19:17:06 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|