Commit 5745a8fa authored by Sulfyderz's avatar Sulfyderz
Browse files

[Error Update]:Improving the method automatonSegmentationAssignment from diar_tools.

parent 95406297
......@@ -10,4 +10,4 @@ from s4d.diar import Diar
from s4d.segmentation import sanity_check, bic_linear, div_gauss
from s4d.viterbi import Viterbi
__version__ = "0.0.1"
\ No newline at end of file
__version__ = "0.0.3"
......@@ -723,9 +723,8 @@ def automatonSegmentation(diarHyp,diarRef,diarUem=None,tolerance=0,modeNoGap=Fal
## diarFinal__clusterToDeleteAccordingToDiarRef: List of clusters to delete in the diarFinal only
## modeNoGap: Drops or not the segment actions (i.e. createSegment & deleteSegment)
## deleteBoundarySameConsecutiveSpk: Whether we delete a boundary for two consecutive segments with the same speaker
## deleteBoundaryMergeCluster: The action "delete a boundary" can merge two consecutive segments with different cluster names (it takes the name of the left/first segment)
def automatonSegmentationAssignment(diarHyp,diarRef,diarUem=None,tolerance=0,modeNoGap=False,diarFinal__clusterToDeleteAccordingToDiarRef=list(),deleteBoundarySameConsecutiveSpk=False,deleteBoundaryMergeCluster=False):
assert isinstance(diarHyp,Diar) and isinstance(diarRef,Diar) and isinstance(modeNoGap,bool) and (diarUem is None or isinstance(diarUem,Diar)) and isinstance(tolerance,numbers.Number) and isinstance(diarFinal__clusterToDeleteAccordingToDiarRef,list) and isinstance(deleteBoundarySameConsecutiveSpk,bool) and isinstance(deleteBoundaryMergeCluster,bool)
def automatonSegmentationAssignment(diarHyp,diarRef,diarUem=None,tolerance=0,modeNoGap=False,diarFinal__clusterToDeleteAccordingToDiarRef=list(),deleteBoundarySameConsecutiveSpk=False):
assert isinstance(diarHyp,Diar) and isinstance(diarRef,Diar) and isinstance(modeNoGap,bool) and (diarUem is None or isinstance(diarUem,Diar)) and isinstance(tolerance,numbers.Number) and isinstance(diarFinal__clusterToDeleteAccordingToDiarRef,list) and isinstance(deleteBoundarySameConsecutiveSpk,bool)
for u in diarFinal__clusterToDeleteAccordingToDiarRef:
assert isinstance(u,str)
......@@ -1045,47 +1044,6 @@ def automatonSegmentationAssignment(diarHyp,diarRef,diarUem=None,tolerance=0,mod
valueTmp=dropSegment(u,valueTmp)
elif u['start']>=(valueRef['stop']+tolerance):
break
# Gets the new segments, modified by previous steps
listHypRefSegment=list()
for y in valueTmp:
if Segment.intersection(y,valueRef) is not None:
if tolerance==0:
listHypRefSegment.append(y)
elif tolerance!=0 and y['start']>=(valueRef['start']-tolerance):
listHypRefSegment.append(y)
for idx,z in enumerate(listHypRefSegment):
# Affectation part
applyChange=False
if valueRef['cluster'] not in dictionary:
if z['cluster'] in actionsAssignmentCreateBis:
dictionary[copy.deepcopy(valueRef['cluster'])]='speakerManual'+str(cpt+1)
actionsAssignmentCreateBis.append('speakerManual'+str(cpt+1))
actionsAssignmentCreate.append([copy.deepcopy(valueRef['cluster']),'speakerManual'+str(cpt+1),copy.deepcopy(z)])
actionsIncrementalAssignmentCreateTurn.append([copy.deepcopy(valueRef['cluster']),'speakerManual'+str(cpt+1),copy.deepcopy(z)])
applyChange=True
cpt+=1
else:
dictionary[copy.deepcopy(valueRef['cluster'])]=copy.deepcopy(z['cluster'])
actionsAssignmentCreateBis.append(copy.deepcopy(z['cluster']))
actionsAssignmentCreate.append(copy.deepcopy([valueRef['cluster'],z['cluster'],copy.deepcopy(z)]))
actionsIncrementalAssignmentCreateTurn.append(copy.deepcopy([valueRef['cluster'],z['cluster'],copy.deepcopy(z)]))
else:
if z['cluster'] == dictionary[valueRef['cluster']]:
actionsAssignmentNothing.append(copy.deepcopy(z))
actionsIncrementalAssignmentNothingTurn.append(copy.deepcopy(z))
else:
actionsAssignmentChange.append(copy.deepcopy([dictionary[valueRef['cluster']],z]))
actionsIncrementalAssignmentChangeTurn.append(copy.deepcopy([dictionary[valueRef['cluster']],z]))
applyChange=True
if applyChange:
# Updates the diar for the merges afterward
segmentTmp=copy.deepcopy(z)
segmentTmp['cluster']=dictionary[valueRef['cluster']]
valueTmp=dropSegment(z,valueTmp)
valueTmp.append_seg(segmentTmp)
valueTmp.sort()
if deleteBoundaryMergeCluster:
break
if not perfectBoundary:
# Gets the new segments, modified by the previous steps
listHypRefSegment=list()
......@@ -1183,7 +1141,47 @@ def automatonSegmentationAssignment(diarHyp,diarRef,diarUem=None,tolerance=0,mod
valueTmp.sort()
newSegment,valueTmp=mergeSegment(newSegment,listTmp[y],valueTmp)
else:
newSegment=listTmp[y]
newSegment=listTmp[y]
# Gets the new segments, modified by previous steps
listHypRefSegment=list()
for y in valueTmp:
if Segment.intersection(y,valueRef) is not None:
if tolerance==0:
listHypRefSegment.append(y)
elif tolerance!=0 and y['start']>=(valueRef['start']-tolerance):
listHypRefSegment.append(y)
for idx,z in enumerate(listHypRefSegment):
# Affectation part
applyChange=False
if valueRef['cluster'] not in dictionary:
if z['cluster'] in actionsAssignmentCreateBis:
dictionary[copy.deepcopy(valueRef['cluster'])]='speakerManual'+str(cpt+1)
actionsAssignmentCreateBis.append('speakerManual'+str(cpt+1))
actionsAssignmentCreate.append([copy.deepcopy(valueRef['cluster']),'speakerManual'+str(cpt+1),copy.deepcopy(z)])
actionsIncrementalAssignmentCreateTurn.append([copy.deepcopy(valueRef['cluster']),'speakerManual'+str(cpt+1),copy.deepcopy(z)])
applyChange=True
cpt+=1
else:
dictionary[copy.deepcopy(valueRef['cluster'])]=copy.deepcopy(z['cluster'])
actionsAssignmentCreateBis.append(copy.deepcopy(z['cluster']))
actionsAssignmentCreate.append(copy.deepcopy([valueRef['cluster'],z['cluster'],copy.deepcopy(z)]))
actionsIncrementalAssignmentCreateTurn.append(copy.deepcopy([valueRef['cluster'],z['cluster'],copy.deepcopy(z)]))
else:
if z['cluster'] == dictionary[valueRef['cluster']]:
actionsAssignmentNothing.append(copy.deepcopy(z))
actionsIncrementalAssignmentNothingTurn.append(copy.deepcopy(z))
else:
actionsAssignmentChange.append(copy.deepcopy([dictionary[valueRef['cluster']],z]))
actionsIncrementalAssignmentChangeTurn.append(copy.deepcopy([dictionary[valueRef['cluster']],z]))
applyChange=True
if applyChange:
# Updates the diar for the merges afterward
segmentTmp=copy.deepcopy(z)
segmentTmp['cluster']=dictionary[valueRef['cluster']]
valueTmp=dropSegment(z,valueTmp)
valueTmp.append_seg(segmentTmp)
valueTmp.sort()
# Updates diarHyp
diarHyp=valueTmp
......
Markdown is supported
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