Package jazzparser :: Package parsers :: Package cky :: Module tools
[hide private]
[frames] | no frames]

Source Code for Module jazzparser.parsers.cky.tools

 1  """Interactive shell tools for the CKY parser. 
 2   
 3  This provides tools for the debugging shell that are specific to the  
 4  CKY parser. 
 5   
 6  """ 
 7  """ 
 8  ============================== License ======================================== 
 9   Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 
10    
11   This file is part of The Jazz Parser. 
12    
13   The Jazz Parser is free software: you can redistribute it and/or modify 
14   it under the terms of the GNU General Public License as published by 
15   the Free Software Foundation, either version 3 of the License, or 
16   (at your option) any later version. 
17    
18   The Jazz Parser is distributed in the hope that it will be useful, 
19   but WITHOUT ANY WARRANTY; without even the implied warranty of 
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
21   GNU General Public License for more details. 
22    
23   You should have received a copy of the GNU General Public License 
24   along with The Jazz Parser.  If not, see <http://www.gnu.org/licenses/>. 
25   
26  ============================ End license ====================================== 
27   
28  """ 
29  __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"  
30   
31  from jazzparser.shell.tools import Tool 
32   
33 -class ChartTool(Tool):
34 """ 35 Tool for examining the chart's contents. 36 """ 37 name = "Inspect CKY Chart" 38 commands = ['chart'] 39 usage = ('chart [<x> [<y>]]', "show final chart. 'x' selects arcs starting from node x. 'x y' selects arc (x,y). Use x='summary' to see a short form of the whole chart.") 40 help = """ 41 Show part or all of the chart that was created during parsing. 42 With no arguments, the whole chart will be printed. Optionally a 43 starting node may be given and only arcs starting at this node will 44 be displayed. An end node may also be given and only signs on the arc 45 between those two nodes will be displayed. 46 Sign indices are displayed with the entries. These are used to identify 47 a particular sign for, for example, rule application. 48 49 If x='summary' (that is, the command 'chart summary'), the short 50 form of the whole chart will be displayed - the form shown in progress 51 reports. 52 53 See also: 54 apply, for applying rules to the signs in the chart. 55 ichart, for displaying the graphical chart inspector. 56 """ 57
58 - def run(self, args, state):
59 chart = state.parser.chart 60 if len(args) == 0: 61 # Print the whole chart 62 print "%s" % chart 63 elif len(args) == 1: 64 if args[0] == 'summary': 65 print chart.summary 66 else: 67 # Print just the given row 68 print "%s" % chart.to_string(rows=[int(args[0])]) 69 else: 70 # Print just one cell 71 print "%s" % chart.to_string(rows=[int(args[0])],cols=[int(args[1])])
72
73 -class InteractiveChartTool(Tool):
74 """ 75 Tool for examining the chart's contents. 76 """ 77 name = "Graphically inspect CKY Chart" 78 commands = ['ichart'] 79 usage = ('ichart', "show chart in the graphical chart inspector") 80 help = """ 81 Show the whole chart in the graphical chart inspector. 82 83 See also: 84 chart, for print the contents of the chart. 85 """ 86
87 - def run(self, args, state):
88 chart = state.parser.chart 89 # We don't use chart.launch_inspector(), because that uses threading 90 # and seems to cause a mess 91 chart.launch_inspector(block=True)
92