TranslationOption::GetSourcePhrase() return a reference, not a pointer. It must always have the reference

This commit is contained in:
Hieu Hoang 2013-08-05 12:38:17 +01:00
parent dbc545089b
commit 6872689bc2
4 changed files with 9 additions and 11 deletions

View File

@ -110,7 +110,7 @@ void PhrasePairFeature::Evaluate(
ScoreComponentCollection* accumulator) const
{
const TargetPhrase& target = context.GetTargetPhrase();
const Phrase& source = *(context.GetTranslationOption().GetSourcePhrase());
const Phrase& source = context.GetTranslationOption().GetSourcePhrase();
if (m_simple) {
ostringstream namestr;
namestr << "pp_";

View File

@ -80,7 +80,7 @@ Hypothesis::Hypothesis(Manager& manager, InputType const& source, const TargetPh
Hypothesis::Hypothesis(const Hypothesis &prevHypo, const TranslationOption &transOpt)
: m_prevHypo(&prevHypo)
, m_targetPhrase(transOpt.GetTargetPhrase())
, m_sourcePhrase(transOpt.GetSourcePhrase())
, m_sourcePhrase(&transOpt.GetSourcePhrase())
, m_sourceCompleted (prevHypo.m_sourceCompleted )
, m_sourceInput (prevHypo.m_sourceInput)
, m_currSourceWordsRange (transOpt.GetSourceWordsRange())

View File

@ -95,8 +95,8 @@ public:
}
/** returns source phrase */
const Phrase *GetSourcePhrase() const {
return &(m_targetPhrase.GetSourcePhrase());
const Phrase &GetSourcePhrase() const {
return m_targetPhrase.GetSourcePhrase();
}
/** whether source span overlaps with those of a hypothesis */

View File

@ -655,13 +655,11 @@ void TranslationOptionCollection::CacheLexReordering()
for(iterTransOpt = transOptList.begin() ; iterTransOpt != transOptList.end() ; ++iterTransOpt) {
TranslationOption &transOpt = **iterTransOpt;
//Phrase sourcePhrase = m_source.GetSubString(WordsRange(startPos,endPos));
const Phrase *sourcePhrase = transOpt.GetSourcePhrase();
if (sourcePhrase) {
Scores score = lexreordering.GetProb(*sourcePhrase
, transOpt.GetTargetPhrase());
if (!score.empty())
transOpt.CacheLexReorderingScores(lexreordering, score);
} // if (sourcePhrase) {
const Phrase &sourcePhrase = transOpt.GetSourcePhrase();
Scores score = lexreordering.GetProb(sourcePhrase
, transOpt.GetTargetPhrase());
if (!score.empty())
transOpt.CacheLexReorderingScores(lexreordering, score);
} // for(iterTransOpt
} // for (size_t endPos = startPos ; endPos < startPos + maxSize; endPos++) {
} // for (size_t startPos = 0 ; startPos < size ; startPos++) {