Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / projects / nov13 / PrepareTranscriptionsMacro.groovy @ 3038

History | View | Annotate | Download (4 kB)

1
package org.txm.macro.projects.nov13
2

    
3
import java.time.LocalTime
4
import java.time.format.DateTimeFormatter
5
import org.txm.utils.*
6
import org.txm.utils.logger.*
7
import org.txm.macro.transcription.RecodeSpeakers
8

    
9
@Field @Option(name="vocapiaDirectory", usage="A Vocapia XML files directory to process", widget="Folder", required=false, def="")
10
                File vocapiaDirectory
11

    
12
@Field @Option(name="resultDirectory", usage="The result directory", widget="Folder", required=false, def="")
13
                File resultDirectory
14
                
15
@Field @Option(name="primarySpeakerIdRegex", usage="speaker ID of the primary speaker", widget="String", required=false, def="")
16
                String primarySpeakerIdRegex
17

    
18
@Field @Option(name="otherNonPrimarySpeakerId", usage="other non primary id of the other turns", widget="String", required=false, def="")
19
                String otherNonPrimarySpeakerId
20
                
21
@Field @Option(name="nonPrimarySpeakerIdRegex", usage="other non primary id of the other turns", widget="String", required=false, def="")
22
                String nonPrimarySpeakerIdRegex
23
                
24
@Field @Option(name="newSectionMarker", usage="section marker", widget="String", required=false, def="*#")
25
                String newSectionMarker
26

    
27
@Field @Option(name="debug", usage="speaker ID of the primary speaker", widget="Boolean", required=false, def="false")
28
                Boolean debug
29
                
30
@Field @Option(name="cleanWorkingDirectories", usage="Clean working directories is selected", widget="Boolean", required=false, def="true")
31
                Boolean cleanWorkingDirectories
32
                
33
if (!ParametersDialog.open(this)) return;
34

    
35
if (resultDirectory.equals(vocapiaDirectory)) {
36
        println "Result directory must differs from vocapiaDirectory: "+vocapiaDirectory
37
        return false;
38
}
39

    
40
resultDirectory.mkdirs();
41

    
42
println "PREPARING VOCAPIA FILES TO TRS FILES..."
43
File trsDirectory = new File(resultDirectory, "vocapia2trs")
44
trsDirectory.mkdir()
45
gse.runMacro(org.txm.macro.transcription.Vocapia2TranscriberMacro, ["vocapiaDirectory":vocapiaDirectory, "resultDirectory":trsDirectory])
46

    
47

    
48
println "DETECTING MARKED SECTIONS..."
49

    
50
trsFiles = trsDirectory.listFiles().findAll(){it.getName().toLowerCase().endsWith(".trs")}
51
if (trsFiles.size() == 0) {
52
        println "No XML file found in $trsDirectory"
53
        return false
54
}
55

    
56
File sectionsDirectory = new File(resultDirectory, "sections")
57
sectionsDirectory.mkdir()
58
gse.runMacro(org.txm.macro.transcription.SegmentTRSInSectionFromMarkerMacro, ["trsDirectory":trsDirectory, "resultDirectory":sectionsDirectory, "newSectionMarker":newSectionMarker, "debug":debug])
59

    
60

    
61
println "CREATING THE 'OTHER' TURNS..."
62

    
63
trsFiles = sectionsDirectory.listFiles().findAll(){it.getName().toLowerCase().endsWith(".trs")}
64
if (trsFiles.size() == 0) {
65
        println "No XML file found in $sectionsDirectory"
66
        return false
67
}
68

    
69
File otherDirectory = new File(resultDirectory, "otherturns")
70
otherDirectory.mkdir()
71
cpb = new ConsoleProgressBar(trsFiles.size())
72
for (File file : trsFiles) {
73
        cpb.tick()
74
        
75
        CreateTheOtherTurns fixer = new CreateTheOtherTurns(file, primarySpeakerIdRegex, otherNonPrimarySpeakerId, debug)
76
        String name = FileUtils.stripExtension(file)
77
        File outFile = new File(otherDirectory, name+".trs")
78
        
79
        if (!fixer.process(outFile)) {
80
                println "WARNING: ERROR WHILE PROCESSING: "+file
81
                if (debug) {println "DEBUG ACTIVATED -> STOP"; return;}
82
        }
83
}
84
cpb.done()
85

    
86

    
87
println "NORMALIZING LOCUTORS..."
88

    
89
trsFiles = otherDirectory.listFiles().findAll(){it.getName().toLowerCase().endsWith(".trs")}
90
if (trsFiles.size() == 0) {
91
        println "No XML file found in $otherDirectory"
92
        return false
93
}
94

    
95
cpb = new ConsoleProgressBar(trsFiles.size())
96
for (File file : trsFiles) {
97
        cpb.tick()
98
        
99
        File outFile = new File(resultDirectory, file.getName())
100
        RecodeSpeakers fixer = new RecodeSpeakers(file, outFile, nonPrimarySpeakerIdRegex, null, otherNonPrimarySpeakerId, otherNonPrimarySpeakerId)
101
        
102
        if (!fixer.process()) {
103
                println "WARNING: ERROR WHILE PROCESSING: "+file
104
                if (debug) {println "DEBUG ACTIVATED -> STOP"; return;}
105
        }
106
}
107
cpb.done()
108

    
109
if (!cleanWorkingDirectories) {
110
        otherDirectory.deleteDir()
111
        trsDirectory.deleteDir()
112
        sectionsDirectory.deleteDir()
113
}
114

    
115
println "Done: "+trsFiles.size()+" files processed. Result files in $resultDirectory"