00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef moses_InputType_h
00024 #define moses_InputType_h
00025
00026 #include <string>
00027 #include "TypeDef.h"
00028 #include "Phrase.h"
00029 #include "TargetPhraseCollection.h"
00030 #include "ReorderingConstraint.h"
00031 #include "NonTerminal.h"
00032 #include "Range.h"
00033 #include "parameters/AllOptions.h"
00034
00035 namespace Moses
00036 {
00037 class Factor;
00038 class PhraseDictionary;
00039 class TranslationOptionCollection;
00040 class ChartTranslationOptions;
00041 class TranslationTask;
00045 class InputType
00046 {
00047 protected:
00048 AllOptions::ptr m_options;
00049 long m_translationId;
00050 long m_documentId;
00051 long m_topicId;
00052 std::string m_weightSetting;
00053 std::vector<std::string> m_topicIdAndProb;
00054 bool m_useTopicId;
00055 bool m_useTopicIdAndProb;
00056 bool m_hasMetaData;
00057 bool m_specifiesWeightSetting;
00058 long m_segId;
00059 ReorderingConstraint m_reorderingConstraint;
00060 std::string m_textType;
00061 std::string m_passthrough;
00062 boost::shared_ptr<std::vector<std::string> > m_context;
00063 public:
00064
00065
00066 std::vector<bool> m_sourceCompleted;
00067 std::string m_initialTargetPhrase;
00068 size_t m_frontSpanCoveredLength;
00069
00070
00071
00072 SPTR<std::map<size_t const, std::vector<float> > > m_coordMap;
00073
00074 InputType(AllOptions::ptr const& opts, long translationId = 0);
00075 virtual ~InputType();
00076
00077 virtual InputTypeEnum GetType() const = 0;
00078
00079 AllOptions::ptr const& options() const {
00080 return m_options;
00081 }
00082
00083 long GetTranslationId() const {
00084 return m_translationId;
00085 }
00086 void SetTranslationId(long translationId) {
00087 m_translationId = translationId;
00088 }
00089 long GetDocumentId() const {
00090 return m_documentId;
00091 }
00092 void SetDocumentId(long documentId) {
00093 m_documentId = documentId;
00094 }
00095 long GetTopicId() const {
00096 return m_topicId;
00097 }
00098 void SetTopicId(long topicId) {
00099 m_topicId = topicId;
00100 }
00101 const std::vector<std::string>* GetTopicIdAndProb() const {
00102 return &m_topicIdAndProb;
00103 }
00104 void SetTopicIdAndProb(std::vector<std::string> topicIdAndProb) {
00105 m_topicIdAndProb = topicIdAndProb;
00106 }
00107 bool GetUseTopicId() const {
00108 return m_useTopicId;
00109 }
00110 void SetUseTopicId(bool useTopicId) {
00111 m_useTopicId = useTopicId;
00112 }
00113 bool GetUseTopicIdAndProb() const {
00114 return m_useTopicIdAndProb;
00115 }
00116 void SetUseTopicIdAndProb(bool useTopicIdAndProb) {
00117 m_useTopicIdAndProb = useTopicIdAndProb;
00118 }
00119 std::string GetTextType() const {
00120 return m_textType;
00121 }
00122 void SetSpecifiesWeightSetting(bool specifiesWeightSetting) {
00123 m_specifiesWeightSetting = specifiesWeightSetting;
00124 }
00125 bool GetSpecifiesWeightSetting() const {
00126 return m_specifiesWeightSetting;
00127 }
00128 void SetWeightSetting(std::string settingName) {
00129 m_weightSetting = settingName;
00130 }
00131 std::string GetWeightSetting() const {
00132 return m_weightSetting;
00133 }
00134 void SetTextType(std::string type) {
00135 m_textType = type;
00136 }
00137 std::string GetPassthroughInformation() const {
00138 return m_passthrough;
00139 }
00140 void SetPassthroughInformation(std::string &passthrough) {
00141 m_passthrough = passthrough;
00142 }
00144 virtual int ComputeDistortionDistance(const Range& prev, const Range& current) const;
00145
00147 virtual bool CanIGetFromAToB(size_t start, size_t end) const;
00148
00150 inline bool IsCoveragePossible(const Range& range) const {
00151 return CanIGetFromAToB(range.GetStartPos(), range.GetEndPos() + 1);
00152 }
00153
00155 inline bool IsExtensionPossible(const Range& prev, const Range& current) const {
00156
00157 size_t t = prev.GetEndPos()+1;
00158 size_t l = current.GetEndPos()+1;
00159 size_t r = l;
00160 if (l<t) {
00161 r = t;
00162 } else {
00163 l = t;
00164 }
00165 if (!CanIGetFromAToB(l,r)) return false;
00166
00167
00168
00169
00170 r = current.GetStartPos();
00171 l = prev.GetEndPos()+1;
00172 if (l == r) return true;
00173 if (prev.GetEndPos() > current.GetStartPos()) {
00174 r = prev.GetStartPos();
00175 l = current.GetEndPos()+1;
00176 if (r == l) return true;
00177 }
00178 return CanIGetFromAToB(l,r);
00179 }
00180
00182 virtual size_t GetSize() const =0;
00183
00184 virtual boost::shared_ptr<std::vector<std::string> > const&
00185 GetContext() const {
00186 return m_context;
00187 }
00188
00189 virtual void
00190 SetContext(boost::shared_ptr<std::vector<std::string> > const& ctx) {
00191 m_context = ctx;
00192 }
00193
00195 virtual int
00196 Read(std::istream& in) = 0;
00197
00198
00199
00200
00202 virtual void Print(std::ostream&) const =0;
00203
00205 virtual TranslationOptionCollection*
00206 CreateTranslationOptionCollection(ttasksptr const& ttask) const=0;
00207
00209 virtual Phrase GetSubString(const Range&) const =0;
00210
00212 virtual const Word& GetWord(size_t pos) const=0;
00213
00215 const ReorderingConstraint& GetReorderingConstraint() const {
00216 return m_reorderingConstraint;
00217 };
00218
00219 virtual const NonTerminalSet &GetLabelSet(size_t startPos, size_t endPos) const = 0;
00220
00221 virtual std::vector <ChartTranslationOptions*> GetXmlChartTranslationOptions() const;
00222
00223 TO_STRING();
00224
00225 };
00226
00227 std::ostream& operator<<(std::ostream&,InputType const&);
00228
00229 }
00230
00231 #endif