|
#pragma once |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <fstream> |
|
#include <vector> |
|
#include <map> |
|
#include "Word.h" |
|
#include "TargetPhraseCollection.h" |
|
#include "Phrase.h" |
|
|
|
namespace OnDiskPt |
|
{ |
|
|
|
class OnDiskWrapper; |
|
class SourcePhrase; |
|
|
|
|
|
class PhraseNode |
|
{ |
|
friend std::ostream& operator<<(std::ostream&, const PhraseNode&); |
|
protected: |
|
uint64_t m_filePos, m_value; |
|
|
|
typedef std::map<Word, PhraseNode> ChildColl; |
|
ChildColl m_children; |
|
PhraseNode *m_currChild; |
|
bool m_saved; |
|
size_t m_pos; |
|
std::vector<float> m_counts; |
|
|
|
TargetPhraseCollection m_targetPhraseColl; |
|
|
|
char *m_memLoad, *m_memLoadLast; |
|
uint64_t m_numChildrenLoad; |
|
|
|
void AddTargetPhrase(size_t pos, const SourcePhrase &sourcePhrase |
|
, TargetPhrase *targetPhrase, OnDiskWrapper &onDiskWrapper |
|
, size_t tableLimit, const std::vector<float> &counts, OnDiskPt::PhrasePtr spShort); |
|
size_t ReadChild(Word &wordFound, uint64_t &childFilePos, const char *mem) const; |
|
void GetChild(Word &wordFound, uint64_t &childFilePos, size_t ind, OnDiskWrapper &onDiskWrapper) const; |
|
|
|
public: |
|
static size_t GetNodeSize(size_t numChildren, size_t wordSize, size_t countSize); |
|
|
|
PhraseNode(); |
|
PhraseNode(uint64_t filePos, OnDiskWrapper &onDiskWrapper); |
|
~PhraseNode(); |
|
|
|
void Add(const Word &word, uint64_t nextFilePos, size_t wordSize); |
|
void Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimit); |
|
|
|
void AddTargetPhrase(const SourcePhrase &sourcePhrase, TargetPhrase *targetPhrase |
|
, OnDiskWrapper &onDiskWrapper, size_t tableLimit |
|
, const std::vector<float> &counts, OnDiskPt::PhrasePtr spShort); |
|
|
|
uint64_t GetFilePos() const { |
|
return m_filePos; |
|
} |
|
uint64_t GetValue() const { |
|
return m_value; |
|
} |
|
void SetValue(uint64_t value) { |
|
m_value = value; |
|
} |
|
size_t GetSize() const { |
|
return m_children.size(); |
|
} |
|
|
|
bool Saved() const { |
|
return m_saved; |
|
} |
|
|
|
void SetPos(size_t pos) { |
|
m_pos = pos; |
|
} |
|
|
|
const PhraseNode *GetChild(const Word &wordSought, OnDiskWrapper &onDiskWrapper) const; |
|
|
|
TargetPhraseCollection::shared_ptr |
|
GetTargetPhraseCollection(size_t tableLimit, |
|
OnDiskWrapper &onDiskWrapper) const; |
|
|
|
void AddCounts(const std::vector<float> &counts) { |
|
m_counts = counts; |
|
} |
|
float GetCount(size_t ind) const; |
|
|
|
}; |
|
|
|
} |
|
|
|
|