class_docstr: A probabilistic, projective dependency parser.
  
  This parser returns the most probable projective parse derived from the
  probabilistic dependency grammar derived from the train() method.  The
  probabilistic model is an implementation of Eisner's (1996) Model C, which
  conditions on head-word, head-tag, child-word, and child-tag.  The decoding
  uses a bottom-up chart-based span concatenation algorithm that's identical
  to the one utilized by the rule-based projective parser.
  
  Usage example
  
  >>> from nltk.parse.dependencygraph import conll_data2
  
  >>> graphs = [
  ... DependencyGraph(entry) for entry in conll_data2.split('\n\n') if entry
  ... ]
  
  >>> ppdp = ProbabilisticProjectiveDependencyParser()
  >>> ppdp.train(graphs)
  
  >>> sent = ['Cathy', 'zag', 'hen', 'wild', 'zwaaien', '.']
  >>> list(ppdp.parse(sent))
  [Tree('zag', ['Cathy', 'hen', Tree('zwaaien', ['wild', '.'])])]
class_docstr_tok: ["A","probabilistic",",","projective","dependency","parser",".","This","parser","returns","the","most","probable","projective","parse","derived","from","the","probabilistic","dependency","grammar","derived","from","the","train","(",")","method",".","The","probabilistic","model","is","an","implementation","of","Eisner","'s","(","1996",")","Model","C",",","which","conditions","on","head-word",",","head-tag",",","child-word",",","and","child-tag",".","The","decoding","uses","a","bottom-up","chart-based","span","concatenation","algorithm","that","'s","identical","to","the","one","utilized","by","the","rule-based","projective","parser",".","Usage","example",">",">",">","from","nltk.parse.dependencygraph","import","conll_data2",">",">",">","graphs","=","[","...","DependencyGraph","(","entry",")","for","entry","in","conll_data2.split","(","'\\n\\n","'",")","if","entry","...","]",">",">",">","ppdp","=","ProbabilisticProjectiveDependencyParser","(",")",">",">",">","ppdp.train","(","graphs",")",">",">",">","sent","=","[","'Cathy","'",",","'zag","'",",","'hen","'",",","'wild","'",",","'zwaaien","'",",","'",".","'","]",">",">",">","list","(","ppdp.parse","(","sent",")",")","[","Tree","(","'zag","'",",","[","'Cathy","'",",","'hen","'",",","Tree","(","'zwaaien","'",",","[","'wild","'",",","'",".","'","]",")","]",")","]"]
docstr: Computes the probability of a dependency graph based
  on the parser's probability model (defined by the parser's
  statistical dependency grammar).
  
  :param dg: A dependency graph to score.
  :type dg: DependencyGraph
  :return: The probability of the dependency graph.
  :rtype: int
docstr_tok: ["Computes","the","probability","of","a","dependency","graph","based","on","the","parser","'s","probability","model","(","defined","by","the","parser's","statistical","dependency","grammar",")",".",":","param","dg",":","A","dependency","graph","to","score",".",":","type","dg",":","DependencyGraph",":","return",":","The","probability","of","the","dependency","graph",".",":","rtype",":","int"]
code: def compute_prob(self, dg):
      """
      Computes the probability of a dependency graph based
      on the parser's probability model (defined by the parser's
      statistical dependency grammar).
  
      :param dg: A dependency graph to score.
      :type dg: DependencyGraph
      :return: The probability of the dependency graph.
      :rtype: int
      """
      prob = 1.0
      for node_index in range(1, len(dg.nodes)):
          # children = dg.nodes[node_index]['deps']
          children = list(
              chain.from_iterable(dg.nodes[node_index]["deps"].values())
          )
  
          nr_left_children = dg.left_children(node_index)
          nr_right_children = dg.right_children(node_index)
          nr_children = nr_left_children + nr_right_children
          for child_index in range(
              0 - (nr_left_children + 1), nr_right_children + 2
          ):
              head_word = dg.nodes[node_index]["word"]
              head_tag = dg.nodes[node_index]["tag"]
              child = "STOP"
              child_tag = "STOP"
              prev_word = "START"
              prev_tag = "START"
              if child_index < 0:
                  array_index = child_index + nr_left_children
                  if array_index >= 0:
                      child = dg.nodes[children[array_index]]["word"]
                      child_tag = dg.nodes[children[array_index]]["tag"]
                  if child_index != -1:
                      prev_word = dg.nodes[children[array_index + 1]][
                          "word"
                      ]
                      prev_tag = dg.nodes[children[array_index + 1]][
                          "tag"
                      ]
                  head_event = (
                      "(head ({} {}) (mods ({}, {}, {}) left))".format(
                          child,
                          child_tag,
                          prev_tag,
                          head_word,
                          head_tag,
                      )
                  )
                  mod_event = "(mods ({}, {}, {}) left))".format(
                      prev_tag,
                      head_word,
                      head_tag,
                  )
                  h_count = self._grammar._events[head_event]
                  m_count = self._grammar._events[mod_event]
  
                  # If the grammar is not covered
                  if m_count != 0:
                      prob *= h_count / m_count
                  else:
                      prob = 0.00000001  # Very small number
  
              elif child_index > 0:
                  array_index = child_index + nr_left_children - 1
                  if array_index < nr_children:
                      child = dg.nodes[children[array_index]]["word"]
                      child_tag = dg.nodes[children[array_index]]["tag"]
                  if child_index != 1:
                      prev_word = dg.nodes[children[array_index - 1]][
                          "word"
                      ]
                      prev_tag = dg.nodes[children[array_index - 1]][
                          "tag"
                      ]
                  head_event = (
                      "(head ({} {}) (mods ({}, {}, {}) right))".format(
                          child,
                          child_tag,
                          prev_tag,
                          head_word,
                          head_tag,
                      )
                  )
                  mod_event = "(mods ({}, {}, {}) right))".format(
                      prev_tag,
                      head_word,
                      head_tag,
                  )
                  h_count = self._grammar._events[head_event]
                  m_count = self._grammar._events[mod_event]
  
                  if m_count != 0:
                      prob *= h_count / m_count
                  else:
                      prob = 0.00000001  # Very small number
  
      return prob
  
imports: from collections import defaultdict
  from functools import total_ordering
  from itertools import chain
  from nltk.grammar import DependencyGrammar, DependencyProduction, ProbabilisticDependencyGrammar
  from nltk.internals import raise_unorderable_types
  from nltk.parse.dependencygraph import DependencyGraph
label_desc: Use image node_id 5 for calling the ProbabilisticProjectiveDependencyParser obj's underlying member method code with example usage: obj.compute_prob(dg) and returns: prob