diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2014-06-05 23:57:00 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2014-06-05 23:57:00 +0400 |
commit | d95bd5bdaed04d4a7cb554d3786208273172e56a (patch) | |
tree | f1322d9f86b0ee237ec6312c4486f51e48d1cbb4 /moses/PP | |
parent | 51b8a0aaad171ee1a34ad24ac0d65f0b2160772f (diff) |
span length property
Diffstat (limited to 'moses/PP')
-rw-r--r-- | moses/PP/SpanLengthPhraseProperty.cpp | 45 | ||||
-rw-r--r-- | moses/PP/SpanLengthPhraseProperty.h | 14 |
2 files changed, 57 insertions, 2 deletions
diff --git a/moses/PP/SpanLengthPhraseProperty.cpp b/moses/PP/SpanLengthPhraseProperty.cpp new file mode 100644 index 000000000..273637170 --- /dev/null +++ b/moses/PP/SpanLengthPhraseProperty.cpp @@ -0,0 +1,45 @@ +#include <vector> +#include "SpanLengthPhraseProperty.h" +#include "moses/Util.h" +#include "util/exception.hh" + +using namespace std; + +namespace Moses +{ +SpanLengthPhraseProperty::SpanLengthPhraseProperty(const std::string &value) +: PhraseProperty(value) +{ + vector<string> toks; + Tokenize(toks, value); + + for (size_t i = 0; i < toks.size(); i = i + 2) { + const string &span = toks[i]; + float count = Scan<float>(toks[i + 1]); + Populate(span, count); + } +} + +void SpanLengthPhraseProperty::Populate(const string &span, float count) +{ + vector<size_t> toks; + Tokenize<size_t>(toks, span, ","); + UTIL_THROW_IF2(toks.size() != 3, "Incorrect format for SpanLength: " << span); + Populate(toks, count); +} + +void SpanLengthPhraseProperty::Populate(const std::vector<size_t> &toks, float count) +{ + size_t ntInd = toks[0]; + size_t sourceLength = toks[1]; + size_t targetLength = toks[2]; + if (ntInd >= m_source.size() ) { + m_source.resize(ntInd + 1); + m_target.resize(ntInd + 1); + } + m_source[ntInd][sourceLength] = count; + m_target[ntInd][targetLength] = count; + +} + +} diff --git a/moses/PP/SpanLengthPhraseProperty.h b/moses/PP/SpanLengthPhraseProperty.h index e25d70515..94e7ab391 100644 --- a/moses/PP/SpanLengthPhraseProperty.h +++ b/moses/PP/SpanLengthPhraseProperty.h @@ -1,8 +1,10 @@ #pragma once -#include "moses/PP/PhraseProperty.h" #include <string> +#include <map> +#include <vector> +#include "moses/PP/PhraseProperty.h" namespace Moses { @@ -10,8 +12,16 @@ namespace Moses class SpanLengthPhraseProperty : public PhraseProperty { public: - SpanLengthPhraseProperty(const std::string &value) : PhraseProperty(value) {}; + SpanLengthPhraseProperty(const std::string &value); + +protected: + // fractional counts + typedef std::map<size_t, float> Map; + typedef std::vector<Map> Vec; + Vec m_source, m_target; + void Populate(const std::string &span, float count); + void Populate(const std::vector<size_t> &toks, float count); }; } // namespace Moses |