Package jazzparser :: Package parsers :: Package pcfg :: Module inspector
[hide private]
[frames] | no frames]

Source Code for Module jazzparser.parsers.pcfg.inspector

 1  """Chart inspector for the pcfg parser. 
 2   
 3  Some small extensions to the CKY chart inspector for the pcfg parser. 
 4   
 5  See L{jazzparser.parsers.cky.inspector} for details. 
 6   
 7  This is basically just copied from  
 8  L{jazzparser.parsers.tagrank.inspector}. 
 9   
10  """ 
11  """ 
12  ============================== License ======================================== 
13   Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 
14    
15   This file is part of The Jazz Parser. 
16    
17   The Jazz Parser is free software: you can redistribute it and/or modify 
18   it under the terms of the GNU General Public License as published by 
19   the Free Software Foundation, either version 3 of the License, or 
20   (at your option) any later version. 
21    
22   The Jazz Parser is distributed in the hope that it will be useful, 
23   but WITHOUT ANY WARRANTY; without even the implied warranty of 
24   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
25   GNU General Public License for more details. 
26    
27   You should have received a copy of the GNU General Public License 
28   along with The Jazz Parser.  If not, see <http://www.gnu.org/licenses/>. 
29   
30  ============================ End license ====================================== 
31   
32  """ 
33  __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"  
34   
35  from jazzparser.parsers.cky.inspector import ChartInspectorThread, \ 
36                      ChartInspectorWindow, CellInspectorWindow 
37  # Gtk version check already done in cky.inspector 
38  import gtk, gobject 
39   
40 -class PcfgCellInspectorWindow(CellInspectorWindow):
41 - def _create_column_data(self):
42 """ 43 Override to add extra column to the cell inspector. 44 45 """ 46 liststore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) 47 # Add all the signs to the store 48 for sign in reversed(sorted(self.signs, key=lambda s: s.probability)): 49 liststore.append(["%f" % sign.probability, "%s" % sign]) 50 return liststore
51
52 - def _create_columns(self):
53 """ 54 Override to add extra column. 55 56 """ 57 # Add a column to the treeview to display the probabilities 58 prob_column = gtk.TreeViewColumn("Probability") 59 self.treeview.append_column(prob_column) 60 # Render the probabilities as text 61 prob_renderer = gtk.CellRendererText() 62 prob_column.pack_start(prob_renderer, True) 63 prob_column.add_attribute(prob_renderer, "text", 0) 64 65 # Add the sign column as before 66 sign_column = gtk.TreeViewColumn("Signs on edge (%d,%d)" % (self.from_node, self.to_node)) 67 self.treeview.append_column(sign_column) 68 # Render the signs as text 69 sign_renderer = gtk.CellRendererText() 70 sign_renderer.set_property('family', 'monospace') 71 sign_column.pack_start(sign_renderer, True) 72 sign_column.add_attribute(sign_renderer, "text", 1) 73 74 # Search signs by the main column 75 self.treeview.set_search_column(1)
76
77 -class PcfgChartInspectorWindow(ChartInspectorWindow):
78 CELL_INSPECTOR_IMPL = PcfgCellInspectorWindow
79
80 -class PcfgChartInspectorThread(ChartInspectorThread):
81 INSPECTOR_IMPL = PcfgChartInspectorWindow
82