Package jazzparser :: Package data :: Package db_mirrors :: Module consistency
[hide private]
[frames] | no frames]

Source Code for Module jazzparser.data.db_mirrors.consistency

 1  """Annotator consistency evaluation data structures. 
 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  import pickle 
29  from . import SequenceIndex 
30 31 -class ConsistencyData(object):
32 """ 33 Data structure to store multiple annotations of the same chord sequences 34 to evaluate annotator consistency. 35 36 Currently only supports pairs of annotations for each sequence. If 37 more than two alternatives need to be compared, this will have to be 38 extended. 39 40 """
41 - def __init__(self, sequences, pairs, sequence_index=False):
42 if sequence_index: 43 # We've been given a fully-formed sequence index 44 self.sequences = sequences 45 else: 46 self.sequences = SequenceIndex(sequences) 47 self.pairs = pairs
48
49 - def __len__(self):
50 return len(self.pairs)
51
52 - def __getitem__(self, index):
53 id1, id2 = self.pairs[index] 54 return (self.sequences.sequence_by_id(id1), 55 self.sequences.sequence_by_id(id2))
56 57 @staticmethod
58 - def from_file(filename):
59 with open(filename, 'r') as file: 60 # Read in the pickled data 61 unpick = pickle.Unpickler(file) 62 data = unpick.load() 63 si, pairs = data 64 return ConsistencyData(si, pairs, sequence_index=True)
65
66 - def save(self, filename):
67 with open(filename, 'w') as file: 68 pickler = pickle.Pickler(file) 69 pickler.dump((self.sequences, self.pairs))
70