class_docstr: Phrase-based stack decoder for machine translation
  
  >>> from nltk.translate import PhraseTable
  >>> phrase_table = PhraseTable()
  >>> phrase_table.add(('niemand',), ('nobody',), log(0.8))
  >>> phrase_table.add(('niemand',), ('no', 'one'), log(0.2))
  >>> phrase_table.add(('erwartet',), ('expects',), log(0.8))
  >>> phrase_table.add(('erwartet',), ('expecting',), log(0.2))
  >>> phrase_table.add(('niemand', 'erwartet'), ('one', 'does', 'not', 'expect'), log(0.1))
  >>> phrase_table.add(('die', 'spanische', 'inquisition'), ('the', 'spanish', 'inquisition'), log(0.8))
  >>> phrase_table.add(('!',), ('!',), log(0.8))
  
  >>> #  nltk.model should be used here once it is implemented
  >>> from collections import defaultdict
  >>> language_prob = defaultdict(lambda: -999.0)
  >>> language_prob[('nobody',)] = log(0.5)
  >>> language_prob[('expects',)] = log(0.4)
  >>> language_prob[('the', 'spanish', 'inquisition')] = log(0.2)
  >>> language_prob[('!',)] = log(0.1)
  >>> language_model = type('',(object,),{'probability_change': lambda self, context, phrase: language_prob[phrase], 'probability': lambda self, phrase: language_prob[phrase]})()
  
  >>> stack_decoder = StackDecoder(phrase_table, language_model)
  
  >>> stack_decoder.translate(['niemand', 'erwartet', 'die', 'spanische', 'inquisition', '!'])
  ['nobody', 'expects', 'the', 'spanish', 'inquisition', '!']
class_docstr_tok: ["Phrase-based","stack","decoder","for","machine","translation",">",">",">","from","nltk.translate","import","PhraseTable",">",">",">","phrase_table","=","PhraseTable","(",")",">",">",">","phrase_table.add","(","(","'niemand","'",",",")",",","(","'nobody","'",",",")",",","log","(","0.8",")",")",">",">",">","phrase_table.add","(","(","'niemand","'",",",")",",","(","'no","'",",","'one","'",")",",","log","(","0.2",")",")",">",">",">","phrase_table.add","(","(","'erwartet","'",",",")",",","(","'expects","'",",",")",",","log","(","0.8",")",")",">",">",">","phrase_table.add","(","(","'erwartet","'",",",")",",","(","'expecting","'",",",")",",","log","(","0.2",")",")",">",">",">","phrase_table.add","(","(","'niemand","'",",","'erwartet","'",")",",","(","'one","'",",","'does","'",",","'not","'",",","'expect","'",")",",","log","(","0.1",")",")",">",">",">","phrase_table.add","(","(","'die","'",",","'spanische","'",",","'inquisition","'",")",",","(","'the","'",",","'spanish","'",",","'inquisition","'",")",",","log","(","0.8",")",")",">",">",">","phrase_table.add","(","(","'","!","'",",",")",",","(","'","!","'",",",")",",","log","(","0.8",")",")",">",">",">","#","nltk.model","should","be","used","here","once","it","is","implemented",">",">",">","from","collections","import","defaultdict",">",">",">","language_prob","=","defaultdict","(","lambda",":","-999.0",")",">",">",">","language_prob","[","(","'nobody","'",",",")","]","=","log","(","0.5",")",">",">",">","language_prob","[","(","'expects","'",",",")","]","=","log","(","0.4",")",">",">",">","language_prob","[","(","'the","'",",","'spanish","'",",","'inquisition","'",")","]","=","log","(","0.2",")",">",">",">","language_prob","[","(","'","!","'",",",")","]","=","log","(","0.1",")",">",">",">","language_model","=","type","(","``",",","(","object",",",")",",","{","'probability_change","'",":","lambda","self",",","context",",","phrase",":","language_prob","[","phrase","]",",","'probability","'",":","lambda","self",",","phrase",":","language_prob","[","phrase","]","}",")","(",")",">",">",">","stack_decoder","=","StackDecoder","(","phrase_table",",","language_model",")",">",">",">","stack_decoder.translate","(","[","'niemand","'",",","'erwartet","'",",","'die","'",",","'spanische","'",",","'inquisition","'",",","'","!","'","]",")","[","'nobody","'",",","'expects","'",",","'the","'",",","'spanish","'",",","'inquisition","'",",","'","!","'","]"]
docstr: Calculate the score of expanding ``hypothesis`` with
  ``translation_option``
  
  :param hypothesis: Hypothesis being expanded
  :type hypothesis: _Hypothesis
  
  :param translation_option: Information about the proposed expansion
  :type translation_option: PhraseTableEntry
  
  :param src_phrase_span: Word position span of the source phrase
  :type src_phrase_span: tuple(int, int)
docstr_tok: ["Calculate","the","score","of","expanding","``","hypothesis","``","with","``","translation_option","``",":","param","hypothesis",":","Hypothesis","being","expanded",":","type","hypothesis",":","_Hypothesis",":","param","translation_option",":","Information","about","the","proposed","expansion",":","type","translation_option",":","PhraseTableEntry",":","param","src_phrase_span",":","Word","position","span","of","the","source","phrase",":","type","src_phrase_span",":","tuple","(","int",",","int",")"]
code: def expansion_score(
      self, hypothesis, translation_option, src_phrase_span
  ):
      """
      Calculate the score of expanding ``hypothesis`` with
      ``translation_option``
  
      :param hypothesis: Hypothesis being expanded
      :type hypothesis: _Hypothesis
  
      :param translation_option: Information about the proposed expansion
      :type translation_option: PhraseTableEntry
  
      :param src_phrase_span: Word position span of the source phrase
      :type src_phrase_span: tuple(int, int)
      """
      score = hypothesis.raw_score
      score += translation_option.log_prob
      # The API of language_model is subject to change; it could accept
      # a string, a list of words, and/or some other type
      score += self.language_model.probability_change(
          hypothesis, translation_option.trg_phrase
      )
      score += self.distortion_score(hypothesis, src_phrase_span)
      score -= self.word_penalty * len(translation_option.trg_phrase)
      return score
  
imports: import warnings
  from collections import defaultdict
  from math import log
label_desc: Use image node_id 9 for calling the StackDecoder obj's underlying member method code with example usage: obj.expansion_score(hypothesis, translation_option, src_phrase_span) and returns: score