Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / importer / transcriber / CheckWhos.groovy @ 187

History | View | Annotate | Download (2.8 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.importer.transcriber
29

    
30
import java.io.File;
31
import javax.xml.stream.*;
32
import java.io.OutputStreamWriter;
33

    
34
// TODO: Auto-generated Javadoc
35
/**
36
 * The Class CheckWhos.
37
 */
38
class CheckWhos {
39
        
40
        /**
41
         * Test.
42
         *
43
         * @param xmlfile the xmlfile
44
         * @return true, if successful
45
         */
46
        public static boolean test(File xmlfile)
47
        {
48
                boolean ret = true;
49
                URL url = xmlfile.toURI().toURL();
50
                def inputData = url.openStream();
51
                XMLInputFactory factory = XMLInputFactory.newInstance();
52
                def parser = factory.createXMLStreamReader(inputData);
53
                
54
                String localname;
55
                String vSpeaker;
56
                
57
                List<String> localspeakers;
58
                
59
                for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) 
60
                {
61
                        switch (event) 
62
                        {
63
                                case XMLStreamConstants.START_ELEMENT:
64
                                        localname = parser.getLocalName();
65
                                        switch(localname)
66
                                        {
67
                                                case "Turn":
68
                                                
69
                                                        vSpeaker = parser.getAttributeValue(null, "speaker");                        
70
                                                        if(vSpeaker == null)
71
                                                        {
72
                                                                localspeakers = [];
73
                                                                vSpeaker = "N/A"
74
                                                        }
75
                                                        else
76
                                                                localspeakers = vSpeaker.split(" ")
77
                                                        break;
78
                                                
79
                                                case "Who":
80
                                                
81
                                                        int n = Integer.parseInt(parser.getAttributeValue(null, "nb")) -1;
82
                                                        if(localspeakers.size() <= n)
83
                                                        {
84
                                                                println "$xmlfile: Who error : line "+parser.getLocation().lineNumber+" col "+parser.getLocation().columnNumber+" in file "+xmlfile;
85
                                                                vSpeaker = "N/A";
86
                                                                ret = false;
87
                                                        }
88
                                                
89
                                                        break;
90
                                                        
91
                                        }
92
                        }
93
                }
94
                return ret;
95
        }
96
        
97
        /**
98
         * The main method.
99
         *
100
         * @param args the arguments
101
         */
102
        public static void main(String[] args)
103
        {
104
                String userdir = System.getProperty("user.home")
105
                for(File trsfile : new File(userdir, "xml/cedre").listFiles())
106
                {
107
                        if(trsfile.getName().endsWith(".trs"))
108
                        {
109
                                if(!CheckWhos.test(trsfile))
110
                                        println trsfile.getName()+" not ok"
111
                        }
112
                }
113
        }
114
        
115
}