00001 // $Id$ 00002 // vim:tabstop=2 00003 00004 /*********************************************************************** 00005 Moses - factored phrase-based language decoder 00006 Copyright (C) 2006 University of Edinburgh 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 00033 namespace Moses 00034 { 00035 00036 class WordsRange; 00037 class Factor; 00038 class PhraseDictionary; 00039 class TranslationOptionCollection; 00040 class TranslationSystem; 00041 00043 class InputType 00044 { 00045 protected: 00046 long m_translationId; //< contiguous Id 00047 bool m_hasMetaData; 00048 long m_segId; 00049 ReorderingConstraint m_reorderingConstraint; 00051 public: 00052 00053 // used in -continue-partial-translation 00054 std::vector<bool> m_sourceCompleted; 00055 std::string m_initialTargetPhrase; 00056 size_t m_frontSpanCoveredLength; 00057 // how many words from the beginning are covered 00058 00059 InputType(long translationId = 0); 00060 virtual ~InputType(); 00061 00062 virtual InputTypeEnum GetType() const = 0; 00063 00064 long GetTranslationId() const { 00065 return m_translationId; 00066 } 00067 void SetTranslationId(long translationId) { 00068 m_translationId = translationId; 00069 } 00071 virtual int ComputeDistortionDistance(const WordsRange& prev, const WordsRange& current) const; 00072 00074 virtual bool CanIGetFromAToB(size_t start, size_t end) const; 00075 00077 inline bool IsCoveragePossible(const WordsRange& range) const { 00078 return CanIGetFromAToB(range.GetStartPos(), range.GetEndPos() + 1); 00079 } 00080 00082 inline bool IsExtensionPossible(const WordsRange& prev, const WordsRange& current) const { 00083 // return ComputeDistortionDistance(prev, current) < 100000; 00084 size_t t = prev.GetEndPos()+1; // 2 00085 size_t l = current.GetEndPos()+1; //l=1 00086 size_t r = l; 00087 if (l<t) { 00088 r = t; //r=2 00089 } else { 00090 l = t; 00091 } 00092 if (!CanIGetFromAToB(l,r)) return false; 00093 00094 // there's another check here: a current span may end at a place that previous could get to, 00095 // but it may not *START* at a place it can get to. We'll also have to check if we're going left or right 00096 00097 r = current.GetStartPos(); 00098 l = prev.GetEndPos()+1; 00099 if (l == r) return true; 00100 if (prev.GetEndPos() > current.GetStartPos()) { 00101 r = prev.GetStartPos(); 00102 l = current.GetEndPos()+1; 00103 if (r == l) return true; 00104 } 00105 return CanIGetFromAToB(l,r); 00106 } 00107 00109 virtual size_t GetSize() const =0; 00110 00112 virtual int Read(std::istream& in,const std::vector<FactorType>& factorOrder) =0; 00113 00115 virtual void Print(std::ostream&) const =0; 00116 00118 virtual TranslationOptionCollection* CreateTranslationOptionCollection(const TranslationSystem* system) const=0; 00119 00121 virtual Phrase GetSubString(const WordsRange&) const =0; 00122 00124 virtual const Word& GetWord(size_t pos) const=0; 00125 00127 const ReorderingConstraint& GetReorderingConstraint() const { 00128 return m_reorderingConstraint; 00129 }; 00130 00131 virtual const NonTerminalSet &GetLabelSet(size_t startPos, size_t endPos) const = 0; 00132 00133 TO_STRING(); 00134 00135 }; 00136 00137 std::ostream& operator<<(std::ostream&,InputType const&); 00138 00139 } 00140 00141 #endif
1.5.9