00001 // $Id$ 00002 00003 #ifndef _TABLES_H 00004 #define _TABLES_H 00005 00006 #include <iostream> 00007 #include <fstream> 00008 #include <cassert> 00009 #include <cstdlib> 00010 #include <string> 00011 #include <queue> 00012 #include <map> 00013 #include <cmath> 00014 00015 namespace MosesTraining 00016 { 00017 00018 typedef std::string WORD; 00019 typedef unsigned int WORD_ID; 00020 00021 class Vocabulary 00022 { 00023 public: 00024 std::map<WORD, WORD_ID> lookup; 00025 std::vector< WORD > vocab; 00026 WORD_ID storeIfNew( const WORD& ); 00027 WORD_ID getWordID( const WORD& ); 00028 inline WORD &getWord( const WORD_ID id ) { 00029 return vocab[ id ]; 00030 } 00031 }; 00032 00033 typedef std::vector< WORD_ID > PHRASE; 00034 typedef unsigned int PHRASE_ID; 00035 00036 class PhraseTable 00037 { 00038 public: 00039 std::map< PHRASE, PHRASE_ID > lookup; 00040 std::vector< PHRASE > phraseTable; 00041 PHRASE_ID storeIfNew( const PHRASE& ); 00042 PHRASE_ID getPhraseID( const PHRASE& ); 00043 void clear(); 00044 inline PHRASE &getPhrase( const PHRASE_ID id ) { 00045 return phraseTable[ id ]; 00046 } 00047 }; 00048 00049 typedef std::vector< std::pair< PHRASE_ID, double > > PHRASEPROBVEC; 00050 00051 class TTable 00052 { 00053 public: 00054 std::map< PHRASE_ID, std::vector< std::pair< PHRASE_ID, double > > > ttable; 00055 std::map< PHRASE_ID, std::vector< std::pair< PHRASE_ID, std::vector< double > > > > ttableMulti; 00056 }; 00057 00058 class DTable 00059 { 00060 public: 00061 std::map< int, double > dtable; 00062 void init(); 00063 void load( const std::string& ); 00064 double get( int ); 00065 }; 00066 00067 } 00068 00069 #endif