Mercurial > hg > multiomr
comparison Result/ProcessGroundS2.py @ 2:46fb79167a61 tip
Main Code
author | Victor Padilla <victor.padilla.mc@gmail.com> |
---|---|
date | Mon, 04 May 2015 22:56:18 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:0f7f611deca4 | 2:46fb79167a61 |
---|---|
1 | |
2 | |
3 ''' | |
4 Created on 13/06/2014 | |
5 | |
6 @author: victor | |
7 ''' | |
8 | |
9 from Process import PipelineAlignment | |
10 from Process import SymbolConversion | |
11 from Functions import MeasureFunctions | |
12 | |
13 class ProcessGroundS2: | |
14 | |
15 def getSimilarity(self,omrs,part): | |
16 ''' | |
17 main function to get the similarity vs the ground | |
18 | |
19 return: | |
20 result=percentage of similarity | |
21 errors= array with errors to write in xml | |
22 scoreWithErrors= score to write with colors | |
23 ''' | |
24 pa=PipelineAlignment() | |
25 mf=MeasureFunctions() | |
26 for omr in omrs: | |
27 try: | |
28 omr=mf.convertVoicesToChord(omr) | |
29 except: | |
30 pass | |
31 | |
32 omr_symbolsAlign=pa.alignGround(omrs,part) | |
33 | |
34 omr_ground=omr_symbolsAlign[0] | |
35 omr_part=omr_symbolsAlign[1] | |
36 | |
37 count=0 | |
38 symbolsLength=0 | |
39 Errors=[] | |
40 arrErrors=[] | |
41 for i in range(len(omr_ground)): | |
42 | |
43 sGround=omr_ground[i] | |
44 sOMR=omr_part[i] | |
45 if isinstance(sGround,list): | |
46 sGroundSimple=sGround[0] | |
47 else: | |
48 sGroundSimple=sGround | |
49 if isinstance(sOMR,list): | |
50 sOMRSimple=sOMR[0] | |
51 else: | |
52 sOMRSimple=sOMR | |
53 | |
54 #Removing grace notes | |
55 if(self.isGraceNote(sGround) or self.isGraceNote(sOMR)): | |
56 continue | |
57 | |
58 if(self.isBarline(sGroundSimple) or self.isBarline(sOMRSimple)): | |
59 continue | |
60 #Removing Time Signatures. PS introduce a lot extra time signatures | |
61 # if(self.isKeySignature(sGroundSimple) or self.isKeySignature(sOMRSimple)): | |
62 # continue | |
63 #Removing clef errors | |
64 if(self.isClef(sGroundSimple) or self.isClef(sOMRSimple)): | |
65 continue | |
66 if(self.isRest(sGroundSimple) or self.isRest(sOMRSimple)): | |
67 continue | |
68 #Removing extra rest due to voices | |
69 # if self.isRest(sOMRSimple): | |
70 # if sGroundSimple=="*": | |
71 # continue | |
72 | |
73 if (sGroundSimple==sOMRSimple): | |
74 if sGround[0]==sOMR[0] and sGround[1]==sOMR[1]:#not counting ties | |
75 #if sGround[0]==sOMR[0]: | |
76 count+=1 | |
77 else: | |
78 Errors.append([sGround,sOMR,i]) | |
79 arrErrors.append(i) | |
80 | |
81 else: | |
82 Errors.append([sGround,sOMR,i]) | |
83 arrErrors.append(i) | |
84 if sOMRSimple=="*": | |
85 try: | |
86 omr_part[i]=omr_ground[i] | |
87 omr_part[i][5]="#00ff00" #note missing | |
88 except: | |
89 print "error",omr_part[i] | |
90 elif sGroundSimple=="*": | |
91 try: | |
92 omr_part[i][5]="#0000ff" #extra note | |
93 except: | |
94 print "error",omr_part[i] | |
95 else: | |
96 try: | |
97 omr_part[i]=omr_ground[i] | |
98 omr_part[i][5]="#ff0000" #mistake in note | |
99 except: | |
100 print "error",omr_part[i] | |
101 | |
102 | |
103 symbolsLength+=1 | |
104 | |
105 result=(float(count)/symbolsLength)*100 | |
106 sc=SymbolConversion() | |
107 omr_part=sc.setVoices(omr_part) | |
108 scoreWithErrors=sc.convertM21(omr_part) | |
109 return result,Errors,scoreWithErrors | |
110 | |
111 def isGraceNote(self,s): | |
112 ''' | |
113 Returns true if the symbol is a grace note | |
114 ''' | |
115 if isinstance(s,list): | |
116 if s[0].find('N:')!=-1: | |
117 duration=s[1] | |
118 if float(duration)==0: | |
119 return True | |
120 | |
121 return False | |
122 | |
123 def isKeySignature(self,s): | |
124 ''' | |
125 Returns true if the symbol is a key signature | |
126 ''' | |
127 if s.find('KS:')!=-1: | |
128 return True | |
129 return False | |
130 | |
131 def isRest(self,s): | |
132 ''' | |
133 Returns true if the symbol is a rest | |
134 ''' | |
135 if s.find('R:')!=-1: | |
136 return True | |
137 return False | |
138 | |
139 def isBarline(self,s): | |
140 ''' | |
141 Returns true if the symbol is a barline | |
142 ''' | |
143 if s.find('!')!=-1: | |
144 return True | |
145 return False | |
146 | |
147 def isClef(self,s): | |
148 ''' | |
149 Returns true if the symbol is a clef | |
150 ''' | |
151 if s.find('CL:')!=-1: | |
152 return True | |
153 return False | |
154 | |
155 |