Hi,

I guess you mean to query a phrase table on disk. If my guess is correct, the code attached might help you.

Regards
--
Felipe

El 04/04/10 23:55, Giuseppe Attardi escribió:
Has anyone developed a tool for querying a phrase table directly?

-- Beppe

_______________________________________________
Moses-support mailing list
[email protected]
http://mailman.mit.edu/mailman/listinfo/moses-support

--
Felipe Sánchez Martínez
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 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 (int argc, char *argv[]) {
  vector<FactorType> input, output;
  vector<float> weight;
  int numScoreComponent=5;
  int numInputScores=0;
  int tableLimit=0;
  int weightWP=0;
  LMList lmList;
  string filePath="/path/to/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);				

  string source_str="";
  for(unsigned i=1; i<argc; i++) {
    if (source_str.length()>0) source_str+=" ";
    source_str+=argv[i];
  }
  
  PhraseDictionaryTreeAdaptor *pd=new PhraseDictionaryTreeAdaptor(numScoreComponent, numInputScores);
				
  cerr<<"Table limit: "<<tableLimit<<endl;
  cerr<<"WeightWordPenalty: "<<weightWP<<endl;
  cerr<<"Source phrase: ___"<<source_str<<"___"<<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, source_str, "|");
  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<<source_str<<" => ___"<<Utils::trim(strs.str())<<"___ ";
    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
[email protected]
http://mailman.mit.edu/mailman/listinfo/moses-support

Reply via email to