diff --git a/moses/FF/LexicalReordering/LexicalReorderingState.cpp b/moses/FF/LexicalReordering/LexicalReorderingState.cpp index aa29a4a12..dbfddd3f9 100644 --- a/moses/FF/LexicalReordering/LexicalReorderingState.cpp +++ b/moses/FF/LexicalReordering/LexicalReorderingState.cpp @@ -189,8 +189,7 @@ int PhraseBasedReorderingState::Compare(const FFState& o) const if (&o == this) return 0; - const PhraseBasedReorderingState* other = dynamic_cast(&o); - UTIL_THROW_IF2(other == NULL, "Wrong state type"); + const PhraseBasedReorderingState* other = static_cast(&o); if (m_prevRange == other->m_prevRange) { if (m_direction == LexicalReorderingConfiguration::Forward) { return ComparePrevScores(other->m_prevScore); diff --git a/moses/FF/TreeStructureFeature.cpp b/moses/FF/TreeStructureFeature.cpp index 10578982a..a5446891a 100644 --- a/moses/FF/TreeStructureFeature.cpp +++ b/moses/FF/TreeStructureFeature.cpp @@ -4,7 +4,6 @@ #include "moses/Hypothesis.h" #include "moses/ChartHypothesis.h" #include "moses/TargetPhrase.h" -#include #include #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); diff --git a/moses/PP/CountsPhraseProperty.cpp b/moses/PP/CountsPhraseProperty.cpp index f7af18d5b..def07e5da 100644 --- a/moses/PP/CountsPhraseProperty.cpp +++ b/moses/PP/CountsPhraseProperty.cpp @@ -1,14 +1,13 @@ #include "moses/PP/CountsPhraseProperty.h" #include #include -#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 diff --git a/moses/PP/CountsPhraseProperty.h b/moses/PP/CountsPhraseProperty.h index f633381b6..19382fe29 100644 --- a/moses/PP/CountsPhraseProperty.h +++ b/moses/PP/CountsPhraseProperty.h @@ -2,6 +2,7 @@ #pragma once #include "moses/PP/PhraseProperty.h" +#include "util/exception.hh" #include #include @@ -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; diff --git a/moses/PP/Factory.cpp b/moses/PP/Factory.cpp index 0cc891a82..45bdafe36 100644 --- a/moses/PP/Factory.cpp +++ b/moses/PP/Factory.cpp @@ -36,8 +36,8 @@ template class DefaultPhrasePropertyCreator : public PhrasePropertyCre { public: boost::shared_ptr 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); } diff --git a/moses/PP/PhraseProperty.h b/moses/PP/PhraseProperty.h index a4353e634..36de46033 100644 --- a/moses/PP/PhraseProperty.h +++ b/moses/PP/PhraseProperty.h @@ -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; }; diff --git a/moses/PP/SourceLabelsPhraseProperty.cpp b/moses/PP/SourceLabelsPhraseProperty.cpp index 6f18480c5..bca5c9a30 100644 --- a/moses/PP/SourceLabelsPhraseProperty.cpp +++ b/moses/PP/SourceLabelsPhraseProperty.cpp @@ -7,14 +7,13 @@ #include #include #include -#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?"); diff --git a/moses/PP/SourceLabelsPhraseProperty.h b/moses/PP/SourceLabelsPhraseProperty.h index 049d88f17..39b43ad3e 100644 --- a/moses/PP/SourceLabelsPhraseProperty.h +++ b/moses/PP/SourceLabelsPhraseProperty.h @@ -2,6 +2,7 @@ #pragma once #include "moses/PP/PhraseProperty.h" +#include "util/exception.hh" #include #include @@ -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; diff --git a/moses/PP/TreeStructurePhraseProperty.h b/moses/PP/TreeStructurePhraseProperty.h index f9acc38dd..45124973f 100644 --- a/moses/PP/TreeStructurePhraseProperty.h +++ b/moses/PP/TreeStructurePhraseProperty.h @@ -10,7 +10,7 @@ namespace Moses class TreeStructurePhraseProperty : public PhraseProperty { public: - TreeStructurePhraseProperty(const std::string &value) : PhraseProperty(value) {}; + TreeStructurePhraseProperty() {}; }; diff --git a/moses/TargetPhrase.cpp b/moses/TargetPhrase.cpp index ede16293c..c09ff2409 100644 --- a/moses/TargetPhrase.cpp +++ b/moses/TargetPhrase.cpp @@ -253,8 +253,8 @@ const PhraseProperty *TargetPhrase::GetProperty(const std::string &key) const std::map >::const_iterator iter; iter = m_properties.find(key); if (iter != m_properties.end()) { - const boost::shared_ptr &value = iter->second; - return value.get(); + const boost::shared_ptr &pp = iter->second; + return pp.get(); } return NULL; } diff --git a/scripts/ems/support/defaultconfig.py b/scripts/ems/support/defaultconfig.py index 5d5187c47..e88b63e3d 100644 --- a/scripts/ems/support/defaultconfig.py +++ b/scripts/ems/support/defaultconfig.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # # Version of ConfigParser which accepts default values diff --git a/scripts/ems/support/mml-filter.py b/scripts/ems/support/mml-filter.py index 437c9dade..5fb43d71e 100755 --- a/scripts/ems/support/mml-filter.py +++ b/scripts/ems/support/mml-filter.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # # Filter a parallel corpus