Hi, If I understood correctly you want to have access to the binary phrase table on your own program to extract some entries on the fly. Attached you will find a piece of code that does exactly this.
Hope it helps Greetings -- Felipe. El vie, 27-11-2009 a las 14:36 -0600, Lane Schwartz escribió: > Hi all, > > I'm just wanting to double-check the current state of the suffix array > code in Moses. Can it be used to extract translation table entries on- > the-fly? > > Also, has anyone written up a paper on this in Moses? I'd like to know > who to cite if this has been written up. ;) > > Cheers, > Lane > > _______________________________________________ > Moses-support mailing list > Moses-support@mit.edu > http://mailman.mit.edu/mailman/listinfo/moses-support -- Felipe Sánchez Martínez <fsanc...@dlsi.ua.es> Departamento de Lenguajes y Sistemas Informáticos Universidad de Alicante, E-03071 Alicante (Spain) Tel.: +34 965 903 400, ext: 2966 Fax: +34 965 909 326 http://www.dlsi.ua.es/~fsanchez
/* * Copyright (C) 2009 Universitat d'Alacant * author: Felipe Sánchez-Martínez * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include <string> #include <vector> #include "utils.h" #include "TypeDef.h" #include "PhraseDictionaryTreeAdaptor.h" #include "Phrase.h" #include "TargetPhraseCollection.h" #include "LMList.h" #include "ScoreComponentCollection.h" using namespace std; using namespace Moses; int main () { vector<FactorType> input, output; vector<float> weight; int numScoreComponent=5; int numInputScores=0; int tableLimit=20; int weightWP=0; LMList lmList; string filePath="/path/to/binary/phrase-table"; cerr<<"numScoreComponent: "<<numScoreComponent<<endl; cerr<<"numInputScores: "<<numInputScores<<endl; input.push_back(0); output.push_back(0); weight.push_back(0); weight.push_back(0); weight.push_back(0); weight.push_back(0); weight.push_back(0); PhraseDictionaryTreeAdaptor *pd=new PhraseDictionaryTreeAdaptor(numScoreComponent, numInputScores); cerr<<"Table limit: "<<tableLimit<<endl; cerr<<"WeightWordPenalty: "<<weightWP<<endl; if (!pd->Load(input, output, filePath, weight, tableLimit, lmList, weightWP)) { delete pd; return false; } cerr<<"-------------------------------------------------"<<endl; FactorDirection direction; Phrase phrase(direction); phrase.CreateFromString(input, "marine equipment", "|"); TargetPhraseCollection *tpc = (TargetPhraseCollection*) pd->GetTargetPhraseCollection(phrase); TargetPhraseCollection::iterator iterTargetPhrase; for (iterTargetPhrase = tpc->begin(); iterTargetPhrase != tpc->end(); ++iterTargetPhrase) { cerr<<(*(*iterTargetPhrase))<<endl; stringstream strs; strs<<static_cast<const Phrase&>(*(*iterTargetPhrase)); cerr<<Utils::trim(strs.str())<<endl; ScoreComponentCollection scc = (*iterTargetPhrase)->GetScoreBreakdown(); cerr<<"Scores: "; for(unsigned i=0; i<scc.size(); i++) { cerr<<scc[i]<<" "; } cerr<<endl; } cerr<<"-------------------------------------------------"<<endl; }
_______________________________________________ Moses-support mailing list Moses-support@mit.edu http://mailman.mit.edu/mailman/listinfo/moses-support