2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
#ifndef PHRASEDICTIONARYTREE_H_
|
|
|
|
#define PHRASEDICTIONARYTREE_H_
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include "TypeDef.h"
|
|
|
|
#include "Dictionary.h"
|
|
|
|
|
2008-09-12 22:09:06 +04:00
|
|
|
|
|
|
|
#include "PrefixTree.h"
|
|
|
|
#include "File.h"
|
|
|
|
#include "ObjectPool.h"
|
|
|
|
#include "LVoc.h"
|
|
|
|
#include "TypeDef.h"
|
|
|
|
#include "Util.h"
|
|
|
|
#include "StaticData.h"
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
class Phrase;
|
|
|
|
class Word;
|
|
|
|
class ConfusionNet;
|
|
|
|
|
2008-09-12 22:09:06 +04:00
|
|
|
|
|
|
|
typedef PrefixTreeF<LabelId,OFF_T> PTF;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
class PDTimp;
|
|
|
|
class PPimp;
|
|
|
|
|
|
|
|
class PhraseDictionaryTree : public Dictionary {
|
|
|
|
PDTimp *imp; //implementation
|
|
|
|
|
|
|
|
PhraseDictionaryTree(); // not implemented
|
|
|
|
PhraseDictionaryTree(const PhraseDictionaryTree&); //not implemented
|
|
|
|
void operator=(const PhraseDictionaryTree&); //not implemented
|
|
|
|
public:
|
2008-09-12 22:09:06 +04:00
|
|
|
PhraseDictionaryTree(size_t numScoreComponent);
|
|
|
|
|
|
|
|
void UseWordAlignment(bool a);
|
|
|
|
bool UseWordAlignment();
|
|
|
|
|
|
|
|
void PrintWordAlignment(bool a);
|
|
|
|
bool PrintWordAlignment();
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
virtual ~PhraseDictionaryTree();
|
|
|
|
|
|
|
|
DecodeType GetDecodeType() const {return Translate;}
|
|
|
|
size_t GetSize() const {return 0;}
|
|
|
|
|
|
|
|
// convert from ascii phrase table format
|
|
|
|
// note: only creates table, does not keep it in memory
|
|
|
|
// -> use Read(outFileNamePrefix);
|
|
|
|
int Create(std::istream& in,const std::string& outFileNamePrefix);
|
|
|
|
|
|
|
|
int Read(const std::string& fileNamePrefix);
|
|
|
|
|
|
|
|
// free memory used by the prefix tree etc.
|
|
|
|
void FreeMemory() const;
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************
|
|
|
|
* access with full source phrase *
|
|
|
|
**************************************/
|
|
|
|
// print target candidates for a given phrase, mainly for debugging
|
|
|
|
void PrintTargetCandidates(const std::vector<std::string>& src,
|
|
|
|
std::ostream& out) const;
|
2008-09-12 22:09:06 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
// get the target candidates for a given phrase
|
|
|
|
void GetTargetCandidates(const std::vector<std::string>& src,
|
|
|
|
std::vector<StringTgtCand>& rv) const;
|
2008-09-12 22:09:06 +04:00
|
|
|
|
|
|
|
// get the target candidates for a given phrase
|
|
|
|
void GetTargetCandidates(const std::vector<std::string>& src,
|
|
|
|
std::vector<StringTgtCand>& rv,
|
|
|
|
std::vector<StringWordAlignmentCand>& swa,
|
|
|
|
std::vector<StringWordAlignmentCand>& twa) const;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
/*****************************
|
|
|
|
* access to prefix tree *
|
|
|
|
*****************************/
|
|
|
|
|
|
|
|
// 'pointer' into prefix tree
|
|
|
|
// the only permitted direct operation is a check for NULL,
|
|
|
|
// e.g. PrefixPtr p; if(p) ...
|
|
|
|
// other usage only through PhraseDictionaryTree-functions below
|
|
|
|
|
|
|
|
class PrefixPtr {
|
|
|
|
PPimp* imp;
|
|
|
|
friend class PDTimp;
|
|
|
|
public:
|
|
|
|
PrefixPtr(PPimp* x=0) : imp(x) {}
|
|
|
|
operator bool() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// return pointer to root node
|
|
|
|
PrefixPtr GetRoot() const;
|
|
|
|
// extend pointer with a word/Factorstring and return the resulting successor
|
|
|
|
// pointer. If there is no such successor node, the result will evaluate to
|
|
|
|
// false. Requirement: the input pointer p evaluates to true.
|
|
|
|
PrefixPtr Extend(PrefixPtr p,const std::string& s) const;
|
|
|
|
|
|
|
|
// get the target candidates for a given prefix pointer
|
|
|
|
// requirement: the pointer has to evaluate to true
|
|
|
|
void GetTargetCandidates(PrefixPtr p,
|
|
|
|
std::vector<StringTgtCand>& rv) const;
|
2008-09-12 22:09:06 +04:00
|
|
|
void GetTargetCandidates(PrefixPtr p,
|
|
|
|
std::vector<StringTgtCand>& rv,
|
|
|
|
std::vector<StringWordAlignmentCand>& swa,
|
|
|
|
std::vector<StringWordAlignmentCand>& twa) const;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
// print target candidates for a given prefix pointer to a stream, mainly
|
|
|
|
// for debugging
|
|
|
|
void PrintTargetCandidates(PrefixPtr p,std::ostream& out) const;
|
|
|
|
std::string GetScoreProducerDescription() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /*PHRASEDICTIONARYTREE_H_*/
|