Ejemplo n.º 1
0
void TEvalScore::GetNGramH(const TIntV& WIdV, 
        const int& MxNGramLen, TIntH& NGramIdH) {

    const int Wds = WIdV.Len();
    for (int NGramLen = 1; NGramLen <= MxNGramLen; NGramLen++) {
        const int MxNGramStart = Wds - NGramLen + 1;
        for (int NGramStart = 0; NGramStart < MxNGramStart; NGramStart++) {
            // get the ngram
            TIntV NGram; WIdV.GetSubValV(NGramStart, NGramStart+NGramLen-1, NGram);
            IAssert(NGram.Len() == NGramLen);
            // get id of the ngram
            int NGramId = NGramH.GetKeyId(NGram);
            // word does not exist yet, add it to the hash table
            if (NGramId == -1) { NGramId = NGramH.AddKey(NGram); }
            // add ngram to the sentence ngram bag
            NGramIdH.AddDat(NGramId)++;
        }
    }
}