00001 #pragma once
00002
00003 #include <boost/unordered_map.hpp>
00004 #include <sys/stat.h>
00005 #include "vocabid.hh"
00006 #include <algorithm>
00007 #include <deque>
00008 #include "probing_hash_utils.hh"
00009 #include "hash.hh"
00010 #include "line_splitter.hh"
00011 #include "moses//Util.h"
00012
00013 namespace Moses
00014 {
00015
00016 class QueryEngine
00017 {
00018 std::map<uint64_t, std::string> source_vocabids;
00019
00020 typedef std::vector<unsigned char> Alignments;
00021 std::vector<Alignments> alignColl;
00022
00023 Table table;
00024 char *mem;
00025
00026 size_t table_filesize;
00027 bool is_reordering;
00028
00029 void read_alignments(const std::string &alignPath);
00030
00031 public:
00032 int num_scores;
00033 int num_lex_scores;
00034 bool logProb;
00035
00036 QueryEngine(const char *);
00037 ~QueryEngine();
00038
00039 std::pair<bool, uint64_t> query(uint64_t key);
00040
00041 const std::map<uint64_t, std::string> &getSourceVocab() const {
00042 return source_vocabids;
00043 }
00044
00045 const std::vector<Alignments> &getAlignments() const {
00046 return alignColl;
00047 }
00048
00049 uint64_t getKey(uint64_t source_phrase[], size_t size) const;
00050
00051 template<typename T>
00052 inline bool Get(const boost::unordered_map<std::string, std::string> &keyValue, const std::string &sought, T &found) const {
00053 boost::unordered_map<std::string, std::string>::const_iterator iter = keyValue.find(sought);
00054 if (iter == keyValue.end()) {
00055 return false;
00056 }
00057
00058 const std::string &foundStr = iter->second;
00059 found = Scan<T>(foundStr);
00060 return true;
00061 }
00062
00063 };
00064
00065 }
00066