directory structure

This commit is contained in:
Hieu Hoang 2015-11-03 13:24:39 +00:00
parent c118849e97
commit 6e5a8ac39c
42 changed files with 76 additions and 264 deletions

View File

@ -1,147 +0,0 @@
/*
* Distortion.cpp
*
* Created on: 28 Oct 2015
* Author: hieu
*/
#include "Distortion.h"
#include "Hypothesis.h"
#include "Manager.h"
#include "moses/Range.h"
#include "moses/Bitmap.h"
using namespace std;
struct DistortionState_traditional : public Moses::FFState {
Moses::Range range;
int first_gap;
DistortionState_traditional(const Moses::Range& wr, int fg) : range(wr), first_gap(fg) {}
size_t hash() const {
return range.GetEndPos();
}
virtual bool operator==(const FFState& other) const {
const DistortionState_traditional& o =
static_cast<const DistortionState_traditional&>(other);
return range.GetEndPos() == o.range.GetEndPos();
}
};
///////////////////////////////////////////////////////////////////////
Distortion::Distortion(size_t startInd, const std::string &line)
:StatefulFeatureFunction(startInd, line)
{
ReadParameters();
}
Distortion::~Distortion() {
// TODO Auto-generated destructor stub
}
const Moses::FFState* Distortion::EmptyHypothesisState(const Manager &mgr, const Phrase &input) const
{
MemPool &pool = mgr.GetPool();
// fake previous translated phrase start and end
size_t start = NOT_FOUND;
size_t end = NOT_FOUND;
/*
if (input.m_frontSpanCoveredLength > 0) {
// can happen with --continue-partial-translation
start = 0;
end = input.m_frontSpanCoveredLength -1;
}
*/
return new (pool.Allocate<DistortionState_traditional>()) DistortionState_traditional(
Moses::Range(start, end),
NOT_FOUND);
}
void
Distortion::EvaluateInIsolation(const System &system,
const PhraseBase &source, const TargetPhrase &targetPhrase,
Scores &scores,
Scores *estimatedScore) const
{
}
Moses::FFState* Distortion::EvaluateWhenApplied(const Manager &mgr,
const Hypothesis &hypo,
const Moses::FFState &prevState,
Scores &scores) const
{
MemPool &pool = mgr.GetPool();
const DistortionState_traditional &prev = static_cast<const DistortionState_traditional&>(prevState);
SCORE distortionScore = CalculateDistortionScore(
prev.range,
hypo.GetRange(),
prev.first_gap);
//cerr << "distortionScore=" << distortionScore << endl;
scores.PlusEquals(mgr.GetSystem(), *this, distortionScore);
DistortionState_traditional* res = new (pool.Allocate<DistortionState_traditional>()) DistortionState_traditional(
hypo.GetRange(),
hypo.GetBitmap().GetFirstGapPos());
return res;
}
SCORE Distortion::CalculateDistortionScore(const Moses::Range &prev, const Moses::Range &curr, const int FirstGap) const
{
bool useEarlyDistortionCost = false;
if(!useEarlyDistortionCost) {
return - (SCORE) ComputeDistortionDistance(prev, curr);
} else {
/* Pay distortion score as soon as possible, from Moore and Quirk MT Summit 2007
Definitions:
S : current source range
S' : last translated source phrase range
S'' : longest fully-translated initial segment
*/
int prefixEndPos = (int)FirstGap-1;
if((int)FirstGap==-1)
prefixEndPos = -1;
// case1: S is adjacent to S'' => return 0
if ((int) curr.GetStartPos() == prefixEndPos+1) {
//IFVERBOSE(4) std::cerr<< "MQ07disto:case1" << std::endl;
return 0;
}
// case2: S is to the left of S' => return 2(length(S))
if ((int) curr.GetEndPos() < (int) prev.GetEndPos()) {
//IFVERBOSE(4) std::cerr<< "MQ07disto:case2" << std::endl;
return (float) -2*(int)curr.GetNumWordsCovered();
}
// case3: S' is a subsequence of S'' => return 2(nbWordBetween(S,S'')+length(S))
if ((int) prev.GetEndPos() <= prefixEndPos) {
//IFVERBOSE(4) std::cerr<< "MQ07disto:case3" << std::endl;
int z = (int)curr.GetStartPos()-prefixEndPos - 1;
return (float) -2*(z + (int)curr.GetNumWordsCovered());
}
// case4: otherwise => return 2(nbWordBetween(S,S')+length(S))
//IFVERBOSE(4) std::cerr<< "MQ07disto:case4" << std::endl;
return (float) -2*((int)curr.GetNumWordsBetween(prev) + (int)curr.GetNumWordsCovered());
}
}
int Distortion::ComputeDistortionDistance(const Moses::Range& prev, const Moses::Range& current) const
{
int dist = 0;
if (prev.GetNumWordsCovered() == 0) {
dist = current.GetStartPos();
} else {
dist = (int)prev.GetEndPos() - (int)current.GetStartPos() + 1 ;
}
return abs(dist);
}

View File

@ -1,42 +0,0 @@
/*
* Distortion.h
*
* Created on: 28 Oct 2015
* Author: hieu
*/
#ifndef DISTORTION_H_
#define DISTORTION_H_
#include "StatefulFeatureFunction.h"
#include "moses/Range.h"
#include "TypeDef.h"
class Distortion : public StatefulFeatureFunction
{
public:
Distortion(size_t startInd, const std::string &line);
virtual ~Distortion();
virtual const Moses::FFState* EmptyHypothesisState(const Manager &mgr, const Phrase &input) const;
virtual void
EvaluateInIsolation(const System &system,
const PhraseBase &source,
const TargetPhrase &targetPhrase,
Scores &scores,
Scores *estimatedScore) const;
virtual Moses::FFState* EvaluateWhenApplied(const Manager &mgr,
const Hypothesis &hypo,
const Moses::FFState &prevState,
Scores &scores) const;
protected:
SCORE CalculateDistortionScore(const Moses::Range &prev, const Moses::Range &curr, const int FirstGap) const;
int ComputeDistortionDistance(const Moses::Range& prev, const Moses::Range& current) const;
};
#endif /* DISTORTION_H_ */

View File

@ -7,7 +7,7 @@
#include <string>
#include <vector>
#include "FeatureFunction.h"
#include "System.h"
#include "../System.h"
#include "moses/Util.h"
using namespace std;

View File

@ -8,17 +8,17 @@
#include <boost/foreach.hpp>
#include "FeatureFunctions.h"
#include "StatefulFeatureFunction.h"
#include "System.h"
#include "../System.h"
#include "../Scores.h"
#include "../MemPool.h"
#include "SkeletonStatelessFF.h"
#include "SkeletonStatefulFF.h"
#include "PhraseTableMemory.h"
#include "UnknownWordPenalty.h"
#include "WordPenalty.h"
#include "Distortion.h"
#include "LanguageModel.h"
#include "Scores.h"
#include "MemPool.h"
#include "TranslationModel/PhraseTableMemory.h"
#include "TranslationModel/UnknownWordPenalty.h"
#include "LM/LanguageModel.h"
using namespace std;

View File

@ -6,9 +6,9 @@
*/
#include <vector>
#include "LanguageModel.h"
#include "System.h"
#include "Manager.h"
#include "Hypothesis.h"
#include "../../System.h"
#include "../../Search/Manager.h"
#include "../../Search/Hypothesis.h"
#include "moses/Util.h"
#include "moses/InputFileStream.h"
#include "moses/LM/PointerState.h"

View File

@ -8,11 +8,11 @@
#ifndef LANGUAGEMODEL_H_
#define LANGUAGEMODEL_H_
#include "StatefulFeatureFunction.h"
#include "TypeDef.h"
#include "../StatefulFeatureFunction.h"
#include "../../TypeDef.h"
#include "moses/Factor.h"
#include "moses/TypeDef.h"
#include "MorphoTrie/MorphTrie.h"
#include "../../MorphoTrie/MorphTrie.h"
////////////////////////////////////////////////////////////////////////////////////////
struct LMScores

View File

@ -6,7 +6,7 @@
*/
#include <boost/foreach.hpp>
#include "PhraseTable.h"
#include "InputPaths.h"
#include "../../InputPaths.h"
using namespace std;

View File

@ -7,9 +7,9 @@
#pragma once
#include <string>
#include <boost/unordered_map.hpp>
#include "TargetPhrases.h"
#include "Word.h"
#include "StatelessFeatureFunction.h"
#include "../../TargetPhrases.h"
#include "../../Word.h"
#include "../StatelessFeatureFunction.h"
#include "moses/Util.h"
class System;

View File

@ -8,11 +8,11 @@
#include <cassert>
#include <boost/foreach.hpp>
#include "PhraseTableMemory.h"
#include "Phrase.h"
#include "TargetPhrase.h"
#include "System.h"
#include "Scores.h"
#include "InputPaths.h"
#include "../../Phrase.h"
#include "../../TargetPhrase.h"
#include "../../System.h"
#include "../../Scores.h"
#include "../../InputPaths.h"
#include "moses/InputFileStream.h"
using namespace std;

View File

@ -6,8 +6,9 @@
*/
#include "UnknownWordPenalty.h"
#include "System.h"
#include "Manager.h"
#include "../../System.h"
#include "../../InputPath.h"
#include "../../Search/Manager.h"
UnknownWordPenalty::UnknownWordPenalty(size_t startInd, const std::string &line)
:PhraseTable(startInd, line)

View File

@ -6,10 +6,9 @@
*/
#include "WordPenalty.h"
#include "TypeDef.h"
#include "Scores.h"
#include "TargetPhrase.h"
#include "Manager.h"
#include "../TypeDef.h"
#include "../Scores.h"
#include "../TargetPhrase.h"
WordPenalty::WordPenalty(size_t startInd, const std::string &line)
:StatelessFeatureFunction(startInd, line)

View File

@ -6,7 +6,7 @@
*/
#include "InputPath.h"
#include "PhraseTable.h"
#include "FF/TranslationModel/PhraseTable.h"
InputPath::InputPath(const SubPhrase &subPhrase, const Moses::Range &range, size_t numPt)
:m_subPhrase(subPhrase)

View File

@ -5,35 +5,36 @@ import option ;
import path ;
exe moses2 :
ArcLists.cpp
Distortion.cpp
FeatureFunction.cpp
FeatureFunctions.cpp
Hypothesis.cpp
InputPath.cpp
InputPaths.cpp
LanguageModel.cpp
Main.cpp
Manager.cpp
MemPool.cpp
Phrase.cpp
PhraseTable.cpp
PhraseTableMemory.cpp
Scores.cpp
SearchNormal.cpp
SkeletonStatefulFF.cpp
SkeletonStatelessFF.cpp
Stack.cpp
StatefulFeatureFunction.cpp
StatelessFeatureFunction.cpp
Scores.cpp
System.cpp
TargetPhrase.cpp
TargetPhrases.cpp
UnknownWordPenalty.cpp
Weights.cpp
Weights.cpp
Word.cpp
WordPenalty.cpp
FF/Distortion.cpp
FF/FeatureFunction.cpp
FF/FeatureFunctions.cpp
FF/SkeletonStatefulFF.cpp
FF/SkeletonStatelessFF.cpp
FF/StatefulFeatureFunction.cpp
FF/StatelessFeatureFunction.cpp
FF/WordPenalty.cpp
FF/LM/LanguageModel.cpp
FF/TranslationModel/PhraseTable.cpp
FF/TranslationModel/PhraseTableMemory.cpp
FF/TranslationModel/UnknownWordPenalty.cpp
Search/ArcLists.cpp
Search/Hypothesis.cpp
Search/Manager.cpp
Search/SearchNormal.cpp
Search/Stack.cpp
../../../moses//moses
../../../OnDiskPt//OnDiskPt
../../..//boost_filesystem

View File

@ -1,7 +1,7 @@
#include <iostream>
#include "System.h"
#include "Manager.h"
#include "Phrase.h"
#include "Search/Manager.h"
#include "moses/InputFileStream.h"
#include "moses/Parameter.h"

View File

@ -9,11 +9,11 @@
#include <cstddef>
#include <stdio.h>
#include "Scores.h"
#include "FeatureFunction.h"
#include "FeatureFunctions.h"
#include "Util.h"
#include "Weights.h"
#include "System.h"
#include "FF/FeatureFunction.h"
#include "FF/FeatureFunctions.h"
#include "moses/Util.h"
using namespace std;

View File

@ -9,9 +9,9 @@
#include <stdlib.h>
#include "Hypothesis.h"
#include "Manager.h"
#include "System.h"
#include "Scores.h"
#include "StatefulFeatureFunction.h"
#include "../System.h"
#include "../Scores.h"
#include "../FF/StatefulFeatureFunction.h"
using namespace std;

View File

@ -12,7 +12,7 @@
#include <cstddef>
#include "moses/FF/FFState.h"
#include "moses/Bitmap.h"
#include "Scores.h"
#include "../Scores.h"
class Manager;
class Phrase;

View File

@ -6,13 +6,13 @@
*/
#include <boost/foreach.hpp>
#include "Manager.h"
#include "PhraseTable.h"
#include "System.h"
#include "SearchNormal.h"
#include "TargetPhrases.h"
#include "TargetPhrase.h"
#include "InputPaths.h"
#include "InputPath.h"
#include "../System.h"
#include "../TargetPhrases.h"
#include "../TargetPhrase.h"
#include "../InputPaths.h"
#include "../InputPath.h"
#include "../FF/TranslationModel/PhraseTable.h"
#include "moses/Range.h"
using namespace std;

View File

@ -10,10 +10,10 @@
#include <cstddef>
#include <string>
#include <vector>
#include "InputPaths.h"
#include "../InputPaths.h"
#include "../TargetPhrase.h"
#include "../MemPool.h"
#include "Stack.h"
#include "TargetPhrase.h"
#include "MemPool.h"
#include "moses/Bitmaps.h"
#include "moses/SquareMatrix.h"

View File

@ -10,9 +10,9 @@
#include "SearchNormal.h"
#include "Stack.h"
#include "Manager.h"
#include "InputPaths.h"
#include "TargetPhrases.h"
#include "TargetPhrase.h"
#include "../InputPaths.h"
#include "../TargetPhrases.h"
#include "../TargetPhrase.h"
using namespace std;

View File

@ -7,7 +7,7 @@
#include "Stack.h"
#include "Hypothesis.h"
#include "Scores.h"
#include "../Scores.h"
Stack::Stack() {
// TODO Auto-generated constructor stub

View File

@ -8,8 +8,8 @@
#include <iostream>
#include <boost/foreach.hpp>
#include "System.h"
#include "FeatureFunction.h"
#include "UnknownWordPenalty.h"
#include "FF/FeatureFunction.h"
#include "FF/TranslationModel/UnknownWordPenalty.h"
#include "moses/Util.h"
#include "util/exception.hh"

View File

@ -7,7 +7,7 @@
#pragma once
#include <vector>
#include "FeatureFunctions.h"
#include "FF/FeatureFunctions.h"
#include "Weights.h"
#include "MemPool.h"
#include "moses/FactorCollection.h"

View File

@ -8,9 +8,9 @@
#include <stdlib.h>
#include "TargetPhrase.h"
#include "Scores.h"
#include "Manager.h"
#include "System.h"
#include "MemPool.h"
#include "Search/Manager.h"
using namespace std;

View File

@ -7,8 +7,8 @@
#include <cassert>
#include <string>
#include <vector>
#include "FeatureFunction.h"
#include "FeatureFunctions.h"
#include "FF/FeatureFunction.h"
#include "FF/FeatureFunctions.h"
#include "Weights.h"
#include "moses/Util.h"