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_Phrase_h
00024 #define moses_Phrase_h
00025
00026 #include <iostream>
00027 #include <vector>
00028 #include <list>
00029 #include <string>
00030 #include "Word.h"
00031 #include "WordsBitmap.h"
00032 #include "TypeDef.h"
00033 #include "Util.h"
00034
00035 #include "util/string_piece.hh"
00036
00037 namespace Moses
00038 {
00039
00040 class Phrase
00041 {
00042 friend std::ostream& operator<<(std::ostream&, const Phrase&);
00043 private:
00044
00045 std::vector<Word> m_words;
00046
00047 public:
00049 static void InitializeMemPool();
00050 static void FinalizeMemPool();
00051
00054 Phrase(size_t reserveSize);
00056 Phrase(const std::vector< const Word* > &mergeWords);
00057
00059 virtual ~Phrase();
00060
00066 void CreateFromString(const std::vector<FactorType> &factorOrder, const StringPiece &phraseString, const StringPiece &factorDelimiter);
00067
00068 void CreateFromStringNewFormat(FactorDirection direction
00069 , const std::vector<FactorType> &factorOrder
00070 , const std::string &phraseString
00071 , const std::string &factorDelimiter
00072 , Word &lhs);
00073
00077 void MergeFactors(const Phrase ©);
00079 void MergeFactors(const Phrase ©, FactorType factorType);
00081 void MergeFactors(const Phrase ©, const std::vector<FactorType>& factorVec);
00082
00086 bool IsCompatible(const Phrase &inputPhrase) const;
00087 bool IsCompatible(const Phrase &inputPhrase, FactorType factorType) const;
00088 bool IsCompatible(const Phrase &inputPhrase, const std::vector<FactorType>& factorVec) const;
00089
00091 inline size_t GetSize() const {
00092 return m_words.size();
00093 }
00094
00096 inline const Word &GetWord(size_t pos) const {
00097 return m_words[pos];
00098 }
00099 inline Word &GetWord(size_t pos) {
00100 return m_words[pos];
00101 }
00103 inline const Factor *GetFactor(size_t pos, FactorType factorType) const {
00104 const Word &ptr = m_words[pos];
00105 return ptr[factorType];
00106 }
00107 inline void SetFactor(size_t pos, FactorType factorType, const Factor *factor) {
00108 Word &ptr = m_words[pos];
00109 ptr[factorType] = factor;
00110 }
00111
00112 size_t GetNumTerminals() const;
00113
00115 bool Contains(const std::vector< std::vector<std::string> > &subPhraseVector
00116 , const std::vector<FactorType> &inputFactor) const;
00117
00119 Word &AddWord();
00121 void AddWord(const Word &newWord) {
00122 AddWord() = newWord;
00123 }
00124
00126 void Append(const Phrase &endPhrase);
00127 void PrependWord(const Word &newWord);
00128
00129 void Clear() {
00130 m_words.clear();
00131 }
00132
00133 void RemoveWord(size_t pos) {
00134 CHECK(pos < m_words.size());
00135 m_words.erase(m_words.begin() + pos);
00136 }
00137
00139 Phrase GetSubString(const WordsRange &wordsRange) const;
00140
00142 std::string GetStringRep(const std::vector<FactorType> factorsToPrint) const;
00143
00144 TO_STRING();
00145
00146
00147 int Compare(const Phrase &other) const;
00148
00152 bool operator< (const Phrase &compare) const {
00153 return Compare(compare) < 0;
00154 }
00155
00156 bool operator== (const Phrase &compare) const {
00157 return Compare(compare) == 0;
00158 }
00159
00160 };
00161
00162
00163 }
00164 #endif