00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021 #ifndef moses_CompletedRuleCollectionS_h
00022 #define moses_CompletedRuleCollectionS_h
00023
00024 #include <vector>
00025 #include <numeric>
00026
00027 #include "moses/StackVec.h"
00028 #include "moses/TargetPhraseCollection.h"
00029 #include "moses/ChartTranslationOptions.h"
00030 #include "moses/ChartCellLabel.h"
00031 #include "moses/ChartParserCallback.h"
00032
00033 namespace Moses
00034 {
00035
00036
00037 struct CompletedRule {
00038 public:
00039
00040 CompletedRule(const TargetPhraseCollection &tpc,
00041 const StackVec &stackVec,
00042 const float score)
00043 : m_stackVec(stackVec)
00044 , m_tpc(tpc)
00045 , m_score(score) {}
00046
00047 const TargetPhraseCollection & GetTPC() const {
00048 return m_tpc;
00049 }
00050
00051 const StackVec & GetStackVector() const {
00052 return m_stackVec;
00053 }
00054
00055 const float GetScoreEstimate() const {
00056 return m_score;
00057 }
00058
00059 private:
00060 const StackVec m_stackVec;
00061 const TargetPhraseCollection &m_tpc;
00062 const float m_score;
00063
00064 };
00065
00066 class CompletedRuleOrdered
00067 {
00068 public:
00069 bool operator()(const CompletedRule* itemA, const CompletedRule* itemB) const {
00070 return itemA->GetScoreEstimate() > itemB->GetScoreEstimate();
00071 }
00072 };
00073
00074 struct CompletedRuleCollection {
00075 public:
00076
00077 CompletedRuleCollection(size_t rule_limit);
00078 ~CompletedRuleCollection();
00079
00080 CompletedRuleCollection(const CompletedRuleCollection &old)
00081 : m_collection(old.m_collection)
00082 , m_scoreThreshold(old.m_scoreThreshold)
00083 , m_ruleLimit(old.m_ruleLimit) {}
00084
00085 CompletedRuleCollection & operator=(const CompletedRuleCollection &old) {
00086
00087 m_collection = old.m_collection;
00088 m_scoreThreshold = old.m_scoreThreshold;
00089 m_ruleLimit = old.m_ruleLimit;
00090 return *this;
00091 }
00092
00093 std::vector<CompletedRule*>::const_iterator begin() const {
00094 return m_collection.begin();
00095 }
00096 std::vector<CompletedRule*>::const_iterator end() const {
00097 return m_collection.end();
00098 }
00099
00100 void Clear() {
00101 RemoveAllInColl(m_collection);
00102 }
00103
00104 void Add(const TargetPhraseCollection &tpc,
00105 const StackVec &stackVec,
00106 const ChartParserCallback &outColl);
00107
00108 void Add(const TargetPhraseCollection &tpc,
00109 const StackVec &stackVec,
00110 const std::vector<float> &stackScores,
00111 const ChartParserCallback &outColl);
00112
00113 private:
00114 std::vector<CompletedRule*> m_collection;
00115 float m_scoreThreshold;
00116 size_t m_ruleLimit;
00117
00118 };
00119
00120 }
00121
00122 #endif