def getLMHeuCost(self, wordsLst, phr_len):
        """ Compute Heuristic LM score for a given candidate.

            Heuristic LM score is calculated for m-1 words in the beginning and end
            of the candidate. The sentence-boundary markers (<s> and </s>) are first
            appended to the candidate and the heuristic scores are then computed
            separately for three cases, i) no boundary, ii) only left boundary and
            iii) only right boundary. The best (max) score from among the three are
            then returned as the LM heuristic score.
        """

        lmHueLst = [0.0, 0.0, 0.0]
        if (phr_len < self.lm_order): initWrds = wordsLst
        else: initWrds = wordsLst[0:self.lm_order-1]

        # Compute LM heuristic score for the first m-1 words
        if (wordsLst[0] == '<s>'):
            is_S_rule = True
        else:
            is_S_rule = False
            initWrds.insert(0, '<s>')

        part_lm_w_edge = 0.0
        part_lm_wo_edge = 0.0
        for i in range( 1, len(initWrds) ):
            part_lm_w_edge += getNGramProb( self.LM, ' '.join( initWrds[:(i+1)] ), i + 1 )
            if (is_S_rule):
                pass
            else:
                part_lm_wo_edge += getNGramProb( self.LM, ' '.join( initWrds[1:(i+1)] ), i )

        lm_heu_w_edge = part_lm_w_edge / SRILangModel.log_normalizer
        if (is_S_rule):
            lm_heu_wo_edge = lm_heu_w_edge
        else:
            lm_heu_wo_edge = part_lm_wo_edge / SRILangModel.log_normalizer

        lmHueLst[1] += lm_heu_w_edge
        lmHueLst[0] += lm_heu_wo_edge
        lmHueLst[2] += lm_heu_wo_edge

        # Compute LM heuristic score for the last m-1 words
        last_indx = phr_len - 1
        if (not is_S_rule and wordsLst[last_indx] != "</s>"):
            if last_indx <= self.lm_order - 1: phr_beg_indx = 1
            else: phr_beg_indx = last_indx - self.lm_order + 2

            phr_end = ' '.join( wordsLst[phr_beg_indx:] ) + " </s>"
            phr_end_len = last_indx - phr_beg_indx + 2
            lmHueLst[2] += ( getNGramProb( self.LM, phr_end, phr_end_len ) / SRILangModel.log_normalizer )

        return max(lmHueLst)                                        # Return the max value of LM heu
dataset/ETHPy150Open sfu-natlang/Kriya/src/Kriya-Decoder/lmSRILM.py/SRILangModel.getLMHeuCost/original