Merge branch 'master' of github.com:moses-smt/mosesdecoder

This commit is contained in:
Hieu Hoang 2014-06-13 17:06:58 +01:00
commit 6cffb39bd6
12 changed files with 35 additions and 28 deletions

View File

@ -189,8 +189,7 @@ int PhraseBasedReorderingState::Compare(const FFState& o) const
if (&o == this)
return 0;
const PhraseBasedReorderingState* other = dynamic_cast<const PhraseBasedReorderingState*>(&o);
UTIL_THROW_IF2(other == NULL, "Wrong state type");
const PhraseBasedReorderingState* other = static_cast<const PhraseBasedReorderingState*>(&o);
if (m_prevRange == other->m_prevRange) {
if (m_direction == LexicalReorderingConfiguration::Forward) {
return ComparePrevScores(other->m_prevScore);

View File

@ -4,7 +4,6 @@
#include "moses/Hypothesis.h"
#include "moses/ChartHypothesis.h"
#include "moses/TargetPhrase.h"
#include <boost/shared_ptr.hpp>
#include <vector>
#include "moses/PP/TreeStructurePhraseProperty.h"
@ -272,8 +271,8 @@ FFState* TreeStructureFeature::EvaluateChart(const ChartHypothesis& cur_hypo
, ScoreComponentCollection* accumulator) const
{
if (const PhraseProperty *property = cur_hypo.GetCurrTargetPhrase().GetProperty("Tree")) {
const std::string &tree = property->GetValueString();
TreePointer mytree (new InternalTree(tree));
const std::string *tree = property->GetValueString();
TreePointer mytree (new InternalTree(*tree));
if (m_labelset) {
AddNTLabels(mytree);

View File

@ -1,14 +1,13 @@
#include "moses/PP/CountsPhraseProperty.h"
#include <sstream>
#include <assert.h>
#include "util/exception.hh"
namespace Moses
{
void CountsPhraseProperty::ProcessValue()
void CountsPhraseProperty::ProcessValue(const std::string &value)
{
std::istringstream tokenizer(m_value);
std::istringstream tokenizer(value);
if (! (tokenizer >> m_targetMarginal)) { // first token: countE
UTIL_THROW2("CountsPhraseProperty: Not able to read target marginal. Flawed property?");
@ -24,7 +23,6 @@ void CountsPhraseProperty::ProcessValue()
UTIL_THROW2("CountsPhraseProperty: Not able to read joint count. Flawed property?");
}
assert( m_jointCount > 0 );
};
} // namespace Moses

View File

@ -2,6 +2,7 @@
#pragma once
#include "moses/PP/PhraseProperty.h"
#include "util/exception.hh"
#include <string>
#include <list>
@ -28,9 +29,9 @@ class CountsPhraseProperty : public PhraseProperty
{
public:
CountsPhraseProperty(const std::string &value) : PhraseProperty(value) {};
CountsPhraseProperty() {};
virtual void ProcessValue();
virtual void ProcessValue(const std::string &value);
size_t GetSourceMarginal() const {
return m_sourceMarginal;
@ -44,6 +45,11 @@ public:
return m_jointCount;
}
virtual const std::string *GetValueString() const {
UTIL_THROW2("CountsPhraseProperty: value string not available in this phrase property");
return NULL;
};
protected:
float m_sourceMarginal, m_targetMarginal, m_jointCount;

View File

@ -36,8 +36,8 @@ template <class P> class DefaultPhrasePropertyCreator : public PhrasePropertyCre
{
public:
boost::shared_ptr<PhraseProperty> CreateProperty(const std::string &value) {
P* property = new P(value);
property->ProcessValue();
P* property = new P();
property->ProcessValue(value);
return Create(property);
}
};
@ -54,7 +54,7 @@ PhrasePropertyFactory::PhrasePropertyFactory()
MOSES_PNAME2("Counts", CountsPhraseProperty);
MOSES_PNAME2("SourceLabels", SourceLabelsPhraseProperty);
MOSES_PNAME2("Tree",TreeStructurePhraseProperty);
MOSES_PNAME2("Tree", TreeStructurePhraseProperty);
}

View File

@ -11,15 +11,15 @@ namespace Moses
class PhraseProperty
{
public:
PhraseProperty(const std::string &value) : m_value(value) {};
PhraseProperty() {};
virtual void ProcessValue() {};
virtual void ProcessValue(const std::string &value) { m_value = new std::string(value); };
const std::string &GetValueString() const { return m_value; };
virtual const std::string *GetValueString() const { return m_value; };
protected:
const std::string m_value;
std::string *m_value;
};

View File

@ -7,14 +7,13 @@
#include <queue>
#include <assert.h>
#include <limits>
#include "util/exception.hh"
namespace Moses
{
void SourceLabelsPhraseProperty::ProcessValue()
void SourceLabelsPhraseProperty::ProcessValue(const std::string &value)
{
std::istringstream tokenizer(m_value);
std::istringstream tokenizer(value);
if (! (tokenizer >> m_nNTs)) { // first token: number of non-terminals (incl. left-hand side)
UTIL_THROW2("SourceLabelsPhraseProperty: Not able to read number of non-terminals. Flawed property?");

View File

@ -2,6 +2,7 @@
#pragma once
#include "moses/PP/PhraseProperty.h"
#include "util/exception.hh"
#include <string>
#include <list>
@ -43,9 +44,9 @@ private:
class SourceLabelsPhraseProperty : public PhraseProperty
{
public:
SourceLabelsPhraseProperty(const std::string &value) : PhraseProperty(value) {};
SourceLabelsPhraseProperty() {};
virtual void ProcessValue();
virtual void ProcessValue(const std::string &value);
size_t GetNumberOfNonTerminals() const {
return m_nNTs;
@ -59,6 +60,11 @@ public:
return m_sourceLabelItems;
};
virtual const std::string *GetValueString() const {
UTIL_THROW2("SourceLabelsPhraseProperty: value string not available in this phrase property");
return NULL;
};
protected:
size_t m_nNTs;

View File

@ -10,7 +10,7 @@ namespace Moses
class TreeStructurePhraseProperty : public PhraseProperty
{
public:
TreeStructurePhraseProperty(const std::string &value) : PhraseProperty(value) {};
TreeStructurePhraseProperty() {};
};

View File

@ -253,8 +253,8 @@ const PhraseProperty *TargetPhrase::GetProperty(const std::string &key) const
std::map<std::string, boost::shared_ptr<PhraseProperty> >::const_iterator iter;
iter = m_properties.find(key);
if (iter != m_properties.end()) {
const boost::shared_ptr<PhraseProperty> &value = iter->second;
return value.get();
const boost::shared_ptr<PhraseProperty> &pp = iter->second;
return pp.get();
}
return NULL;
}

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
#
# Version of ConfigParser which accepts default values

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
#
# Filter a parallel corpus