EvaluateLM.cpp

Go to the documentation of this file.
00001 #include "stdio.h"
00002 #include "stdlib.h"
00003 #include "time.h"
00004 #include "_SuffixArrayLanguageModel.h"
00005 #include <iostream>
00006 #include <sstream>
00007 #include <string>
00008 
00009 using namespace std;
00010 
00017 int main(int argc, char * argv[]){
00018         if(argc<2){
00019                 cerr<<"\nUsage:\n\t"<<argv[0]<<" configurationFileName < sentences\n";
00020                 exit(0);
00021         }
00022 
00023         C_SuffixArrayLanguageModel salm(argv[1]);
00024 
00025         long ltime1, ltime2;
00026         time( &ltime1 );
00027 
00028         string aWord;
00029         char aLine[10240];
00030         while(!cin.eof()){
00031                 cin.getline(aLine, 10240, '\n');
00032 
00033                 if(strlen(aLine)>0){
00034                         istringstream inputLine(aLine, istringstream::in);
00035                         LMState lmState = salm.beginOfSentenceState();
00036 
00037                         LMState nextState;
00038                         double logProb = 0;
00039 
00040                         while(! inputLine.eof()){
00041                                 inputLine>>aWord;
00042                                 if(aWord.length()>0){
00043                                         IndexType vocId = salm.returnVocId(C_String((char *) aWord.c_str()));
00044                                         logProb+=salm.logProb(lmState, vocId, nextState);
00045                                         lmState = nextState;
00046                                 }
00047                                 aWord="";
00048                         }
00049 
00050                         logProb+=salm.logProbEnd(lmState);
00051                         cout<<"LogProb="<<logProb<<endl;
00052                         
00053                 }
00054 
00055                 aLine[0]=0;
00056         }
00057 
00058         time( &ltime2 );        
00059         cerr<<"\n"<<ltime2-ltime1<<" seconds spent."<<endl;
00060 
00061         return 1;
00062 }

Generated on Fri Jul 6 23:11:09 2007 for SALM by  doxygen 1.5.1