Package jazzparser :: Package evaluation :: Module results
[hide private]
[frames] | no frames]

Source Code for Module jazzparser.evaluation.results

 1  """A few simple convenience functions for processing results from evaluation 
 2   
 3  """ 
 4  """ 
 5  ============================== License ======================================== 
 6   Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 
 7    
 8   This file is part of The Jazz Parser. 
 9    
10   The Jazz Parser is free software: you can redistribute it and/or modify 
11   it under the terms of the GNU General Public License as published by 
12   the Free Software Foundation, either version 3 of the License, or 
13   (at your option) any later version. 
14    
15   The Jazz Parser is distributed in the hope that it will be useful, 
16   but WITHOUT ANY WARRANTY; without even the implied warranty of 
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
18   GNU General Public License for more details. 
19    
20   You should have received a copy of the GNU General Public License 
21   along with The Jazz Parser.  If not, see <http://www.gnu.org/licenses/>. 
22   
23  ============================ End license ====================================== 
24   
25  """ 
26  __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>" 
27   
28  from jazzparser.data.parsing import ParseResults 
29  from jazzparser.grammar import get_grammar 
30   
31 -def get_top_result(filename):
32 """ 33 Loads a top parse result from a ParseResults file and the gold standard 34 result. 35 36 @note: effectively now moved to ParseResults.get_top_result(). 37 This is just a wrapper for backward compatibility. 38 39 @rtype: pair 40 @return: gold standard result and top parser result 41 42 """ 43 # Load the data in from the file 44 res = ParseResults.from_file(filename) 45 top,gold = res.get_top_result() 46 if top is not None: 47 return top.lf, gold.lf 48 else: 49 return None,None
50
51 -def results_alignment(top_result, gold, grammar=None):
52 """ 53 Returns the list of alignment operations that result in the optimal alignment. 54 55 @return: tuple containing the alignment and the two sequences in the form 56 that they were compared (gold, top result). 57 58 """ 59 if grammar is None: 60 grammar = get_grammar() 61 # Perform the alignment 62 alignment,gold_seq,result_seq = grammar.formalism.Evaluation.tonal_space_alignment(gold, top_result) 63 return alignment,gold_seq,result_seq
64
65 -def result_lengths(filename, grammar=None):
66 """ 67 Opens the parse results file and returns the lengths of the gold standard 68 path and the top parse result's path. 69 70 """ 71 if grammar is None: 72 grammar = get_grammar() 73 # Load the data in from the file 74 res = ParseResults.from_file(filename) 75 76 gold_parse = res.get_gold_semantics() 77 if gold_parse is None: 78 gold_length = 0 79 else: 80 # Measure the length of the gold standard 81 gold_length = grammar.formalism.Evaluation.tonal_space_length(gold_parse) 82 83 # Get the results in order of probability 84 results = res.semantics 85 if len(results) == 0: 86 # No results: cannot analyse them 87 return gold_length,0 88 top_result = results[0][1] 89 top_length = grammar.formalism.Evaluation.tonal_space_length(top_result) 90 91 return gold_length, top_length
92