00001 00002 #pragma once 00003 00004 #include "moses/PP/PhraseProperty.h" 00005 #include "util/exception.hh" 00006 #include <string> 00007 #include <list> 00008 00009 namespace Moses 00010 { 00011 00012 // Note that we require label tokens (strings) in the corresponding property values of phrase table entries 00013 // to be replaced beforehand by indices (size_t) of a label vocabulary. (TODO: change that?) 00014 00015 class SourceLabelsPhrasePropertyItem 00016 { 00017 friend class SourceLabelsPhraseProperty; 00018 00019 public: 00020 SourceLabelsPhrasePropertyItem() {}; 00021 00022 float GetSourceLabelsRHSCount() const { 00023 return m_sourceLabelsRHSCount; 00024 }; 00025 00026 const std::list<size_t> &GetSourceLabelsRHS() const { 00027 return m_sourceLabelsRHS; 00028 }; 00029 00030 const std::list< std::pair<size_t,float> > &GetSourceLabelsLHSList() const { 00031 return m_sourceLabelsLHSList; 00032 }; 00033 00034 private: 00035 float m_sourceLabelsRHSCount; 00036 std::list<size_t> m_sourceLabelsRHS; // should be of size nNTs-1 (empty if initial rule, i.e. no right-hand side non-terminals) 00037 std::list< std::pair<size_t,float> > m_sourceLabelsLHSList; // list of left-hand sides for this right-hand side, with counts 00038 }; 00039 00040 00041 class SourceLabelsPhraseProperty : public PhraseProperty 00042 { 00043 public: 00044 SourceLabelsPhraseProperty() {}; 00045 00046 virtual void ProcessValue(const std::string &value); 00047 00048 size_t GetNumberOfNonTerminals() const { 00049 return m_nNTs; 00050 } 00051 00052 float GetTotalCount() const { 00053 return m_totalCount; 00054 } 00055 00056 const std::list<SourceLabelsPhrasePropertyItem> &GetSourceLabelItems() const { 00057 return m_sourceLabelItems; 00058 }; 00059 00060 virtual const std::string *GetValueString() const { 00061 UTIL_THROW2("SourceLabelsPhraseProperty: value string not available in this phrase property"); 00062 return NULL; 00063 }; 00064 00065 protected: 00066 00067 size_t m_nNTs; 00068 float m_totalCount; 00069 00070 std::list<SourceLabelsPhrasePropertyItem> m_sourceLabelItems; 00071 }; 00072 00073 } // namespace Moses 00074