diff options
author | Hieu Hoang <fishandfrolick@gmail.com> | 2012-05-15 19:35:00 +0400 |
---|---|---|
committer | Hieu Hoang <fishandfrolick@gmail.com> | 2012-05-15 19:35:00 +0400 |
commit | 3f3401f9bac7dfab9f88ea1bf2f61199eb739aa2 (patch) | |
tree | b4f1659f8e5aa74422707a7b74a35be93b32394f /OnDiskPt | |
parent | 12278a9f981570072ca1c26a39f2eaf977a5d8e7 (diff) |
Add util for querying on-disk pt
Diffstat (limited to 'OnDiskPt')
-rw-r--r-- | OnDiskPt/Phrase.h | 2 | ||||
-rw-r--r-- | OnDiskPt/TargetPhrase.cpp | 17 | ||||
-rw-r--r-- | OnDiskPt/TargetPhrase.h | 2 | ||||
-rw-r--r-- | OnDiskPt/Vocab.h | 7 | ||||
-rw-r--r-- | OnDiskPt/Word.cpp | 9 | ||||
-rw-r--r-- | OnDiskPt/Word.h | 2 |
6 files changed, 31 insertions, 8 deletions
diff --git a/OnDiskPt/Phrase.h b/OnDiskPt/Phrase.h index dae4f7a39..f7de9a10d 100644 --- a/OnDiskPt/Phrase.h +++ b/OnDiskPt/Phrase.h @@ -49,7 +49,7 @@ public: return m_words.size(); } - void DebugPrint(std::ostream &out, const Vocab &vocab) const; + virtual void DebugPrint(std::ostream &out, const Vocab &vocab) const; int Compare(const Phrase &compare) const; bool operator<(const Phrase &compare) const; diff --git a/OnDiskPt/TargetPhrase.cpp b/OnDiskPt/TargetPhrase.cpp index f1359f2bf..b4ac16a2b 100644 --- a/OnDiskPt/TargetPhrase.cpp +++ b/OnDiskPt/TargetPhrase.cpp @@ -305,6 +305,23 @@ UINT64 TargetPhrase::ReadScoresFromFile(std::fstream &fileTPColl) return bytesRead; } +void TargetPhrase::DebugPrint(ostream &out, const Vocab &vocab) const +{ + Phrase::DebugPrint(out, vocab); + + for (size_t ind = 0; ind < m_align.size(); ++ind) { + const AlignPair &alignPair = m_align[ind]; + out << alignPair.first << "-" << alignPair.second << " "; + } + out << ", "; + + for (size_t ind = 0; ind < m_scores.size(); ++ind) { + out << m_scores[ind] << " "; + } + + return; +} + std::ostream& operator<<(std::ostream &out, const TargetPhrase &phrase) { out << (const Phrase&) phrase << ", " ; diff --git a/OnDiskPt/TargetPhrase.h b/OnDiskPt/TargetPhrase.h index ea82e1f11..589fbb743 100644 --- a/OnDiskPt/TargetPhrase.h +++ b/OnDiskPt/TargetPhrase.h @@ -93,7 +93,7 @@ public: UINT64 ReadOtherInfoFromFile(UINT64 filePos, std::fstream &fileTPColl); UINT64 ReadFromFile(std::fstream &fileTP, size_t numFactors); - void DebugPrint(std::ostream &out, const Vocab &vocab) const; + virtual void DebugPrint(std::ostream &out, const Vocab &vocab) const; }; diff --git a/OnDiskPt/Vocab.h b/OnDiskPt/Vocab.h index 360aedf4a..f8c1dd649 100644 --- a/OnDiskPt/Vocab.h +++ b/OnDiskPt/Vocab.h @@ -41,10 +41,6 @@ protected: std::vector<std::string> m_lookup; // opposite of m_vocabColl UINT64 m_nextId; // starts @ 1 - const std::string &GetString(UINT32 vocabId) const { - return m_lookup[vocabId]; - } - public: Vocab() :m_nextId(1) @@ -52,6 +48,9 @@ public: UINT64 AddVocabId(const std::string &factorString); UINT64 GetVocabId(const std::string &factorString, bool &found) const; const Moses::Factor *GetFactor(UINT32 vocabId, Moses::FactorType factorType, Moses::FactorDirection direction, bool isNonTerminal) const; + const std::string &GetString(UINT32 vocabId) const { + return m_lookup[vocabId]; + } bool Load(OnDiskWrapper &onDiskWrapper); void Save(OnDiskWrapper &onDiskWrapper); diff --git a/OnDiskPt/Word.cpp b/OnDiskPt/Word.cpp index 75aebe940..68db69be0 100644 --- a/OnDiskPt/Word.cpp +++ b/OnDiskPt/Word.cpp @@ -152,9 +152,16 @@ void Word::DebugPrint(ostream &out, const Vocab &vocab) const std::vector<UINT64>::const_iterator iter; for (size_t ind = 0; ind < m_factors.size() - 1; ++ind) { - out << *iter << "|"; + UINT64 vocabId = *iter; + const string &str = vocab.GetString(vocabId); + out << str << "|"; } + // last + UINT64 vocabId = m_factors.back(); + const string &str = vocab.GetString(vocabId); + out << str; + if (m_isNonTerminal) out << "]"; } diff --git a/OnDiskPt/Word.h b/OnDiskPt/Word.h index 1cc1204f6..dc7a2424d 100644 --- a/OnDiskPt/Word.h +++ b/OnDiskPt/Word.h @@ -71,7 +71,7 @@ public: , const std::vector<Moses::FactorType> &outputFactorsVec , const Vocab &vocab) const; - void DebugPrint(std::ostream &out, const Vocab &vocab) const; + virtual void DebugPrint(std::ostream &out, const Vocab &vocab) const; int Compare(const Word &compare) const; bool operator<(const Word &compare) const; |