00001 #pragma once 00002 00003 #include <istream> 00004 #include <map> 00005 #include <ostream> 00006 #include <vector> 00007 00008 #include "vocabulary.h" 00009 00010 namespace MosesTraining { 00011 namespace Syntax { 00012 00013 class Pcfg { 00014 public: 00015 typedef std::vector<std::size_t> Key; 00016 typedef std::map<Key, double> Map; 00017 typedef Map::iterator iterator; 00018 typedef Map::const_iterator const_iterator; 00019 00020 Pcfg() {} 00021 00022 iterator begin() { return rules_.begin(); } 00023 const_iterator begin() const { return rules_.begin(); } 00024 00025 iterator end() { return rules_.end(); } 00026 const_iterator end() const { return rules_.end(); } 00027 00028 void Add(const Key &, double); 00029 bool Lookup(const Key &, double &) const; 00030 void Read(std::istream &, Vocabulary &); 00031 void Write(const Vocabulary &, std::ostream &) const; 00032 00033 private: 00034 Map rules_; 00035 }; 00036 00037 } // namespace Syntax 00038 } // namespace MosesTraining