mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
span length property
This commit is contained in:
parent
51b8a0aaad
commit
d95bd5bdae
@ -1631,6 +1631,11 @@
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/PP/PhraseProperty.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>PP/SpanLengthPhraseProperty.cpp</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/PP/SpanLengthPhraseProperty.cpp</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>PP/SpanLengthPhraseProperty.h</name>
|
||||
<type>1</type>
|
||||
|
@ -42,6 +42,9 @@ void SpanLength::Evaluate(const InputType &input
|
||||
return;
|
||||
}
|
||||
|
||||
string str = property.get()->GetValueString();
|
||||
cerr << "str=" << str << endl;
|
||||
|
||||
const Phrase *ruleSource = targetPhrase.GetRuleSource();
|
||||
assert(ruleSource);
|
||||
cerr << *ruleSource << endl;
|
||||
|
45
moses/PP/SpanLengthPhraseProperty.cpp
Normal file
45
moses/PP/SpanLengthPhraseProperty.cpp
Normal file
@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user