diff options
author | Hieu Hoang <fishandfrolick@gmail.com> | 2012-05-15 18:06:25 +0400 |
---|---|---|
committer | Hieu Hoang <fishandfrolick@gmail.com> | 2012-05-15 18:06:25 +0400 |
commit | fea7bf9d1af349a7485cca4194cfe71e694a809b (patch) | |
tree | b6fe7fffb398741f961a10c4066eb6e31da7b579 /contrib | |
parent | b9e203f267e8e7831b04b355dbef3104f790f6d2 (diff) |
Add util for querying on-disk pt
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/queryOnDiskPt/compile.sh | 2 | ||||
-rw-r--r-- | contrib/queryOnDiskPt/queryOnDiskPt.cpp | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/contrib/queryOnDiskPt/compile.sh b/contrib/queryOnDiskPt/compile.sh index 8d1660b17..1643e27d1 100755 --- a/contrib/queryOnDiskPt/compile.sh +++ b/contrib/queryOnDiskPt/compile.sh @@ -1,6 +1,6 @@ SRI=/Users/hieuhoang/workspace/srilm IRST=/Users/hieuhoang/workspace/irstlm/trunk -g++ queryOnDiskPt.cpp ../../moses/src/PhraseDictionary.cpp -I../../moses/src/ -I../../ -L../../dist/lib/ -I../../OnDiskPt -lmert_lib -ldynsa -lz -lmoses_internal -lOnDiskPt -lLM -lkenlm -lkenutil -lRuleTable -lCYKPlusParser -lScope3Parser -L$SRI/lib/macosx/ -ldstruct -lflm -llattice -lmisc -loolm -L/opt/local/lib -lboost_thread-mt -L$IRST/lib -lirstlm +g++ -o queryOnDiskPt queryOnDiskPt.cpp ../../moses/src/PhraseDictionary.cpp -I../../moses/src/ -I../../ -L../../dist/lib/ -I../../OnDiskPt -lmert_lib -ldynsa -lz -lmoses_internal -lOnDiskPt -lLM -lkenlm -lkenutil -lRuleTable -lCYKPlusParser -lScope3Parser -L$SRI/lib/macosx/ -ldstruct -lflm -llattice -lmisc -loolm -L/opt/local/lib -lboost_thread-mt -L$IRST/lib -lirstlm diff --git a/contrib/queryOnDiskPt/queryOnDiskPt.cpp b/contrib/queryOnDiskPt/queryOnDiskPt.cpp index fb2667adf..afcd1b46b 100644 --- a/contrib/queryOnDiskPt/queryOnDiskPt.cpp +++ b/contrib/queryOnDiskPt/queryOnDiskPt.cpp @@ -17,6 +17,8 @@ void usage(); typedef unsigned int uint; +#define TABLE_LIMIT 20 + void Tokenize(OnDiskPt::Phrase &phrase , const std::string &token, bool addSourceNonTerm, bool addTargetNonTerm , OnDiskPt::OnDiskWrapper &onDiskWrapper) @@ -94,6 +96,8 @@ int main(int argc, char **argv) bool retDb = onDiskWrapper.BeginLoad(ttable); CHECK(retDb); + cerr << "Ready..." << endl; + std::string line; while(getline(std::cin, line)) { std::vector<std::string> tokens; @@ -116,10 +120,37 @@ int main(int argc, char **argv) } } + const PhraseNode *node = &onDiskWrapper.GetRootSourceNode(); + assert(node); + + for (size_t pos = 0; pos < sourcePhrase.GetSize(); ++pos) + { + const Word &word = sourcePhrase.GetWord(pos); + node = node->GetChild(word, onDiskWrapper); + + if (node == NULL) + { + break; + } + } + + if (node) + { // source phrase points to something + const TargetPhraseCollection *coll = node->GetTargetPhraseCollection(TABLE_LIMIT, onDiskWrapper); + string str = coll->GetDebugStr(); + cout << "Found" << str << endl; + } + else + { + cout << "Not found" << endl; + } std::cout << '\n'; std::cout.flush(); } + + cerr << "Finished." << endl; + } void usage() |