00001
00002 #pragma once
00003
00004 #include "moses/PP/PhraseProperty.h"
00005 #include "util/exception.hh"
00006 #include <string>
00007 #include <list>
00008 #include <map>
00009 #include <vector>
00010
00011 namespace Moses
00012 {
00013 class Factor;
00014
00015 class NonTermContextProperty : public PhraseProperty
00016 {
00017 public:
00018
00019 NonTermContextProperty();
00020 ~NonTermContextProperty();
00021
00022 virtual void ProcessValue(const std::string &value);
00023
00024 virtual const std::string *GetValueString() const {
00025 UTIL_THROW2("NonTermContextProperty: value string not available in this phrase property");
00026 return NULL;
00027 };
00028
00029 float GetProb(size_t ntInd,
00030 size_t contextInd,
00031 const Factor *factor,
00032 float smoothConstant) const;
00033
00034 protected:
00035
00036 class ProbStore
00037 {
00038 typedef std::map<const Factor*, float> Map;
00039 typedef std::vector<Map> Vec;
00040 Vec m_vec;
00041 float m_totalCount;
00042
00043 float GetCount(size_t contextInd,
00044 const Factor *factor,
00045 float smoothConstant) const;
00046 float GetTotalCount(size_t contextInd, float smoothConstant) const;
00047
00048 public:
00049
00050 ProbStore()
00051 :m_vec(4)
00052 ,m_totalCount(0) {
00053 }
00054
00055 float GetProb(size_t contextInd,
00056 const Factor *factor,
00057 float smoothConstant) const;
00058
00059 float GetSize(size_t index) const {
00060 return m_vec[index].size();
00061 }
00062
00063 void AddToMap(size_t index, const Factor *factor, float count);
00064
00065 };
00066
00067
00068 std::vector<ProbStore> m_probStores;
00069
00070 void AddToMap(size_t ntIndex, size_t index, const Factor *factor, float count);
00071
00072 };
00073
00074 }
00075