Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DistortionOrientation.cpp « src « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a1ffff05db0ec6bde8de856a259d8a59a4f1aee1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// $Id$

#include <iostream>
#include <limits>
#include <assert.h>
#include "DistortionOrientation.h"
#include "TypeDef.h"
#include "Hypothesis.h"
/*
 * Load the file pointed to by filename; set up the table according to
 * the orientation and condition parameters. Direction will be used
 * later for computing the score.
 * 
 * default type is Msd, meaning will distinguish between monotone, swap, discontinuous rather than
 * just monotone/non monotone.
 */
int DistortionOrientation::GetOrientation(const Hypothesis *curr_hypothesis, int direction, int type) 
{
	size_t numSourceWords = curr_hypothesis->GetWordsBitmap().GetSize();
	const WordsRange &currTargetRange = curr_hypothesis->GetPrevHypo()->GetCurrSourceWordsRange()
			   , &prevSourceRange = curr_hypothesis->GetCurrSourceWordsRange()
			   , &currSourceRange = curr_hypothesis->GetCurrTargetWordsRange();

	size_t prev_source_start = prevSourceRange.GetStartPos();
	size_t prev_source_end = prevSourceRange.GetEndPos();
	size_t curr_source_start = currSourceRange.GetStartPos();
	size_t curr_source_end = currSourceRange.GetEndPos();
	size_t curr_target_start = currTargetRange.GetStartPos();
	size_t curr_target_end = currTargetRange.GetEndPos();

	if(direction==LexReorderType::Backward)
	{
		if(curr_target_start==0 || curr_target_end==numSourceWords || prev_source_end==curr_source_start)
		{
			//the first two conditionals are edge cases which judge first and last phrases as monotonic
			return DistortionOrientationType::MONO;
		}
		else if(type==DistortionOrientationType::Msd) //distinguish between monotone, swap, discontinuous
		{
			if(prev_source_start==curr_source_end)
				return DistortionOrientationType::SWAP;
			else
				return DistortionOrientationType::DISC;
		}
		else //only distinguish between Monotone, non monotone
		{
			return DistortionOrientationType::NON_MONO;
		}
		
	}
	else //assume direction is forward, do same computation but on PREVIOUS hypothesis
	{
		return DistortionOrientation::GetOrientation(curr_hypothesis->GetPrevHypo()
													 ,LexReorderType::Forward
													 ,type);
	}
}