Commit 0663dcd2 authored by Sulfyderz's avatar Sulfyderz
Browse files

[New]:Adding new parameters to the method createCorrectionOrderFromDiarHacBic.

parent 3c630507
......@@ -5084,16 +5084,20 @@ class Show(object):
self.diarRaw.pack()
# Create the correction order which fast decreases the DER and the HCIQ ratio (DER(t-1)-DER(t))/(HCIQ(t-1)-HCIQ(t))
def createCorrectionOrderFromDiarHacBic(self,lookForBestSeg=True,refNoOverlap=False,useUem=True,correctSegModeBigFirst=False,tolerance=25,cb=12,db=5.1,cn=12.7,sn=7.6,v=0):
assert "diarHacBic" in self.__dict__ and isinstance(refNoOverlap,bool) and isinstance(useUem,bool) and isinstance(tolerance,numbers.Number) and isinstance(correctSegModeBigFirst,bool) and isinstance(lookForBestSeg,bool)
## modeNewAction: Pour un seg ref donné, on supprime tout. Actions possibles pour un seg ref: 2 createBoundary si nécessaire avec 1 createLabel ou 1 selectLabel; Sinon 1 validate.
## onlyDER: On recherche uniquement à faire décroitre le plus rapidement possible le DER. HCIQ oublié.
def createCorrectionOrderFromDiarHacBic(self,onlyDER=False,modeNewAction=False,lookForBestSeg=True,refNoOverlap=False,useUem=True,correctSegModeBigFirst=False,tolerance=25,cb=12,db=5.1,cn=12.7,sn=7.6,v=0):
assert "diarHacBic" in self.__dict__ and isinstance(onlyDER,bool) and isinstance(modeNewAction,bool) and isinstance(refNoOverlap,bool) and isinstance(useUem,bool) and isinstance(tolerance,numbers.Number) and isinstance(correctSegModeBigFirst,bool) and isinstance(lookForBestSeg,bool)
self.correctionOrder=dict()
self.correctionOrder["diar"]=dict()
self.correctionOrder["DER"]=dict()
self.correctionOrder["HCIQ"]=dict()
if not onlyDER:
self.correctionOrder["HCIQ"]=dict()
self.correctionOrder["correction"]=dict()
self.correctionOrder["correctedAreaHyp"]=dict()
self.correctionOrder["correctedAreaRef"]=dict()
self.correctionOrder["ratio"]=dict()
if not onlyDER:
self.correctionOrder["ratio"]=dict()
if refNoOverlap:
diarRef=self.diarRefNoOverlap
......@@ -5111,11 +5115,13 @@ class Show(object):
for key in self.diarHacBic.keys():
self.correctionOrder["diar"][key]=dict()
self.correctionOrder["DER"][key]=dict()
self.correctionOrder["HCIQ"][key]=dict()
if not onlyDER:
self.correctionOrder["HCIQ"][key]=dict()
self.correctionOrder["correction"][key]=dict()
self.correctionOrder["correctedAreaHyp"][key]=dict()
self.correctionOrder["correctedAreaRef"][key]=dict()
self.correctionOrder["ratio"][key]=dict()
if not onlyDER:
self.correctionOrder["ratio"][key]=dict()
value=copy.deepcopy(self.diarHacBic[key])
if useUem:
......@@ -5145,13 +5151,15 @@ class Show(object):
self.correctionOrder["DER"][key][-1]=der.error()
#Calculer le HCIQ
self.correctionOrder["HCIQ"][key][-1]=0
if not onlyDER:
self.correctionOrder["HCIQ"][key][-1]=0
#Calculer le ratio
self.correctionOrder["correction"][key][-1]=None
self.correctionOrder["correctedAreaHyp"][key][-1]=None
self.correctionOrder["correctedAreaRef"][key][-1]=None
self.correctionOrder["ratio"][key][-1]=None
if not onlyDER:
self.correctionOrder["ratio"][key][-1]=None
diarRefLoop=copy.deepcopy(diarRef)
#Cluster affecté
......@@ -5163,11 +5171,13 @@ class Show(object):
prevDER=self.correctionOrder["DER"][key][i-1].spk_conf+self.correctionOrder["DER"][key][i-1].spk_miss+self.correctionOrder["DER"][key][i-1].spk_fa
self.correctionOrder["diar"][key][i]=None
self.correctionOrder["DER"][key][i]=None
self.correctionOrder["HCIQ"][key][i]=None
if not onlyDER:
self.correctionOrder["HCIQ"][key][i]=None
self.correctionOrder["correction"][key][i]=None
self.correctionOrder["correctedAreaHyp"][key][i]=None
self.correctionOrder["correctedAreaRef"][key][i]=None
self.correctionOrder["ratio"][key][i]=None
if not onlyDER:
self.correctionOrder["ratio"][key][i]=None
clusterAffTmp=set()
segTmp=None
for j in diarRefLoop:
......@@ -5188,7 +5198,7 @@ class Show(object):
#Récupérer les segments qui matchent avec le segment ref selectionné et effectuer les post-traitements nécessaires.
## Gère les createBoundary.
valueMatchRaw=Diar()
toRename=Diar()
#toRename=Diar()
for y in value:
if Segment.intersection(j,y) is not None:
valueMatchRaw.append_seg(copy.deepcopy(y))
......@@ -5199,10 +5209,10 @@ class Show(object):
cbNumberLocal+=1
if y['stop']>j['stop']:
valueLocal=DiarTools.splitSegment(y,valueLocal,j['stop'])
x=copy.deepcopy(y)
x['start']=j['stop']
x['cluster']=j['cluster']
toRename.append_seg(x)
#x=copy.deepcopy(y)
#x['start']=j['stop']
#x['cluster']=j['cluster']
#toRename.append_seg(x)
y['stop']=j['stop']
cbNumberLocal+=1
valueMatch.append_seg(y)
......@@ -5210,53 +5220,69 @@ class Show(object):
valueMatchRaw.sort()
#Gérer les affectées et les "création name"
## Problème: Comment rename (trouver) la bonne étiquette hyp qui matche le plus avec celle de la ref ?
if j['cluster'] not in clusterAffLocal:
cnNumberLocal=1
if correctSegModeBigFirst:
dMax=0
clusterMax=None
for y in valueMatch:
if y.duration()>dMax and y['cluster'] not in clusterAffLocal:
dMax=y.duration()
clusterMax=y['cluster']
if clusterMax is not None and dMax!=0:
#-2 car là où on le crée et la fois où on le valide dans le getHCIQ
vNumberLocal=-1
valueMatch.rename('cluster',[clusterMax],j['cluster'])
valueLocal.rename('cluster',[clusterMax],j['cluster'])
else:
clusterFirst=None
for idx,y in enumerate(valueMatch):
if y['cluster'] not in clusterAffLocal:
clusterFirst=y['cluster']
break
#Comprend le cas où tous remplis.
if idx!=0:
snNumberLocal+=1
if clusterFirst is not None:
vNumberLocal=-1
valueMatch.rename('cluster',[clusterFirst],j['cluster'])
valueLocal.rename('cluster',[clusterFirst],j['cluster'])
if valueMatch[0]['cluster']!=j['cluster']:
snNumberLocal=-1
if not modeNewAction:
if correctSegModeBigFirst:
dMax=0
clusterMax=None
for y in valueMatch:
if y.duration()>dMax and y['cluster'] not in clusterAffLocal:
dMax=y.duration()
clusterMax=y['cluster']
if clusterMax is not None and dMax!=0:
#-2 car là où on le crée et la fois où on le valide dans le getHCIQ
vNumberLocal=-1
valueMatch.rename('cluster',[clusterMax],j['cluster'])
valueLocal.rename('cluster',[clusterMax],j['cluster'])
else:
clusterFirst=None
for idx,y in enumerate(valueMatch):
if y['cluster'] not in clusterAffLocal:
clusterFirst=y['cluster']
break
#Comprend le cas où tous remplis.
if idx!=0:
snNumberLocal+=1
if clusterFirst is not None:
vNumberLocal=-1
valueMatch.rename('cluster',[clusterFirst],j['cluster'])
valueLocal.rename('cluster',[clusterFirst],j['cluster'])
if valueMatch[0]['cluster']!=j['cluster']:
snNumberLocal=-1
clusterAffLocal.add(j['cluster'])
#MAJ valueLocal
valueLocal=DiarTools.releaseFramesFromSegment(j,valueLocal)
valueLocal.append_seg(j)
for z in toRename:
valueLocal=DiarTools.releaseFrames(start=z['start'],stop=z['stop'],diar=valueLocal)
valueLocal.append_seg(z)
#for z in toRename:
# valueLocal=DiarTools.releaseFrames(start=z['start'],stop=z['stop'],diar=valueLocal)
# valueLocal.append_seg(z)
#Calculer le HCIQ pour le segment ref selectionné
correctionLocal=DiarTools.borderGetHumanCorrectionsToDo(valueMatch,diarRefLocal,diarUemLocal,False,clusterAffLocal,0,"__NONSPEECHREF__","__NONSPEECHHYP__")
assert correctionLocal["create_boundary"]==0
correctionLocal["create_boundary"]+=cbNumberLocal
correctionLocal["create_name"]+=cnNumberLocal
correctionLocal["select_name"]+=snNumberLocal
correctionLocal["validate"]+=vNumberLocal
HCIQLocal=correctionLocal["create_boundary"]*cb+correctionLocal["delete_boundary"]*db+correctionLocal["create_name"]*cn+correctionLocal["select_name"]*sn+correctionLocal["validate"]*v
HCIQLocal=self.correctionOrder["HCIQ"][key][i-1]+HCIQLocal
if not onlyDER:
if not modeNewAction:
correctionLocal=DiarTools.borderGetHumanCorrectionsToDo(valueMatch,diarRefLocal,diarUemLocal,False,clusterAffLocal,0,"__NONSPEECHREF__","__NONSPEECHHYP__")
assert correctionLocal["create_boundary"]==0
correctionLocal["create_boundary"]+=cbNumberLocal
correctionLocal["create_name"]+=cnNumberLocal
correctionLocal["select_name"]+=snNumberLocal
correctionLocal["validate"]+=vNumberLocal
else:
correctionLocal=dict()
correctionLocal["create_boundary"]=cbNumberLocal
correctionLocal["delete_boundary"]=0
correctionLocal["create_name"]=cnNumberLocal
if cbNumberLocal==0 and len(valueMatch)==1 and valueMatch[0]['cluster']==j['cluster']:
correctionLocal["select_name"]=0
correctionLocal["validate"]=1
else:
if cnNumberLocal==0:
correctionLocal["select_name"]=1
correctionLocal["validate"]=0
HCIQLocal=correctionLocal["create_boundary"]*cb+correctionLocal["delete_boundary"]*db+correctionLocal["create_name"]*cn+correctionLocal["select_name"]*sn+correctionLocal["validate"]*v
HCIQLocal=self.correctionOrder["HCIQ"][key][i-1]+HCIQLocal
#Calculer le DER pour le segment ref selectionné
with Toolbox.suppress_stdout():
......@@ -5267,19 +5293,30 @@ class Show(object):
#Vérifie si c'est le meilleur ratio, MAJ dans le cas contraire du choix du meilleur segment ref à corriger
currentDER=DERLocal.spk_conf+DERLocal.spk_miss+DERLocal.spk_fa
ratioLocal=exp((prevDER-currentDER)/(self.correctionOrder["HCIQ"][key][i-1]-HCIQLocal))
if isnan(ratioLocal):
assert prevDER==currentDER and self.correctionOrder["HCIQ"][key][i-1]==HCIQLocal
if self.correctionOrder["ratio"][key][i] is None or (not isnan(ratioLocal) and (isnan(self.correctionOrder["ratio"][key][i]) or ratioLocal<self.correctionOrder["ratio"][key][i])):
self.correctionOrder["diar"][key][i]=copy.deepcopy(valueLocal)
self.correctionOrder["DER"][key][i]=DERLocal
self.correctionOrder["HCIQ"][key][i]=HCIQLocal
self.correctionOrder["correction"][key][i]=correctionLocal
self.correctionOrder["correctedAreaHyp"][key][i]=valueMatchRaw
self.correctionOrder["correctedAreaRef"][key][i]=copy.deepcopy(j)
self.correctionOrder["ratio"][key][i]=ratioLocal
clusterAffTmp=clusterAffLocal
segTmp=j
if not onlyDER:
ratioLocal=exp((prevDER-currentDER)/(self.correctionOrder["HCIQ"][key][i-1]-HCIQLocal))
if isnan(ratioLocal):
assert prevDER==currentDER and self.correctionOrder["HCIQ"][key][i-1]==HCIQLocal
if self.correctionOrder["ratio"][key][i] is None or (not isnan(ratioLocal) and (isnan(self.correctionOrder["ratio"][key][i]) or ratioLocal<self.correctionOrder["ratio"][key][i])):
self.correctionOrder["diar"][key][i]=copy.deepcopy(valueLocal)
self.correctionOrder["DER"][key][i]=DERLocal
self.correctionOrder["HCIQ"][key][i]=HCIQLocal
self.correctionOrder["correction"][key][i]=correctionLocal
self.correctionOrder["correctedAreaHyp"][key][i]=valueMatchRaw
self.correctionOrder["correctedAreaRef"][key][i]=copy.deepcopy(j)
self.correctionOrder["ratio"][key][i]=ratioLocal
clusterAffTmp=clusterAffLocal
segTmp=j
else:
if self.correctionOrder["DER"][key][i] is None or currentDER<(self.correctionOrder["DER"][key][i].spk_conf+self.correctionOrder["DER"][key][i].spk_miss+self.correctionOrder["DER"][key][i].spk_fa):
self.correctionOrder["diar"][key][i]=copy.deepcopy(valueLocal)
self.correctionOrder["DER"][key][i]=DERLocal
self.correctionOrder["correction"][key][i]=correctionLocal
self.correctionOrder["correctedAreaHyp"][key][i]=valueMatchRaw
self.correctionOrder["correctedAreaRef"][key][i]=copy.deepcopy(j)
clusterAffTmp=clusterAffLocal
segTmp=j
if not lookForBestSeg:
break
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment