Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Germann <Ulrich.Germann@gmail.com>2015-10-18 23:27:58 +0300
committerUlrich Germann <Ulrich.Germann@gmail.com>2015-10-18 23:27:58 +0300
commitbdb0227ee9648ea96e8ee266d32581c63762b8b0 (patch)
tree5aff9707a743b3ec5f0e16cba70771b7299516f0 /OnDiskPt
parent7a85126a926c4ffdbd0a956b3b4cec07eea33ed2 (diff)
Life cycle of TargetPhraseCollection is now managed via shared pointers.
Diffstat (limited to 'OnDiskPt')
-rw-r--r--OnDiskPt/PhraseNode.cpp14
-rw-r--r--OnDiskPt/PhraseNode.h5
-rw-r--r--OnDiskPt/TargetPhraseCollection.cpp13
-rw-r--r--OnDiskPt/TargetPhraseCollection.h7
-rw-r--r--OnDiskPt/queryOnDiskPt.cpp2
5 files changed, 22 insertions, 19 deletions
diff --git a/OnDiskPt/PhraseNode.cpp b/OnDiskPt/PhraseNode.cpp
index 8e50147b2..74e01d457 100644
--- a/OnDiskPt/PhraseNode.cpp
+++ b/OnDiskPt/PhraseNode.cpp
@@ -249,16 +249,12 @@ size_t PhraseNode::ReadChild(Word &wordFound, uint64_t &childFilePos, const char
return memRead;
}
-const TargetPhraseCollection *PhraseNode::GetTargetPhraseCollection(size_t tableLimit, OnDiskWrapper &onDiskWrapper) const
+TargetPhraseCollection::shared_ptr
+PhraseNode::
+GetTargetPhraseCollection(size_t tableLimit, OnDiskWrapper &onDiskWrapper) const
{
- TargetPhraseCollection *ret = new TargetPhraseCollection();
-
- if (m_value > 0)
- ret->ReadFromFile(tableLimit, m_value, onDiskWrapper);
- else {
-
- }
-
+ TargetPhraseCollection::shared_ptr ret(new TargetPhraseCollection);
+ if (m_value > 0) ret->ReadFromFile(tableLimit, m_value, onDiskWrapper);
return ret;
}
diff --git a/OnDiskPt/PhraseNode.h b/OnDiskPt/PhraseNode.h
index 901852952..39b9b3f21 100644
--- a/OnDiskPt/PhraseNode.h
+++ b/OnDiskPt/PhraseNode.h
@@ -92,8 +92,11 @@ public:
}
const PhraseNode *GetChild(const Word &wordSought, OnDiskWrapper &onDiskWrapper) const;
- const TargetPhraseCollection *GetTargetPhraseCollection(size_t tableLimit, OnDiskWrapper &onDiskWrapper) const;
+ TargetPhraseCollection::shared_ptr
+ GetTargetPhraseCollection(size_t tableLimit,
+ OnDiskWrapper &onDiskWrapper) const;
+
void AddCounts(const std::vector<float> &counts) {
m_counts = counts;
}
diff --git a/OnDiskPt/TargetPhraseCollection.cpp b/OnDiskPt/TargetPhraseCollection.cpp
index 73ad2540c..a22c3633b 100644
--- a/OnDiskPt/TargetPhraseCollection.cpp
+++ b/OnDiskPt/TargetPhraseCollection.cpp
@@ -114,23 +114,22 @@ void TargetPhraseCollection::Save(OnDiskWrapper &onDiskWrapper)
}
-Moses::TargetPhraseCollection *TargetPhraseCollection::ConvertToMoses(const std::vector<Moses::FactorType> &inputFactors
+Moses::TargetPhraseCollection::shared_ptr TargetPhraseCollection::ConvertToMoses(const std::vector<Moses::FactorType> &inputFactors
, const std::vector<Moses::FactorType> &outputFactors
, const Moses::PhraseDictionary &phraseDict
, const std::vector<float> &weightT
, Vocab &vocab
, bool isSyntax) const
{
- Moses::TargetPhraseCollection *ret = new Moses::TargetPhraseCollection();
+ Moses::TargetPhraseCollection::shared_ptr ret;
+ ret.reset(new Moses::TargetPhraseCollection);
CollType::const_iterator iter;
for (iter = m_coll.begin(); iter != m_coll.end(); ++iter) {
const TargetPhrase &tp = **iter;
- Moses::TargetPhrase *mosesPhrase = tp.ConvertToMoses(inputFactors, outputFactors
- , vocab
- , phraseDict
- , weightT
- , isSyntax);
+ Moses::TargetPhrase *mosesPhrase
+ = tp.ConvertToMoses(inputFactors, outputFactors, vocab,
+ phraseDict, weightT, isSyntax);
/*
// debugging output
diff --git a/OnDiskPt/TargetPhraseCollection.h b/OnDiskPt/TargetPhraseCollection.h
index 227a0ffc2..255c94054 100644
--- a/OnDiskPt/TargetPhraseCollection.h
+++ b/OnDiskPt/TargetPhraseCollection.h
@@ -21,6 +21,8 @@
#include "TargetPhrase.h"
#include "Vocab.h"
+#include "moses/TargetPhraseCollection.h"
+#include <boost/shared_ptr.hpp>
namespace Moses
{
@@ -50,6 +52,9 @@ protected:
std::string m_debugStr;
public:
+ typedef boost::shared_ptr<TargetPhraseCollection const> shared_const_ptr;
+ typedef boost::shared_ptr<TargetPhraseCollection> shared_ptr;
+
static size_t s_sortScoreInd;
TargetPhraseCollection();
@@ -69,7 +74,7 @@ public:
uint64_t GetFilePos() const;
- Moses::TargetPhraseCollection *ConvertToMoses(const std::vector<Moses::FactorType> &inputFactors
+ Moses::TargetPhraseCollection::shared_ptr ConvertToMoses(const std::vector<Moses::FactorType> &inputFactors
, const std::vector<Moses::FactorType> &outputFactors
, const Moses::PhraseDictionary &phraseDict
, const std::vector<float> &weightT
diff --git a/OnDiskPt/queryOnDiskPt.cpp b/OnDiskPt/queryOnDiskPt.cpp
index 77576d956..1eeb65d9a 100644
--- a/OnDiskPt/queryOnDiskPt.cpp
+++ b/OnDiskPt/queryOnDiskPt.cpp
@@ -56,7 +56,7 @@ int main(int argc, char **argv)
if (node) {
// source phrase points to a bunch of rules
- const TargetPhraseCollection *coll = node->GetTargetPhraseCollection(tableLimit, onDiskWrapper);
+ TargetPhraseCollection::shared_ptr coll = node->GetTargetPhraseCollection(tableLimit, onDiskWrapper);
string str = coll->GetDebugStr();
cout << "Found " << coll->GetSize() << endl;