[SRILM User List] c++ sample for building language model

Andreas Stolcke stolcke at icsi.berkeley.edu
Fri Mar 8 12:37:35 PST 2013


On 3/8/2013 8:06 AM, Yi Yang wrote:
> Hi Mohsen,
>
> Hope the following codes can be helpful:
you forgot to create the Vocab object.  In your case you could create it 
globally to your code works otherwise:

Vocab vocab;

Andreas

>
> void SrilmTest::srilm_init(const char* fname, int order) {
>   File file(fname, "r", 0);
>   assert(file);

>   ngram = new Ngram(vocab, order);
>   ngram->read(file, false);
>   cerr << "Done\n";
> }
>
> int SrilmTest::srilm_getvoc(const char* word) {
>   return vocab.getIndex((VocabString)word);
> }
>
> float SrilmTest::srilm_wordprob(int w, int* context) {
>   return (float)ngram->wordProb(w, (VocabIndex*)context);
> }
>
>
> On Thu, Mar 7, 2013 at 3:23 PM, mohsen jadidi <mohsen.jadidi at gmail.com 
> <mailto:mohsen.jadidi at gmail.com>> wrote:
>
>     Hey,
>
>     I need to use srilm in my c++ code to build ML. all the examples
>     and slides in the internet explained it using ngram-count command
>     not code. I know should use <Ngram.h> <Vocab.h>. can you point me
>     to a starting point?
>
>     cheers,
>
>
>     -- 
>     Mohsen
>
>     _______________________________________________
>     SRILM-User site list
>     SRILM-User at speech.sri.com <mailto:SRILM-User at speech.sri.com>
>     http://www.speech.sri.com/mailman/listinfo/srilm-user
>
>
>
>
> -- 
> Sincerely,
> Yi Yang
> http://www.cc.gatech.edu/~yyang319/ 
> <http://www.cc.gatech.edu/%7Eyyang319/>
>
>
> _______________________________________________
> SRILM-User site list
> SRILM-User at speech.sri.com
> http://www.speech.sri.com/mailman/listinfo/srilm-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.speech.sri.com/pipermail/srilm-user/attachments/20130308/2102b7d3/attachment.html>


More information about the SRILM-User mailing list