|
1 |
// Copyright © - ENS de Lyon - http://textometrie.ens-lyon.fr
|
|
2 |
//
|
|
3 |
// This file is part of the TXM platform.
|
|
4 |
//
|
|
5 |
// The TXM platform is free software: you can redistribute it and/or modify
|
|
6 |
// it under the terms of the GNU General Public License as published by
|
|
7 |
// the Free Software Foundation, either version 3 of the License, or
|
|
8 |
// (at your option) any later version.
|
|
9 |
//
|
|
10 |
// The TXM platform is distributed in the hope that it will be useful,
|
|
11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
// GNU General Public License for more details.
|
|
14 |
//
|
|
15 |
// You should have received a copy of the GNU General Public License
|
|
16 |
// along with the TXM platform. If not, see <http://www.gnu.org/licenses/>.
|
|
17 |
//
|
|
18 |
// $LastChangedDate: 2011-11-01 16:12:36 +0100 (mar., 01 nov. 2011) $
|
|
19 |
// $LastChangedRevision: 2049 $
|
|
20 |
// $LastChangedBy: sheiden $
|
|
21 |
//
|
|
22 |
|
|
23 |
package org.txm.scripts.importer.transcriber
|
|
24 |
import java.text.DecimalFormat;
|
|
25 |
// parameters
|
|
26 |
|
|
27 |
|
|
28 |
formater = DecimalFormat.getInstance(Locale.ENGLISH)
|
|
29 |
|
|
30 |
def getTurnDuration(element) // end < start
|
|
31 |
{
|
|
32 |
float d = 0;
|
|
33 |
|
|
34 |
def timeS = element.attributes()["startTime"]
|
|
35 |
def time = Float.parseFloat(timeS)
|
|
36 |
def timeE = element.attributes()["endTime"]
|
|
37 |
def time2 = Float.parseFloat(timeE)
|
|
38 |
|
|
39 |
d = time2 - time;
|
|
40 |
|
|
41 |
String content = element.text()
|
|
42 |
if (content.length() > 0) {
|
|
43 |
return d
|
|
44 |
} else {
|
|
45 |
return 0.0f;
|
|
46 |
}
|
|
47 |
}
|
|
48 |
|
|
49 |
public float getTotalTime(File infile) {
|
|
50 |
def timeResolution = 0.001
|
|
51 |
URL u = infile.toURI().toURL()
|
|
52 |
InputStream ins = u.openStream()
|
|
53 |
|
|
54 |
// Open input file
|
|
55 |
def slurper = new XmlParser();
|
|
56 |
slurper.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
|
|
57 |
def trs = slurper.parse(infile.toURI().toString())
|
|
58 |
|
|
59 |
float total = 0.0f;
|
|
60 |
// Then fix all <Sync>s of Turns
|
|
61 |
for (def section : trs.Episode.Section) {
|
|
62 |
|
|
63 |
section.Turn.each{ turn ->
|
|
64 |
int t = getTurnDuration(turn);
|
|
65 |
total += t
|
|
66 |
}
|
|
67 |
}
|
|
68 |
|
|
69 |
println "T "+infile.getName()+" : "+total
|
|
70 |
return total
|
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
/// MAIN ///
|
|
75 |
|
|
76 |
String userdir = System.getProperty("user.home")
|
|
77 |
//File inDirectory = new File(userdir, "xml/cedre") //
|
|
78 |
File inDirectory = new File(userdir, "xml/leman/final 2012-03-26")
|
|
79 |
|
|
80 |
float totalDirectory = 0;
|
|
81 |
for (File f : inDirectory.listFiles()) {
|
|
82 |
if (f.getName().endsWith(".trs")) {
|
|
83 |
float t = getTotalTime(f);
|
|
84 |
totalDirectory += t;
|
|
85 |
}
|
|
86 |
}
|
|
87 |
|
|
88 |
println "T "+inDirectory.getName()+" : "+totalDirectory+" s "+" -> "+(totalDirectory/60)+" m" +" -> "+(totalDirectory/60/60)+" h"
|