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

ChartTrellisPath.cpp « src « moses-chart - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 567350bc049d01ef6b8f66dfedad1e6adcf00d7c (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "ChartTrellisPath.h"
#include "ChartHypothesis.h"
#include "ChartTrellisPathCollection.h"
#include "../../moses/src/StaticData.h"
#include "../../moses/src/Word.h"

using namespace std;

namespace MosesChart
{

TrellisPath::TrellisPath(const Hypothesis *hypo)
:m_finalNode(new TrellisNode(hypo))
,m_scoreBreakdown(hypo->GetScoreBreakDown())
,m_totalScore(hypo->GetTotalScore())
,m_prevNodeChanged(NULL)
,m_prevPath(NULL)
{
}

TrellisPath::TrellisPath(const TrellisPath &origPath
												, const TrellisNode &soughtNode
												, const Hypothesis &replacementHypo
												, Moses::ScoreComponentCollection	&scoreChange)
:m_scoreBreakdown(origPath.GetScoreBreakdown())
,m_prevPath(&origPath)
{
	m_finalNode = new TrellisNode(origPath.GetFinalNode()
															, soughtNode
															, replacementHypo
															, scoreChange
															, m_prevNodeChanged);

	m_scoreBreakdown.PlusEquals(scoreChange);

	m_totalScore = m_scoreBreakdown.GetWeightedScore();
}

TrellisPath::~TrellisPath()
{
	delete m_finalNode;
}

Moses::Phrase TrellisPath::GetOutputPhrase() const
{
	Moses::Phrase ret = GetFinalNode().GetOutputPhrase();
	return ret;
}

void TrellisPath::CreateDeviantPaths(TrellisPathCollection &pathColl, const TrellisNode &soughtNode) const
{
	// copy this path but replace startHypo with its arc
	const ArcList *arcList = soughtNode.GetHypothesis().GetArcList();

	if (arcList)
	{
		ArcList::const_iterator iterArcList;
		for (iterArcList = arcList->begin(); iterArcList != arcList->end(); ++iterArcList)
		{
			Moses::ScoreComponentCollection	scoreChange;

			const Hypothesis &replacementHypo = **iterArcList;
			TrellisPath *newPath = new TrellisPath(*this, soughtNode, replacementHypo, scoreChange);
			pathColl.Add(newPath);
		}
	}

	// recusively create deviant paths for child nodes
	const TrellisNode::NodeChildren &children = soughtNode.GetChildren();

	TrellisNode::NodeChildren::const_iterator iter;
	for (iter = children.begin(); iter != children.end(); ++iter)
	{
		const TrellisNode &child = **iter;
		CreateDeviantPaths(pathColl, child);
	}
}

void TrellisPath::CreateDeviantPaths(TrellisPathCollection &pathColl) const
{
	if (m_prevNodeChanged == NULL)
	{ // initial enumeration from a pure hypo
		CreateDeviantPaths(pathColl, GetFinalNode());
	}
	else
	{ // don't change m_prevNodeChanged, just it's children
		const TrellisNode::NodeChildren &children = m_prevNodeChanged->GetChildren();

		TrellisNode::NodeChildren::const_iterator iter;
		for (iter = children.begin(); iter != children.end(); ++iter)
		{
			const TrellisNode &child = **iter;
			CreateDeviantPaths(pathColl, child);
		}
	}
}

std::ostream& operator<<(std::ostream &out, const TrellisPath &path)
{
	out << &path << "  " << path.m_prevPath << "  " << path.GetOutputPhrase() << endl;

	if (path.m_prevNodeChanged)
	{
		out << "changed " << path.m_prevNodeChanged->GetHypothesis() << endl;
	}

	out << path.GetFinalNode() << endl;

	return out;
}

};