root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / importer / transcriber / compiler.groovy @ 2361
History | View | Annotate | Download (18.3 kB)
1 |
// Copyright © 2010-2013 ENS de Lyon.
|
---|---|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice
|
4 |
// Sophia Antipolis, University of Paris 3.
|
5 |
//
|
6 |
// The TXM platform is free software: you can redistribute it
|
7 |
// and/or modify it under the terms of the GNU General Public
|
8 |
// License as published by the Free Software Foundation,
|
9 |
// either version 2 of the License, or (at your option) any
|
10 |
// later version.
|
11 |
//
|
12 |
// The TXM platform is distributed in the hope that it will be
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
15 |
// PURPOSE. See the GNU General Public License for more
|
16 |
// details.
|
17 |
//
|
18 |
// You should have received a copy of the GNU General
|
19 |
// Public License along with the TXM platform. If not, see
|
20 |
// http://www.gnu.org/licenses.
|
21 |
//
|
22 |
//
|
23 |
//
|
24 |
// $LastChangedDate:$
|
25 |
// $LastChangedRevision:$
|
26 |
// $LastChangedBy:$
|
27 |
//
|
28 |
package org.txm.scripts.importer.transcriber
|
29 |
|
30 |
import java.io.File; |
31 |
|
32 |
import javax.xml.stream.*; |
33 |
|
34 |
import java.io.OutputStreamWriter; |
35 |
import java.util.LinkedHashMap; |
36 |
import org.txm.objects.* |
37 |
import org.txm.searchengine.cqp.corpus.* |
38 |
import org.txm.importer.cwb.CwbEncode |
39 |
import org.txm.importer.cwb.CwbMakeAll |
40 |
import org.txm.importer.cwb.CwbProcess; |
41 |
import org.txm.importer.cwb.PatchCwbRegistry; |
42 |
import org.txm.utils.ConsoleProgressBar |
43 |
import org.txm.utils.Pair; |
44 |
|
45 |
/**
|
46 |
* The Class compiler.
|
47 |
*/
|
48 |
class compiler { |
49 |
|
50 |
boolean ADD_TEXTID_TO_REF = true |
51 |
|
52 |
/** The input data. */
|
53 |
private def inputData; |
54 |
|
55 |
/** The factory. */
|
56 |
private def factory; |
57 |
|
58 |
/** The parser. */
|
59 |
private XMLStreamReader parser;
|
60 |
|
61 |
/** The output. */
|
62 |
OutputStreamWriter output;
|
63 |
|
64 |
/** The basename. */
|
65 |
String corpusname;
|
66 |
|
67 |
/** The projectname. */
|
68 |
String projectname
|
69 |
|
70 |
/** The outdir. */
|
71 |
String outdir;
|
72 |
|
73 |
/** The debug. */
|
74 |
boolean debug = false; |
75 |
|
76 |
/** The removeinterviewers. */
|
77 |
boolean removeinterviewers = false; |
78 |
|
79 |
/** The trans. */
|
80 |
HashMap<String, ArrayList<Pair<String, String>>> trans; |
81 |
|
82 |
/** The speakers. */
|
83 |
HashMap<String, ArrayList<Pair<String, String>>> speakers; |
84 |
|
85 |
/** The speakersname. */
|
86 |
HashMap<String, String> speakersname = new HashMap<String, String>(); |
87 |
|
88 |
/** The topics. */
|
89 |
HashMap<String, ArrayList<Pair<String, String>>> topics; |
90 |
|
91 |
|
92 |
/** The interviewers. */
|
93 |
ArrayList<String> interviewers = []; |
94 |
static HashSet<String> sectionAttrs; |
95 |
|
96 |
/** The anatypes. */
|
97 |
private static anatypes = [] |
98 |
private static anavalues = [:] |
99 |
|
100 |
/**
|
101 |
* Removes the interviewers.
|
102 |
*
|
103 |
* @param value the value
|
104 |
* @return the java.lang. object
|
105 |
*/
|
106 |
public removeInterviewers(boolean value) { |
107 |
this.removeinterviewers = value;
|
108 |
} |
109 |
|
110 |
File cqpFile
|
111 |
/**
|
112 |
* Run.
|
113 |
*
|
114 |
* @param xmlfiles the xmlfiles
|
115 |
* @param basename the basename
|
116 |
* @param projectname the projectname
|
117 |
* @param outdir the outdir
|
118 |
* @return true, if successful
|
119 |
*/
|
120 |
public boolean run(Project project, List<File> xmlfiles, String corpusname, String projectname, File binDir) { |
121 |
|
122 |
//println "run compiler with $xmlfiles, $basename and $outdir"
|
123 |
this.outdir = binDir;
|
124 |
this.corpusname = corpusname;
|
125 |
this.projectname = projectname;
|
126 |
|
127 |
anatypes = ["event"] // reset |
128 |
anavalues = [:] // reset
|
129 |
|
130 |
sectionAttrs = new HashSet<String>() // reset section attributs set |
131 |
|
132 |
CorpusBuild corpus = project.getCorpusBuild(project.getName(), MainCorpus.class); |
133 |
if (corpus != null) { |
134 |
if (project.getDoUpdate()) {
|
135 |
corpus.clean(); // remove old files
|
136 |
} else {
|
137 |
corpus.delete(); // remove old files and TXMResult children
|
138 |
} |
139 |
} else {
|
140 |
corpus = new MainCorpus(project);
|
141 |
corpus.setID(project.getName()); |
142 |
corpus.setName(project.getName()); |
143 |
} |
144 |
corpus.setDescription("Built with the XML-TRS import module");
|
145 |
|
146 |
cqpFile = new File(binDir,"cqp/"+corpusname+".cqp"); |
147 |
cqpFile.delete() |
148 |
new File(binDir,"cqp").mkdirs() |
149 |
new File(binDir,"data").mkdirs() |
150 |
new File(binDir,"registry").mkdirs() |
151 |
|
152 |
// get all anatypes
|
153 |
for (File f : xmlfiles) { |
154 |
getAnaTypes(f) |
155 |
} |
156 |
//println "ANATYPES: "+anatypes
|
157 |
if (!createOutput(cqpFile)) return false; |
158 |
output.write("<txmcorpus lang=\"fr\">\n")
|
159 |
output.close(); |
160 |
|
161 |
println("Compiling "+xmlfiles.size()+" files") |
162 |
ConsoleProgressBar cpb = new ConsoleProgressBar(xmlfiles.size())
|
163 |
for (File txmFile :xmlfiles) { |
164 |
if (txmFile.exists()) {
|
165 |
cpb.tick() |
166 |
if (!process(txmFile)) {
|
167 |
println("Failed to compile "+txmFile)
|
168 |
} |
169 |
} |
170 |
} |
171 |
cpb.done() |
172 |
if (!createOutput(cqpFile)) return false; |
173 |
output.write("</txmcorpus>\n")
|
174 |
output.close(); |
175 |
|
176 |
//2- Import into CWB
|
177 |
File registryFile = new File(binDir, "registry/"+corpusname.toLowerCase()) |
178 |
File dataDir = new File(binDir, "data/$corpusname") |
179 |
|
180 |
new File(binDir, "registry").mkdir(); |
181 |
if (!new File(binDir, "registry").exists()) { |
182 |
println "Can't create registry directory"
|
183 |
return false; |
184 |
} |
185 |
|
186 |
if (!(CwbEncode.isExecutableAvailable() && CwbMakeAll.isExecutableAvailable())) {
|
187 |
println ("Error: CWB executables not well set.")
|
188 |
return false; |
189 |
} |
190 |
CwbEncode cwbEn = new CwbEncode();
|
191 |
CwbMakeAll cwbMa = new CwbMakeAll();
|
192 |
cwbEn.setDebug(debug); |
193 |
cwbMa.setDebug(debug); |
194 |
|
195 |
String uAttr = "u:0+spkid+spk+scope+accent+s+time+check+dialect+type"; |
196 |
String textAttr ="text:0+base+project" |
197 |
if (trans != null) { |
198 |
for (String key : trans.keySet()) { |
199 |
for (Pair p : trans.get(key)) {
|
200 |
if (ignoreTranscriberMetadata) {
|
201 |
String meta =p.getFirst();
|
202 |
if ( meta != "scribe" && meta != "audio_filename" && |
203 |
meta != "version" && meta != "version_date") |
204 |
textAttr+="+"+meta
|
205 |
} else {
|
206 |
textAttr+="+"+p.getFirst()
|
207 |
} |
208 |
} |
209 |
break;
|
210 |
} |
211 |
} |
212 |
|
213 |
String sectionAttr = "div:0" // "div:0+id+topic+endtime+starttime+type" |
214 |
for (String attr : sectionAttrs) { |
215 |
sectionAttr += "+"+attr
|
216 |
} |
217 |
|
218 |
List<String> pargs = ["spk", "ref", "id", "entitytype", "entityid"] |
219 |
for (String ana : anatypes) pargs.add(ana) |
220 |
|
221 |
String[] pAttributes = pargs |
222 |
|
223 |
String[] sAttributes = ["txmcorpus:0+lang", uAttr , textAttr, "event:0+id+desc+type+extent", sectionAttr, "sp:0+id+speaker+endtime+starttime+overlap+time"]; |
224 |
|
225 |
println "pAttributes: $pAttributes"
|
226 |
println "sAttributes: $sAttributes"
|
227 |
//return;
|
228 |
try {
|
229 |
cwbEn.run(dataDir.getAbsolutePath(), |
230 |
cqpFile.getAbsolutePath(), |
231 |
registryFile.getAbsolutePath(), pAttributes, sAttributes); |
232 |
if (!registryFile.exists()) {
|
233 |
println "Error: The registry file was not created: $regPath. See https://groupes.renater.fr/wiki/txm-users/public/faq"
|
234 |
return false; |
235 |
} |
236 |
cwbMa.run(corpusname, registryFile.getParent()); |
237 |
|
238 |
} catch (Exception ex) {System.out.println(ex); return false;} |
239 |
|
240 |
return true; |
241 |
} |
242 |
|
243 |
/**
|
244 |
* Creates the output.
|
245 |
*
|
246 |
* @param dirPathName the dir path name
|
247 |
* @param fileName the file name
|
248 |
* @return true, if successful
|
249 |
*/
|
250 |
private boolean createOutput(File f){ |
251 |
try {
|
252 |
//File f = new File(dirPathName, fileName)
|
253 |
output = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(f,f.exists())) , "UTF-8"); |
254 |
return true; |
255 |
} catch (Exception e) { |
256 |
System.out.println(e.getLocalizedMessage());
|
257 |
return false; |
258 |
} |
259 |
} |
260 |
|
261 |
/** The text_id. */
|
262 |
String text_id
|
263 |
|
264 |
/** The u opened. */
|
265 |
boolean uOpened = false; |
266 |
|
267 |
/** The idturn. */
|
268 |
int idturn = 1; |
269 |
|
270 |
/** The idsection. */
|
271 |
int idsection = 1; |
272 |
|
273 |
/** The idu. */
|
274 |
int idu = 1; |
275 |
|
276 |
/** The idevent. */
|
277 |
int idevent = 1; |
278 |
|
279 |
/** The events. */
|
280 |
List<String> events = []; |
281 |
static int vEntityId = 0; |
282 |
static int vEntityIdCount = 1; |
283 |
|
284 |
/**
|
285 |
* Process.
|
286 |
*
|
287 |
* @param xmlfile the xmlfile
|
288 |
* @return true, if successful
|
289 |
*/
|
290 |
private boolean process(File xmlfile) { |
291 |
text_id = xmlfile.getName(); |
292 |
text_id = text_id.substring(0, text_id.length() -4); |
293 |
|
294 |
idturn = 1;
|
295 |
idsection = 1;
|
296 |
idu = 1;
|
297 |
|
298 |
boolean flagAna;
|
299 |
boolean flagForm;
|
300 |
boolean flagWord;
|
301 |
String vWord=""; |
302 |
String vForm=""; |
303 |
String vAna=""; |
304 |
String vEvents = "N/A"; |
305 |
String vEntityType = "N/A" |
306 |
String wordid= ""; |
307 |
//def wordattributes = [:];
|
308 |
String anatype = ""; |
309 |
String anavalue = ""; |
310 |
|
311 |
String formatedTime;
|
312 |
|
313 |
LinkedHashMap<String, String> anahash = new LinkedHashMap<String, String>(); |
314 |
String currentType;
|
315 |
|
316 |
URL url = xmlfile.toURI().toURL();
|
317 |
inputData = url.openStream(); |
318 |
factory = XMLInputFactory.newInstance(); |
319 |
parser = factory.createXMLStreamReader(inputData); |
320 |
String filename = xmlfile.getName()
|
321 |
String textid = filename.substring(0, filename.length() - 4); |
322 |
|
323 |
createOutput(cqpFile); |
324 |
String localname;
|
325 |
|
326 |
//get all metadatas declared before Episode tag
|
327 |
speakers = new HashMap<String, ArrayList<Pair<String, String>>>(); |
328 |
trans = new HashMap<String, ArrayList<Pair<String, String>>>(); |
329 |
topics = new HashMap<String, ArrayList<Pair<String, String>>>(); |
330 |
//println "parse infos"
|
331 |
parseInfos(); |
332 |
|
333 |
// println "Trans: $trans"
|
334 |
// println "Topics: $topics"
|
335 |
// println "Speakers: $speakers"
|
336 |
// def transproperties = ""
|
337 |
// for (String key : trans.keySet()) {
|
338 |
// for (Pair p : trans.get(key))
|
339 |
// transproperties+="\t"+p.getSecond();
|
340 |
// break;
|
341 |
// }
|
342 |
// println "Trans properties: "+transproperties
|
343 |
List<String> localspeakers; |
344 |
|
345 |
|
346 |
for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { |
347 |
//print "event: "+event +" "
|
348 |
switch (event) {
|
349 |
case XMLStreamConstants.START_ELEMENT:
|
350 |
localname = parser.getLocalName(); |
351 |
//println localname
|
352 |
switch(localname) {
|
353 |
case "div": |
354 |
output.write("<div");
|
355 |
for (int i = 0 ; i < parser.getAttributeCount() ; i ++) { |
356 |
String name = parser.getAttributeLocalName(i).replace("_","").toLowerCase() |
357 |
output.write(" "+name+"=\""+parser.getAttributeValue(i)+"\""); |
358 |
sectionAttrs << name |
359 |
} |
360 |
output.write ">\n"
|
361 |
break;
|
362 |
case "sp": |
363 |
output.write("<sp");
|
364 |
writeAttributes(); |
365 |
output.write ">\n"
|
366 |
break;
|
367 |
case "u": |
368 |
output.write("<u");
|
369 |
for (int i = 0 ; i < parser.getAttributeCount() ; i ++) { |
370 |
String name = parser.getAttributeLocalName(i).replace("_","").toLowerCase() |
371 |
output.write(" "+name+"=\""+parser.getAttributeValue(i)+"\""); |
372 |
if (name == "time") formatedTime = parser.getAttributeValue(i) |
373 |
else if (name == "spk") u_name = parser.getAttributeValue(i) |
374 |
} |
375 |
output.write ">\n"
|
376 |
break;
|
377 |
case "event": |
378 |
output.write("<event");
|
379 |
writeAttributes(); |
380 |
output.write ">\n"
|
381 |
|
382 |
if (parser.getAttributeValue(null, "type") == "entities") { |
383 |
if (parser.getAttributeValue(null, "extent") == "begin") { |
384 |
vEntityType = parser.getAttributeValue(null, "desc"); |
385 |
vEntityId = vEntityIdCount++; |
386 |
} else {
|
387 |
vEntityType = "N/A";
|
388 |
vEntityId = 0;
|
389 |
} |
390 |
} else if (parser.getAttributeValue(null, "type") == "pronounce") { |
391 |
if (parser.getAttributeValue(null, "extent") == "begin") |
392 |
events.add(parser.getAttributeValue(null, "desc")) |
393 |
else if (parser.getAttributeValue(null, "extent") == "end") |
394 |
events.remove(parser.getAttributeValue(null, "desc")) |
395 |
vEvents = "";
|
396 |
for (String s : events) |
397 |
vEvents += s+"#";
|
398 |
if (vEvents.length() > 0) |
399 |
vEvents = vEvents.substring(0, vEvents.length()-1); |
400 |
else
|
401 |
vEvents = ""
|
402 |
} |
403 |
break;
|
404 |
case "w": |
405 |
for (int i = 0 ; i < parser.getAttributeCount(); i++) { |
406 |
if (parser.getAttributeLocalName(i).equals("id")) { |
407 |
wordid = parser.getAttributeValue(i); |
408 |
break;
|
409 |
} |
410 |
} |
411 |
anavalues = [:]; |
412 |
break;
|
413 |
case "form": |
414 |
flagForm = true;
|
415 |
vForm = "";
|
416 |
vAna ="";
|
417 |
break;
|
418 |
case "ana": |
419 |
flagAna = true;
|
420 |
anavalue = "";
|
421 |
for (int i = 0 ; i < parser.getAttributeCount(); i++) |
422 |
if (parser.getAttributeLocalName(i).equals("type")) { |
423 |
anatype = parser.getAttributeValue(i).substring(1);//remove the # |
424 |
break;
|
425 |
} |
426 |
break;
|
427 |
} |
428 |
break;
|
429 |
case XMLStreamConstants.END_ELEMENT:
|
430 |
localname = parser.getLocalName(); |
431 |
|
432 |
switch (localname) {
|
433 |
case "text": |
434 |
output.write("</text>\n")
|
435 |
break;
|
436 |
case "Topics": |
437 |
break;
|
438 |
case "Topic": |
439 |
break;
|
440 |
case "Speakers": |
441 |
break;
|
442 |
case "Speaker": |
443 |
break;
|
444 |
case "Episode": |
445 |
break;
|
446 |
case "div": |
447 |
output.write("</div>\n")
|
448 |
break;
|
449 |
case "sp": |
450 |
output.write("</sp>\n")
|
451 |
break;
|
452 |
case "u": |
453 |
output.write("</u>\n")
|
454 |
break;
|
455 |
case "event": |
456 |
output.write("</event>\n")
|
457 |
break;
|
458 |
case "form": |
459 |
flagForm = false;
|
460 |
break;
|
461 |
case "ana": |
462 |
anavalues.put(anatype, anavalue) |
463 |
flagAna = false;
|
464 |
break;
|
465 |
case "w": |
466 |
// concat spk id and ref
|
467 |
String isEnq = (interviewers.contains(u_name))?"*":""; |
468 |
String ref = (u_name+", "+formatedTime+""+isEnq) |
469 |
if (ADD_TEXTID_TO_REF) ref = textid+", "+ref |
470 |
vForm +="\t"+u_name+"\t"+ref |
471 |
|
472 |
// concat entity and entity ID
|
473 |
vAna+= "\t"+vEntityType+"\t"+vEntityId; |
474 |
|
475 |
//concat ana values
|
476 |
for (String type : anatypes) { |
477 |
def v = anavalues.get(type);
|
478 |
if (v == null) v = ""; |
479 |
|
480 |
if ("event" == type) { |
481 |
if (v.length() > 0) |
482 |
vAna+="\t#"+v;
|
483 |
else
|
484 |
vAna+="\t";
|
485 |
|
486 |
//concat <Event> values
|
487 |
if (vEvents != null && vEvents.length() > 0 && vEvents != "N/A") |
488 |
vAna += "#"+vEvents;
|
489 |
} else {
|
490 |
vAna+="\t"+v;
|
491 |
} |
492 |
} |
493 |
|
494 |
|
495 |
vForm = vForm.replaceAll("\n", "").replaceAll("&", "&").replaceAll("<", "<"); |
496 |
|
497 |
if (removeinterviewers) {
|
498 |
if (!interviewers.contains(u_name))
|
499 |
output.write(vForm+"\t"+wordid+vAna+"\n"); |
500 |
} else {
|
501 |
output.write(vForm+"\t"+wordid+vAna+"\n"); |
502 |
} |
503 |
|
504 |
vAna = "";
|
505 |
vForm = "";
|
506 |
break;
|
507 |
} |
508 |
break
|
509 |
case XMLStreamConstants.CHARACTERS:
|
510 |
if (flagForm)
|
511 |
vForm += parser.getText().trim(); |
512 |
if (flagAna) {
|
513 |
anavalue += parser.getText().trim(); |
514 |
} |
515 |
break;
|
516 |
} |
517 |
} |
518 |
|
519 |
parser.close(); |
520 |
inputData.close(); |
521 |
output.close(); |
522 |
return true; |
523 |
} |
524 |
|
525 |
/** The u_name. */
|
526 |
String u_name;
|
527 |
|
528 |
/**
|
529 |
* Write start tag.
|
530 |
*/
|
531 |
private void writeStartTag() { |
532 |
output.write("<"+parser.getLocalName());
|
533 |
writeAttributes(); |
534 |
output.write ">\n"
|
535 |
} |
536 |
|
537 |
/**
|
538 |
* Write attributes.
|
539 |
*/
|
540 |
private void writeAttributes() { |
541 |
for (int i = 0 ; i < parser.getAttributeCount() ; i ++) { |
542 |
output.write(" "+parser.getAttributeLocalName(i).replace("_","").toLowerCase()+"=\""+parser.getAttributeValue(i)+"\""); |
543 |
} |
544 |
} |
545 |
|
546 |
private void getAnaTypes(File xmlFile) { |
547 |
inputData = xmlFile.toURI().toURL().openStream(); |
548 |
factory = XMLInputFactory.newInstance(); |
549 |
parser = factory.createXMLStreamReader(inputData); |
550 |
String ana = "ana" |
551 |
HashSet<String> types = new HashSet<String>(); |
552 |
for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { |
553 |
if (event == XMLStreamConstants.START_ELEMENT) { // start elem |
554 |
if (ana.equals(parser.getLocalName())) { // ana elem |
555 |
for (int i = 0 ; i < parser.getAttributeCount(); i++) { // find @type |
556 |
if ("type".equals(parser.getAttributeLocalName(i))) { // @type |
557 |
types.add(parser.getAttributeValue(i).substring(1)); //remove the # |
558 |
break;
|
559 |
} |
560 |
} |
561 |
} |
562 |
} |
563 |
} |
564 |
if (parser != null) parser.close(); |
565 |
if (inputData != null) inputData.close(); |
566 |
|
567 |
for (String type : types) |
568 |
if (!anatypes.contains(type))
|
569 |
anatypes << type |
570 |
} |
571 |
|
572 |
/**
|
573 |
* Write start tag.
|
574 |
*
|
575 |
* @param id the id
|
576 |
*/
|
577 |
private void writeStartTag(int id) { |
578 |
output.write("<"+parser.getLocalName().toLowerCase());
|
579 |
output.write(" id=\""+id+"\""); |
580 |
writeAttributes(); |
581 |
output.write ">\n"
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* Write end tag.
|
586 |
*/
|
587 |
private void writeEndTag() { |
588 |
output.write("</"+parser.getLocalName().toLowerCase()+">\n"); |
589 |
} |
590 |
|
591 |
/** The ignore transcriber metadata. */
|
592 |
boolean ignoreTranscriberMetadata = false; |
593 |
|
594 |
/**
|
595 |
* Sets the ignore transcriber metadata.
|
596 |
*
|
597 |
* @param state the new ignore transcriber metadata
|
598 |
*/
|
599 |
public void setIgnoreTranscriberMetadata(boolean state) { |
600 |
this.ignoreTranscriberMetadata = state;
|
601 |
} |
602 |
|
603 |
/**
|
604 |
* Parses the infos.
|
605 |
*/
|
606 |
private void parseInfos() { //until tag Episode |
607 |
String localname;
|
608 |
//assert(parser != null);
|
609 |
for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { |
610 |
if (event == XMLStreamConstants.START_ELEMENT) {
|
611 |
localname = parser.getLocalName(); |
612 |
switch (localname) {
|
613 |
case "text": |
614 |
output.write("<text project=\""+projectname+"\" base=\""+corpusname+"\"") |
615 |
for (int i = 0 ; i < parser.getAttributeCount() ; i ++) { |
616 |
if (ignoreTranscriberMetadata) {
|
617 |
if (parser.getAttributeLocalName(i) != "scribe" && |
618 |
parser.getAttributeLocalName(i) != "audio_filename" &&
|
619 |
parser.getAttributeLocalName(i) != "version" &&
|
620 |
parser.getAttributeLocalName(i) != "version_date")
|
621 |
output.write(" "+parser.getAttributeLocalName(i).replace("_","").toLowerCase()+"=\""+parser.getAttributeValue(i)+"\""); |
622 |
} else {
|
623 |
output.write(" "+parser.getAttributeLocalName(i).replace("_","").toLowerCase()+"=\""+parser.getAttributeValue(i)+"\""); |
624 |
} |
625 |
} |
626 |
|
627 |
output.write ">\n"
|
628 |
|
629 |
ArrayList list = new ArrayList<Pair<String, String>>() |
630 |
trans.put("trans", list);
|
631 |
|
632 |
for (int i = 0 ; i < parser.getAttributeCount() ; i ++) { |
633 |
list.add(new Pair(parser.getAttributeLocalName(i).replace("_","").toLowerCase(), parser.getAttributeValue(i))); |
634 |
if(parser.getAttributeLocalName(i).startsWith("enq")) |
635 |
interviewers.add(parser.getAttributeValue(i)); |
636 |
} |
637 |
return
|
638 |
case "Topic": |
639 |
String id = parser.getAttributeValue(null, "id"); |
640 |
if (id != null) { |
641 |
ArrayList list = new ArrayList<Pair<String, String>>() |
642 |
topics.put(id, list); |
643 |
} else {
|
644 |
println "found tag $localname with no id"
|
645 |
} |
646 |
break;
|
647 |
case "Speaker": |
648 |
//case "Trans":
|
649 |
String id = parser.getAttributeValue(null, "id"); |
650 |
String name = parser.getAttributeValue(null, "name"); |
651 |
if (id != null && name != null) { |
652 |
speakersname.put(id, name); |
653 |
} else {
|
654 |
println "found tag $localname with no id ($id)or name ($name)"
|
655 |
return;
|
656 |
} |
657 |
if (id != null) { |
658 |
ArrayList list = new ArrayList<Pair<String, String>>() |
659 |
speakers.put(id, list); |
660 |
|
661 |
for (int i = 0 ; i < parser.getAttributeCount() ; i ++) { |
662 |
list.add(new Pair(parser.getAttributeLocalName(i), parser.getAttributeValue(i)));
|
663 |
} |
664 |
} else {
|
665 |
println "found tag $localname with no id"
|
666 |
return;
|
667 |
} |
668 |
break;
|
669 |
} |
670 |
} |
671 |
} |
672 |
} |
673 |
|
674 |
/**
|
675 |
* Sets the debug.
|
676 |
*/
|
677 |
public void setDebug() { |
678 |
debug = true;
|
679 |
} |
680 |
|
681 |
} |