mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-19 15:17:10 +03:00
Made LRModel::ReorderingType an enumerated type.
This commit is contained in:
parent
085c88cc7b
commit
dcffbb5f4d
@ -14,6 +14,7 @@
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
bool
|
||||
IsMonotonicStep(WordsRange const& prev, // words range of last source phrase
|
||||
WordsRange const& cur, // words range of current source phrase
|
||||
@ -340,8 +341,8 @@ Expand(const TranslationOption& topt, const InputType& input,
|
||||
if ((m_direction != LRModel::Forward && m_useFirstBackwardScore) || !m_first) {
|
||||
LRModel const& lrmodel = m_configuration;
|
||||
WordsRange const cur = topt.GetSourceWordsRange();
|
||||
ReorderingType reoType = (m_first ? lrmodel.GetOrientation(cur)
|
||||
: lrmodel.GetOrientation(m_prevRange,cur));
|
||||
LRModel::ReorderingType reoType = (m_first ? lrmodel.GetOrientation(cur)
|
||||
: lrmodel.GetOrientation(m_prevRange,cur));
|
||||
CopyScores(scores, topt, input, reoType);
|
||||
}
|
||||
return new PhraseBasedReorderingState(this, topt);
|
||||
|
@ -25,7 +25,6 @@ class SparseReordering;
|
||||
class LRModel
|
||||
{
|
||||
public:
|
||||
typedef int ReorderingType;
|
||||
friend class LexicalReordering;
|
||||
enum ModelType { Monotonic, MSD, MSLR, LeftRight, None };
|
||||
enum Direction { Forward, Backward, Bidirectional };
|
||||
@ -33,6 +32,8 @@ public:
|
||||
|
||||
// constants for the different types of reordering
|
||||
// (correspond to indices in the respective table)
|
||||
#if 0
|
||||
typedef int ReorderingType;
|
||||
static const ReorderingType M = 0; // monotonic
|
||||
static const ReorderingType NM = 1; // non-monotonic
|
||||
static const ReorderingType S = 1; // swap
|
||||
@ -42,7 +43,21 @@ public:
|
||||
static const ReorderingType R = 0; // right
|
||||
static const ReorderingType L = 1; // left
|
||||
static const ReorderingType MAX = 3; // largest possible
|
||||
|
||||
#else
|
||||
enum ReorderingType
|
||||
{
|
||||
M = 0, // monotonic
|
||||
NM = 1, // non-monotonic
|
||||
S = 1, // swap
|
||||
D = 2, // discontinuous
|
||||
DL = 2, // discontinuous, left
|
||||
DR = 3, // discontinuous, right
|
||||
R = 0, // right
|
||||
L = 1, // left
|
||||
MAX = 3, // largest possible
|
||||
NONE = 4 // largest possible
|
||||
};
|
||||
#endif
|
||||
// determine orientation, depending on model:
|
||||
|
||||
|
||||
@ -129,7 +144,7 @@ class LRState : public FFState
|
||||
{
|
||||
public:
|
||||
|
||||
typedef int ReorderingType;
|
||||
typedef LRModel::ReorderingType ReorderingType;
|
||||
|
||||
virtual
|
||||
int
|
||||
|
@ -101,9 +101,11 @@ void SparseReordering::PreCalculateFeatureNames(size_t index, const string& id,
|
||||
for (size_t position = SparseReorderingFeatureKey::First;
|
||||
position <= SparseReorderingFeatureKey::Last; ++position) {
|
||||
for (int reoType = 0; reoType <= LRModel::MAX; ++reoType) {
|
||||
SparseReorderingFeatureKey key(
|
||||
index, static_cast<SparseReorderingFeatureKey::Type>(type), factor, isCluster,
|
||||
static_cast<SparseReorderingFeatureKey::Position>(position), side, reoType);
|
||||
SparseReorderingFeatureKey
|
||||
key(index, static_cast<SparseReorderingFeatureKey::Type>(type),
|
||||
factor, isCluster,
|
||||
static_cast<SparseReorderingFeatureKey::Position>(position),
|
||||
side, static_cast<LRModel::ReorderingType>(reoType));
|
||||
m_featureMap.insert(pair<SparseReorderingFeatureKey, FName>(key,m_producer->GetFeatureName(key.Name(id))));
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public:
|
||||
void CopyScores(const TranslationOption& currentOpt,
|
||||
const TranslationOption* previousOpt,
|
||||
const InputType& input,
|
||||
LRState::ReorderingType reoType,
|
||||
LRModel::ReorderingType reoType,
|
||||
LRModel::Direction direction,
|
||||
ScoreComponentCollection* scores) const ;
|
||||
|
||||
@ -120,7 +120,7 @@ private:
|
||||
void AddFeatures(
|
||||
SparseReorderingFeatureKey::Type type, SparseReorderingFeatureKey::Side side,
|
||||
const Word& word, SparseReorderingFeatureKey::Position position,
|
||||
LRState::ReorderingType reoType,
|
||||
LRModel::ReorderingType reoType,
|
||||
ScoreComponentCollection* scores) const;
|
||||
|
||||
};
|
||||
|
@ -23,7 +23,7 @@ namespace Moses
|
||||
, sum_pairs (0)
|
||||
, in_progress (0)
|
||||
{
|
||||
for (int i = 0; i <= po_other; ++i)
|
||||
for (int i = 0; i <= Moses::LRModel::NONE; ++i)
|
||||
ofwd[i] = obwd[i] = 0;
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ namespace Moses
|
||||
jstats()
|
||||
: my_rcnt(0), my_wcnt(0), my_cnt2(0)
|
||||
{
|
||||
for (int i = 0; i <= po_other; ++i)
|
||||
for (int i = 0; i <= Moses::LRModel::NONE; ++i)
|
||||
ofwd[i] = obwd[i] = 0;
|
||||
my_aln.reserve(1);
|
||||
}
|
||||
@ -89,7 +89,7 @@ namespace Moses
|
||||
my_rcnt = other.rcnt();
|
||||
my_wcnt = other.wcnt();
|
||||
my_aln = other.aln();
|
||||
for (int i = 0; i <= po_other; i++)
|
||||
for (int i = 0; i <= Moses::LRModel::NONE; i++)
|
||||
{
|
||||
ofwd[i] = other.ofwd[i];
|
||||
obwd[i] = other.obwd[i];
|
||||
@ -100,7 +100,7 @@ namespace Moses
|
||||
jstats::
|
||||
dcnt_fwd(PhraseOrientation const idx) const
|
||||
{
|
||||
assert(idx <= po_other);
|
||||
assert(idx <= Moses::LRModel::NONE);
|
||||
return ofwd[idx];
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ namespace Moses
|
||||
jstats::
|
||||
dcnt_bwd(PhraseOrientation const idx) const
|
||||
{
|
||||
assert(idx <= po_other);
|
||||
assert(idx <= Moses::LRModel::NONE);
|
||||
return obwd[idx];
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ namespace Moses {
|
||||
float my_wcnt; // weighted count
|
||||
uint32_t my_cnt2;
|
||||
vector<pair<size_t, vector<uchar> > > my_aln;
|
||||
uint32_t ofwd[po_other+1], obwd[po_other+1];
|
||||
uint32_t ofwd[Moses::LRModel::NONE+1], obwd[Moses::LRModel::NONE+1];
|
||||
public:
|
||||
jstats();
|
||||
jstats(jstats const& other);
|
||||
@ -132,7 +132,7 @@ namespace Moses {
|
||||
size_t in_progress; // keeps track of how many threads are currently working on this
|
||||
|
||||
// size_t Moses::LRModel::ReorderingType
|
||||
uint32_t ofwd[po_other+1], obwd[po_other+1];
|
||||
uint32_t ofwd[Moses::LRModel::NONE+1], obwd[Moses::LRModel::NONE+1];
|
||||
|
||||
// typedef typename boost::unordered_map<typename ::uint64_t, jstats> trg_map_t;
|
||||
typedef std::map<typename ::uint64_t, jstats> trg_map_t;
|
||||
@ -180,8 +180,8 @@ namespace Moses {
|
||||
::uint64_t p1, p2;
|
||||
uint32_t raw1,raw2,sample1,sample2,good1,good2,joint;
|
||||
vector<float> fvals;
|
||||
float dfwd[po_other+1]; // distortion counts // counts or probs?
|
||||
float dbwd[po_other+1]; // distortion counts
|
||||
float dfwd[Moses::LRModel::NONE+1]; // distortion counts // counts or probs?
|
||||
float dbwd[Moses::LRModel::NONE+1]; // distortion counts
|
||||
vector<uchar> aln;
|
||||
float score;
|
||||
bool inverse;
|
||||
@ -266,7 +266,7 @@ namespace Moses {
|
||||
if (js.aln().size())
|
||||
aln = js.aln()[0].second;
|
||||
float total_fwd = 0, total_bwd = 0;
|
||||
for (int i = 0; i <= po_other; i++)
|
||||
for (int i = 0; i <= Moses::LRModel::NONE; i++)
|
||||
{
|
||||
PhraseOrientation po = static_cast<PhraseOrientation>(i);
|
||||
total_fwd += js.dcnt_fwd(po)+1;
|
||||
@ -274,7 +274,7 @@ namespace Moses {
|
||||
}
|
||||
|
||||
// should we do that here or leave the raw counts?
|
||||
for (int i = 0; i <= po_other; i++)
|
||||
for (int i = 0; i <= Moses::LRModel::NONE; i++)
|
||||
{
|
||||
PhraseOrientation po = static_cast<PhraseOrientation>(i);
|
||||
dfwd[i] = float(js.dcnt_fwd(po)+1)/total_fwd;
|
||||
@ -344,7 +344,7 @@ namespace Moses {
|
||||
, score(o.score)
|
||||
, inverse(o.inverse)
|
||||
{
|
||||
for (int i = 0; i <= po_other; ++i)
|
||||
for (int i = 0; i <= Moses::LRModel::NONE; ++i)
|
||||
{
|
||||
dfwd[i] = o.dfwd[i];
|
||||
dbwd[i] = o.dbwd[i];
|
||||
@ -846,7 +846,7 @@ namespace Moses {
|
||||
while (j->step(sid,offset))
|
||||
{
|
||||
aln.clear();
|
||||
int po_fwd=po_other,po_bwd=po_other;
|
||||
int po_fwd=Moses::LRModel::NONE,po_bwd=Moses::LRModel::NONE;
|
||||
if (j->fwd)
|
||||
{
|
||||
if (!ag.bt.find_trg_phr_bounds
|
||||
|
@ -5,6 +5,7 @@ namespace Moses
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
Moses::LRModel::ReorderingType po_other = Moses::LRModel::NONE;
|
||||
// check if min and max in the aligmnet vector v are within the
|
||||
// bounds LFT and RGT and update the actual bounds L and R; update
|
||||
// the total count of alignment links in the underlying phrase
|
||||
@ -100,12 +101,12 @@ namespace Moses
|
||||
return Moses::LRModel::S;
|
||||
while (e2 < a2.size() && a2[e2].size() == 0) ++e2;
|
||||
if (e2 == a2.size()) // should never happen, actually
|
||||
return po_other;
|
||||
return Moses::LRModel::NONE;
|
||||
if (a2[e2].back() < s1)
|
||||
return Moses::LRModel::DL;
|
||||
if (a2[e2].front() >= e1)
|
||||
return Moses::LRModel::DR;
|
||||
return po_other;
|
||||
return Moses::LRModel::NONE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
namespace Moses { namespace bitext {
|
||||
|
||||
typedef Moses::LRModel::ReorderingType PhraseOrientation;
|
||||
static int const po_other = Moses::LRModel::MAX+1;
|
||||
|
||||
PhraseOrientation
|
||||
find_po_fwd(std::vector<std::vector<ushort> >& a1,
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "mmsapt.h"
|
||||
// #include "mmsapt.h"
|
||||
// currently broken
|
||||
|
||||
// namespace Moses
|
||||
|
Loading…
Reference in New Issue
Block a user