Revision 2

projets/CMC2ELAN/src/TEICMC2TRS.groovy (revision 2)
1

  
2

  
3
import java.io.File;
4
import java.net.URL;
5

  
6
import javax.xml.stream.*;
7
import java.text.SimpleDateFormat;
8
import java.util.Date;
9

  
10
public class TEICMC2TRS extends StaxIdentityParser {
11

  
12
	File outputDirectory;
13
	String loc;
14

  
15
	public TEICMC2TRS(File inputFile, String loc) {
16
		super(inputFile);
17
		this.loc = loc;
18
	}
19
	
20
	boolean inBody = false
21
	boolean inName = false;
22
	String filenameValue = "";
23
	boolean inDate = false;
24
	String dateValue = "";
25
	boolean inTime = false;
26
	String timeValue = "";
27
	boolean inPosting = false;
28
	String postingID = ""
29
	String postingWho = ""
30
	boolean inP;
31
	String content = ""
32

  
33
	protected void processStartElement() {
34
		if (parser.getLocalName() == "body") { // write TRS HEADER
35
			inBody = true
36
			writer.writeStartElement("Trans");
37
			writer.writeAttribute("version","10");
38
			writer.writeAttribute("audio_filename","");
39
			writer.writeAttribute("scribe","");
40
			writer.writeAttribute("version_date","");
41
			
42
			writer.writeStartElement("Topics");
43
			writer.writeEndElement(); //Topics
44
			writer.writeStartElement("Speakers");
45
			writer.writeStartElement("Speaker");
46
			writer.writeAttribute("id",loc);
47
			writer.writeAttribute("name",loc);
48
			writer.writeAttribute("check","");
49
			writer.writeAttribute("dialect","");
50
			writer.writeAttribute("scope","");
51
			writer.writeEndElement(); //Speaker
52
			writer.writeEndElement(); //Speakers
53
			
54
			writer.writeStartElement("Episode");
55
			writer.writeStartElement("Section");
56
			writer.writeAttribute("type","report");
57
			writer.writeAttribute("startTime","");
58
			writer.writeAttribute("endTime","");
59
			
60
		} else if (parser.getLocalName() == "posting") {
61
			inPosting = true
62
			for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
63
				if (parser.getAttributeLocalName(i) == "who") {
64
					postingWho = parser.getAttributeValue(i)
65
				} else if (parser.getAttributeLocalName(i) == "type") {
66
					postingID = parser.getAttributeValue(i)
67
				}
68
			}
69
			return;
70
		} else if(inPosting) {
71
			if ( parser.getLocalName() == "dateline") {
72
			} else if (parser.getLocalName() == "name") {
73
				inName = true
74
				filenameValue = ""
75
			} else if (parser.getLocalName() == "date") {
76
				inDate = true;
77
				dateValue = ""
78
			} else if (parser.getLocalName() == "time") {
79
				inTime = true;
80
				timeValue = ""
81
			} else if (parser.getLocalName() == "p") {
82
				inP = true;
83
				content = ""
84
			}
85
			return;
86
		}
87
	}
88

  
89
	protected void processCharacters() {
90
		if (inPosting) {
91
			if (inName) {
92
				filenameValue += parser.getText();
93
				return;
94
			} else if (inDate) {
95
				dateValue += parser.getText();
96
				return;
97
			} else if (inTime) {
98
				timeValue += parser.getText();
99
				return;
100
			} else if (inP) {
101
				content += parser.getText();
102
				return;
103
			}
104
		}
105

  
106
	}
107

  
108
	SimpleDateFormat formatter = new SimpleDateFormat("HHmmss");
109
	Date from = null// use only the first from
110
	protected void processEndElement()
111
	{
112
		if (parser.getLocalName() == "body") { // write TRS HEADER
113
			writer.writeEndElement(); //Section
114
			writer.writeEndElement(); //Episode
115
			writer.writeEndElement(); //Trans
116
		} else if (inPosting) {
117
			if (inPosting && parser.getLocalName() == "name") {
118
				inName = false;
119
			} else if (parser.getLocalName() == "date") {
120
				inDate = false;
121
			} else if (parser.getLocalName() == "p") {
122
				inP = false;
123
			} else if (parser.getLocalName() == "time") {
124
				inTime = false;
125
			} else if (parser.getLocalName() == "posting") {
126
				if (writer == null) {
127
					println "Error Houston !!! with loc=$postingWho date=$dateValue at="parser.getLocation()
128
					return;
129
				}
130
				// write Turn
131
				//println "write Turn"
132
				
133
				if (from == null) {
134
					int i1 = filenameValue.indexOf(".flv")
135
					int i2 = i1-6
136
					String date1 = filenameValue.substring(i2, i1)
137
					from = formatter.parse(date1);
138
				}
139
				
140
				Date to = formatter.parse(timeValue.replace(":", ""));
141
				float diff = ((float)((to.getTime() - from.getTime()))) / 1000.0f // ms
142
				float diff2 = diff + 10
143
				writer.writeStartElement("Turn");
144
				writer.writeAttribute("startTime","$diff");
145
				writer.writeAttribute("endTime","$diff2");
146
				writer.writeAttribute("speaker",postingWho);
147
				writer.writeStartElement("Sync");
148
				writer.writeAttribute("time","$diff");
149
				writer.writeEndElement(); //Sync
150
				writer.writeCharacters(content)
151
				writer.writeEndElement(); //Turn
152
				writer.writeCharacters("\n")
153
				//println "end write Turn"
154
				inPosting = false
155
			}
156
			return;
157
		}
158

  
159
	}
160

  
161
	public static void main(String[] args) {
162
		File inputFile = new File("/home/mdecorde/xml/comere/split_out/tt_5-2013-11-12-teicmr.xml")
163
		File outputFile = new File("/home/mdecorde/xml/comere/split_out/tt_5-2013-11-12-teicmr-broken.trs")
164
		File outputFixedFile = new File("/home/mdecorde/xml/comere/split_out/tt_5-2013-11-12-teicmr.trs")
165
		
166
		
167
		XPathResult xpathProcessor = new XPathResult(inputFile);
168
		def loc = xpathProcessor.getXpathResponse("//tei:posting/@who")
169

  
170
		def p1 = new TEICMC2TRS(inputFile, loc)		
171
		def p2 = new FixMissingTimings(outputFile, outputFixedFile)
172
		
173
		if (p1 && p2) {
174
			outputFile.delete()
175
		} else {
176
			println "Failed to convert $inputFile to TRS"
177
		}
178
	}
179
}
projets/CMC2ELAN/src/StaxStackWriter.groovy (revision 2)
1

  
2

  
3
import javax.xml.namespace.NamespaceContext;
4
import javax.xml.stream.*;
5

  
6
public class StaxStackWriter implements XMLStreamWriter {
7

  
8
	public XMLStreamWriter writer;
9
	public Writer output;
10
	public File infile;
11
	public def events = [];
12
	
13
	public StaxStackWriter(def output) {
14
		XMLOutputFactory factory = XMLOutputFactory.newInstance();
15
		this.output = output
16
		this.writer = factory.createXMLStreamWriter(output);//create a new file
17
	}
18
	
19
	public StaxStackWriter(File infile) {
20
		this(infile.newWriter("UTF-8"))
21
		this.infile = infile
22
	}
23
	
24
	public File getInfile() {
25
		return infile;
26
	}
27

  
28
	public void write(String txt) {
29
		output.write(txt)
30
	}
31
	
32
	public void writeEndElements() {
33
		int size = events.size();
34
		for (int i = 0 ; i < size ; i++) {
35
			writeEndElement();
36
		}
37
		events = [];
38
	}
39

  
40
	public void writeStartElements(def tagsToWrite) {
41
		for (String tag : tagsToWrite)
42
			writeStartElement(tag);
43
	}
44

  
45
	public def getTagStack() {
46
		return events;
47
	}
48

  
49
	@Override
50
	public void close () throws XMLStreamException {
51
		writer.close();
52
		output.close();
53
	}
54

  
55
	@Override
56
	public void flush () throws XMLStreamException {
57
		writer.flush();
58

  
59
	}
60

  
61
	@Override
62
	public NamespaceContext getNamespaceContext() {
63
		return writer.getNamespaceContext();
64
	}
65

  
66
	@Override
67
	public String getPrefix (String uri) throws XMLStreamException {
68
		return writer.getPrefix(uri);
69
	}
70

  
71
	@Override
72
	public Object getProperty (String name) throws IllegalArgumentException {
73
		return writer.getProperty(name);
74
	}
75

  
76
	@Override
77
	public void setDefaultNamespace (String uri) throws XMLStreamException {
78
		writer.setDefaultNamespace(uri);
79
	}
80

  
81
	@Override
82
	public void setNamespaceContext(NamespaceContext context)
83
	throws XMLStreamException {
84
		writer.setNamespaceContext(context);
85
	}
86

  
87
	@Override
88
	public void setPrefix (String prefix, String uri) throws XMLStreamException {
89
		writer.setPrefix(prefix, uri);
90
	}
91

  
92
	@Override
93
	public void writeAttribute (String localName, String value) throws XMLStreamException {
94
		writer.writeAttribute(localName, value);
95
	}
96

  
97
	@Override
98
	public void writeAttribute (String namespaceURI, String localName, String value) throws XMLStreamException {
99
		writer.writeAttribute(namespaceURI, localName, value);
100
	}
101

  
102
	@Override
103
	public void writeAttribute (String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
104
		writer.writeAttribute(prefix, namespaceURI, localName, value);
105
	}
106

  
107
	@Override
108
	public void writeCData (String data) throws XMLStreamException {
109
		writer.writeCData(data);
110
	}
111

  
112
	@Override
113
	public void writeCharacters (String text) throws XMLStreamException {
114
		writer.writeCharacters(text);
115
	}
116

  
117
	@Override
118
	public void writeCharacters (char[] text, int start, int len) throws XMLStreamException {
119
		writer.writeCharacters(text, start, len);
120
	}
121

  
122
	@Override
123
	public void writeComment (String data) throws XMLStreamException {
124
		writer.writeComment(data);
125
	}
126

  
127
	@Override
128
	public void writeDTD (String dtd) throws XMLStreamException {
129
		writer.writeDTD(dtd);
130
	}
131

  
132
	@Override
133
	public void writeDefaultNamespace(String namespaceURI)
134
	throws XMLStreamException {
135
		writer.writeDefaultNamespace(namespaceURI);
136
	}
137

  
138
	public void writeElement (String localName, String text) throws XMLStreamException {
139
		writer.writeStartElement(localName);
140
		writer.writeCharacters(text);
141
		writer.writeEndElement();
142
	}
143
	
144
	public void writeElement (String localName, def map, String text) throws XMLStreamException {
145
		writer.writeStartElement(localName);
146
		for (def key : map.keySet()) writeAttribute(key.toString(), map[key].toString());
147
		writer.writeCharacters(text);
148
		writer.writeEndElement();
149
	}
150

  
151
	@Override
152
	public void writeEmptyElement (String localName) throws XMLStreamException {
153
		writer.writeEmptyElement(localName);
154
	}
155

  
156
	public void writeEmptyElement (String localName, def map) throws XMLStreamException {
157
		writer.writeEmptyElement(localName);
158
		for (def key : map.keySet())
159
			writeAttribute(key.toString(), map[key].toString());
160
	}
161

  
162
	@Override
163
	public void writeEmptyElement(String namespaceURI, String localName)
164
	throws XMLStreamException {
165
		writer.writeEmptyElement(namespaceURI, localName);
166
	}
167

  
168
	@Override
169
	public void writeEmptyElement (String prefix, String localName, String namespaceURI) throws XMLStreamException {
170
		writer.writeEmptyElement(prefix, localName, namespaceURI);
171
	}
172

  
173
	@Override
174
	public void writeEndDocument () throws XMLStreamException {
175
		writer.writeEndDocument();
176
	}
177

  
178
	@Override
179
	public void writeEndElement () throws XMLStreamException {
180
		writer.writeEndElement();
181
		events.pop()
182

  
183
	}
184

  
185
	@Override
186
	public void writeEntityRef (String name) throws XMLStreamException {
187
		writer.writeEntityRef(name);
188
	}
189

  
190
	@Override
191
	public void writeNamespace(String prefix, String namespaceURI)
192
	throws XMLStreamException {
193
		writer.writeNamespace(prefix, namespaceURI);
194
	}
195

  
196
	@Override
197
	public void writeProcessingInstruction(String target)
198
	throws XMLStreamException {
199
		writer.writeProcessingInstruction(target);
200
	}
201

  
202
	@Override
203
	public void writeProcessingInstruction(String target, String data)
204
	throws XMLStreamException {
205
		writer.writeProcessingInstruction(target, data);
206
	}
207

  
208
	@Override
209
	public void writeStartDocument () throws XMLStreamException {
210
		writer.writeStartDocument();
211

  
212
	}
213

  
214
	@Override
215
	public void writeStartDocument (String version) throws XMLStreamException {
216
		writer.writeStartDocument(version);
217
	}
218

  
219
	@Override
220
	public void writeStartDocument(String encoding, String version)
221
	throws XMLStreamException {
222
		writer.writeStartDocument(encoding, version);
223
	}
224

  
225
	@Override
226
	public void writeStartElement (String localName) throws XMLStreamException {
227
		writer.writeStartElement(localName);
228
		events << localName
229

  
230
	}
231
	
232
	public void writeStartElement (String localName, def map) throws XMLStreamException {
233
		writeStartElement(localName);
234
		for (def key : map.keySet()) {
235
			writeAttribute(key.toString(), map[key].toString());
236
		}
237
	}
238

  
239
	@Override
240
	public void writeStartElement(String namespaceURI, String localName)
241
	throws XMLStreamException {
242
		writer.writeStartElement(namespaceURI, localName);
243
		events << localName
244
	}
245

  
246
	@Override
247
	public void writeStartElement(String prefix, String localName,
248
	String namespaceURI) throws XMLStreamException {
249
		writer.writeStartElement(prefix, localName, namespaceURI);
250
		events << localName
251
	}
252
}
projets/CMC2ELAN/src/XPathResult.groovy (revision 2)
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: 2014-10-06 11:42:50 +0200 (lun., 06 oct. 2014) $
25
// $LastChangedRevision: 2842 $
26
// $LastChangedBy: mdecorde $ 
27
//
28

  
29
import java.io.File;
30
import java.io.IOException;
31
import java.util.Iterator;
32
import org.w3c.dom.*;
33
import org.xml.sax.SAXException;
34

  
35
import javax.xml.bind.helpers.DefaultValidationEventHandler;
36
import javax.xml.parsers.*;
37
import javax.xml.xpath.*;
38
import javax.xml.stream.*;
39
import java.net.URL;
40
import java.util.Iterator;
41

  
42
// TODO: Auto-generated Javadoc
43
/**
44
 * The Class XPathResult.
45
 *
46
 * @authors ayepdieu, mdecorde, vchabanis
47
 * 
48
 * return the id of a bfm tag <milestone/>
49
 */
50
public class XPathResult {
51
	
52
	/** The doc. */
53
	Document doc;
54
	XPath xpath;
55

  
56
	/**
57
	 * Instantiates a new x path result.
58
	 *
59
	 * @param file the file
60
	 */
61
	public XPathResult(File xmlfile) {
62
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
63
		factory.setNamespaceAware(true); // never forget this!
64
		
65
		DocumentBuilder builder = factory.newDocumentBuilder();
66
		doc = builder.parse(xmlfile);
67
		
68
		XPathFactory xfactory = XPathFactory.newInstance();
69
		xpath = xfactory.newXPath();
70
		xpath.setNamespaceContext(new PersonalNamespaceContext());
71
	}
72
	
73
	public def getNodes(String query) {
74
		def rnodes = [];
75
		
76
		XPathExpression expr = xpath.compile(query);
77
		Object result = expr.evaluate(doc, XPathConstants.NODESET);
78
		
79
		NodeList nodes = (NodeList) result;
80
		for (int i = 0; i < nodes.getLength(); i++) {
81
			rnodes.add(nodes.item(i));
82
		}
83
		return rnodes;
84
	}
85
		
86
	public String getXpathResponse(String query) {
87
		XPathExpression expr = xpath.compile(query);
88
		Object result = expr.evaluate(doc, XPathConstants.NODESET);
89
		
90
		NodeList nodes = (NodeList) result;
91
		for (int i = 0; i < nodes.getLength(); i++) {
92
			return (nodes.item(i).getNodeValue());
93
		}
94
	}
95
	
96
	public ArrayList<String> getXpathResponses(String query) {
97
		ArrayList<String> xresult = new ArrayList<String>();
98
		XPathExpression expr = xpath.compile(query);
99
		Object result = expr.evaluate(doc, XPathConstants.NODESET);
100
		
101
		NodeList nodes = (NodeList) result;
102
		for (int i = 0; i < nodes.getLength(); i++) {
103
			//println nodes.item(i)
104
			xresult.add((nodes.item(i).getNodeValue()));
105
		}
106
		return xresult
107
	}
108
	
109
	public String getXpathResponse(String query, String devaultValue) {
110
		String rez = getXpathResponse(query);
111
		if (rez == null)
112
			return devaultValue;
113
		return rez;
114
	}
115
	
116
	public void close() {
117
		xpath = null;
118
		doc = null;
119
	}
120

  
121
	/**
122

  
123
	 * OBSOLETE VERSION FOR TXM return the node text content given a XPath
124

  
125
	 * "//path.../.../@attr"
126
	 * 
127
	 * @param path
128
	 * @param attr
129
	 *            null or "" return the text of the tag targeted
130
	 * @return
131
	 */
132
	/*
133
	 * public String getXpathResponse(String path, String attr) throws
134
	 * ParserConfigurationException, SAXException, IOException,
135
	 * XPathExpressionException { String Query = path;
136
	 * 
137
	 * //println "XPath : "+Query; XPathFactory factory =
138
	 * XPathFactory.newInstance(); XPath xpath = factory.newXPath();
139
	 * xpath.setNamespaceContext(new PersonalNamespaceContext());
140
	 * XPathExpression expr = xpath.compile(Query);
141
	 * 
142
	 * Object result = expr.evaluate(doc, XPathConstants.NODESET); // don't work
143
	 * on windows NodeList nodes = (NodeList) result; //println
144
	 * "result xpath : "+nodes.getLength(); for(int i = 0 ; i <
145
	 * nodes.getLength() ; i++) { //println
146
	 * "item : "+nodes.item(i).getLocalName(); if(attr != null &&
147
	 * !attr.matches("")) return
148
	 * nodes.item(i).getAttributes().getNamedItem(attr).getNodeValue(); else
149
	 * return nodes.item(i).getTextContent();
150
	 * 
151
	 * } return ""; }
152
	 */
153
	
154
	static public String getXpathResponse(File xmlfile, String query, String devaultValue) {
155
		String rez = getXpathResponse(xmlfile, query);
156
		if (rez == null)
157
			return devaultValue;
158
		return rez;
159
	}
160
	
161
	static public String getXpathResponse(File xmlfile, String query, String devaultValue, boolean namespaceAware) {
162
		String rez = getXpathResponse(xmlfile, query, namespaceAware);
163
		if (rez == null)
164
			return devaultValue;
165
		return rez;
166
	}
167

  
168
	/**
169
	 * Gets the xpath response.
170
	 *
171
	 * @param xmlfile the xmlfile
172
	 * @param query the query
173
	 * @return the xpath response
174
	 */
175
	static public String getXpathResponse(File xmlfile, String query) {
176
		return getXpathResponse(xmlfile, query, true);
177
	}
178
	
179
	/**
180
	 * Gets the xpath response.
181
	 *
182
	 * @param xmlfile the xmlfile
183
	 * @param query the query
184
	 * @return the xpath response
185
	 */
186
	static public String getXpathResponse(File xmlfile, String query, boolean namespaceAware) {
187
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
188
		factory.setNamespaceAware(namespaceAware); // never forget this!
189
		
190
		DocumentBuilder builder = factory.newDocumentBuilder();
191
		Document doc = builder.parse(xmlfile);
192
		
193
		XPathFactory xfactory = XPathFactory.newInstance();
194
		XPath xpath = xfactory.newXPath();
195
		xpath.setNamespaceContext(new PersonalNamespaceContext());
196
		
197
		XPathExpression expr = xpath.compile(query);
198
		Object result = expr.evaluate(doc, XPathConstants.NODESET);
199
		
200
		NodeList nodes = (NodeList) result;
201
		for (int i = 0; i < nodes.getLength(); i++) {
202
			return (nodes.item(i).getNodeValue());
203
		}
204
	}
205

  
206
	/**
207
	 * The main method.
208
	 *
209
	 * @param args the arguments
210
	 */
211
	public static void main(String[] args) {
212
		println("main of XPathResult")
213
		File xmlFile = new File("/home/mdecorde/TXM/corpora/superphenix/txm/SUPERPHENIX/CreysSuper_04_0175.xml")
214
		String value = XPathResult.getXpathResponse(xmlFile, "TEI/text/@date");
215
		println "value: $value"
216
		//value = XPathResult.getXpathResponse(new File("/home/mdecorde/xml/bfm/strasb.xml"), "tei:TEI/tei:teiHeader/tei:revisionDesc/tei:change[contains(.,'étiquetage morpho')]");
217
		//println "value: $value"
218
	}
219
}
projets/CMC2ELAN/src/Main.groovy (revision 2)
1
File inputFile = new File("/home/mdecorde/xml/comere/ismael-textchat.xml")
2
File outputDir = new File("/home/mdecorde/xml/comere/forElan")
3
File splitDir = new File("/home/mdecorde/xml/comere/split")
4
File xsltfile = new File("/home/mdecorde/xsl/cmc2trs.xsl")
5

  
6
outputDir.deleteDir()
7
outputDir.mkdirs()
8
splitDir.deleteDir()
9
splitDir.mkdirs()
10

  
11
println "Split $inputFile per locutor"
12
XPathResult xpathProcessor = new XPathResult(inputFile);
13
def dates = xpathProcessor.getXpathResponses("//tei:dateline/tei:date/text()")
14
def locs = xpathProcessor.getXpathResponses("//tei:listPerson/tei:person/@xml:id")
15

  
16
dates = new HashSet(dates)
17
dates = new ArrayList(dates)
18
println dates.sort()
19
println locs
20

  
21
def p = new TEICMCPerLocPerDate(inputFile, splitDir)
22
println p.processDatesAndLocs(dates, locs)
23

  
24
def singleCMCFiles = splitDir.listFiles()
25
if (singleCMCFiles == null || singleCMCFiles.size() == 0) {
26
	println "no singleCMCFile produced by $inputFile"
27
	return;
28
}
29

  
30
println "Converting XML-TEI-CMC to XML-TRS from : "+splitDir
31
for (File singleCMCFile : singleCMCFiles) {
32
	println " Processing: "+singleCMCFile
33
	String name = singleCMCFile.getName();
34
	int idx = name.indexOf(".")
35
	if (idx > 0) name = name.substring(0, idx)
36

  
37
	File outputFile = new File(outputDir, name+"-brokentimes.trs")
38
	File outputFixedFile = new File(outputDir, name+".trs")
39

  
40

  
41
	XPathResult xpathProcessor2 = new XPathResult(singleCMCFile);
42
	def loc = xpathProcessor2.getXpathResponse("//tei:posting/@who")
43

  
44
	def p1 = new TEICMC2TRS(singleCMCFile, loc)
45
	def p2 = new FixMissingTimings(outputFile, outputFixedFile)
46

  
47
	if (p1.process(outputFile) && p2.process()) {
48
		outputFile.delete()
49
		println " Result saved in: $outputFixedFile"
50
	} else {
51
		println " Failed to convert $singleCMCFile to TRS"
52
	}
53
}
projets/CMC2ELAN/src/PersonalNamespaceContext.groovy (revision 2)
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: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28

  
29

  
30
import java.util.Iterator;
31
import javax.xml.*;
32
import javax.xml.namespace.NamespaceContext;
33

  
34
// TODO: Auto-generated Javadoc
35
/**
36
 * Instantiates a new personal namespace context.
37
 *
38
 * @author ayepdieu
39
 * do correpondances between namespace and uri
40
 */
41
 public class PersonalNamespaceContext implements NamespaceContext {
42
		public PersonalNamespaceContext() {
43
			super();
44
		}
45
	    
46
    	/* (non-Javadoc)
47
    	 * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(java.lang.String)
48
    	 */
49
    	public String getNamespaceURI(String prefix) {
50
	        if (prefix == null) throw new NullPointerException("Null prefix");
51
	        else if ("tei".equals(prefix)) return "http://www.tei-c.org/ns/1.0";
52
	        else if ("me".equals(prefix)) return "http://www.menota.org/ns/1.0";
53
	        else if ("bfm".equals(prefix)) return "http://bfm.ens-lsh.fr/ns/1.0";
54
	        else if ("txm".equals(prefix)) return "http://textometrie.org/1.0";
55
	        else if ("xi".equals(prefix)) return "http://www.w3.org/2001/XInclude";
56
	        else if ("xml".equals(prefix)) return XMLConstants.XML_NS_URI;
57
	        return XMLConstants.NULL_NS_URI;
58
	    }
59

  
60
	    /**
61
    	 * 
62
    	 * @param uri the uri
63
    	 * @return the prefix
64
    	 */
65
	    public String getPrefix(String uri) {
66
	    	if (uri == null) throw new NullPointerException("Null prefix");
67
	        else if ("http://www.tei-c.org/ns/1.0".equals(uri)) return "tei";
68
	        else if ("http://www.menota.org/ns/1.0".equals(uri)) return "me";
69
	        else if ("http://bfm.ens-lsh.fr/ns/1.0".equals(uri)) return "bfm";
70
	        else if ("http://textometrie.org/1.0".equals(uri)) return "txm";
71
	        else if ("http://www.w3.org/2001/XInclude".equals(uri)) return "xi";
72
	        else if("http://www.w3.org/XML/1998/namespace") return "xml"
73
	        else if (XMLConstants.XML_NS_URI.equals(uri)) return "xml";
74
	        else XMLConstants.NULL_NS_URI;
75
	    }
76

  
77
	    /**
78
    	 * This method isn't necessary for XPath processing either.
79
    	 *
80
    	 * @param uri the uri
81
    	 * @return the prefixes
82
    	 */
83
	    public Iterator getPrefixes(String uri) {
84
	        throw new UnsupportedOperationException();
85
	    }
86
	}
projets/CMC2ELAN/src/StaxIdentityParser.groovy (revision 2)
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: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $
27
//
28

  
29
import java.io.File;
30
import javax.xml.stream.XMLStreamConstants;
31
import javax.xml.stream.XMLOutputFactory;
32
import javax.xml.stream.XMLStreamWriter;
33
import java.io.File;
34
import java.net.URL;
35
import javax.xml.stream.*;
36
import org.txm.importer.filters.*;
37

  
38
class StaxIdentityParser {
39
	/** The input */
40
	protected URL inputurl;
41
	protected def inputData;
42
	protected XMLInputFactory factory;
43
	protected XMLStreamReader parser;
44
	
45
	/** The output. */
46
	protected XMLOutputFactory outfactory = XMLOutputFactory.newInstance();
47
	protected Writer output;
48
	protected XMLStreamWriter writer;
49
	
50
	public static String TXMNS = "http://textometrie.org/1.0";
51
	public static String TEINS = "http://www.tei-c.org/ns/1.0";
52
	protected static PersonalNamespaceContext Nscontext = new PersonalNamespaceContext();
53
	
54
	protected String currentXPath = "/"
55
	protected String localname;
56
	int processingXInclude = 0;
57
	
58
	public StaxIdentityParser(File infile)
59
	{
60
		this(infile.toURI().toURL());
61
	}
62
	
63
	public StaxIdentityParser(URL inputurl)
64
	{
65
		this.inputurl = inputurl;
66
		inputData = inputurl.openStream();
67
		factory = XMLInputFactory.newInstance();
68
		parser = factory.createXMLStreamReader(inputData);
69
	}
70
	
71
	protected void before()
72
	{
73
		
74
	}
75
	
76
	protected void after()
77
	{
78
		factory = null;
79
		if (parser !=null) parser.close();
80
		if (writer != null) writer.close();
81
		parser = null;
82
	}
83
	
84
	protected void closeForError() {
85
		parser.close();
86
	}
87
	
88
	/**
89
	 * Creates the output.
90
	 *
91
	 * @param outfile the outfile
92
	 * @return true, if successful
93
	 */
94
	private boolean createOutput(File f) {
95
		try {
96
			if (writer != null) // process from a file
97
				writer.close();
98
			if (output != null) // process from a file
99
				output.close();
100

  
101
			output = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
102
			writer = outfactory.createXMLStreamWriter(output);//create a new file
103
			writer.setNamespaceContext(Nscontext);
104
			return true;
105
		} catch (Exception e) {
106
			System.out.println("Error: create output of "+f+": "+e);
107
			return false;
108
		}
109
	}
110
	
111
	public boolean process(File outfile)
112
	{
113
		if (!createOutput(outfile))
114
			return false;
115
		writer.writeStartDocument("UTF-8", "1.0");
116
		writer.writeCharacters("\n");
117
		boolean ret = process(writer);
118
		if (writer != null) { // process from a file
119
			writer.close();
120
		}
121
		if (output != null) { // process from a file
122
		//	output.flush()
123
			output.close();
124
		}
125
		
126
		if (parser != null)
127
			try {parser.close()} catch(Exception e){println "parser exep: "+e}
128
			
129
		return ret;
130
	}
131
	
132
	public boolean process(XMLStreamWriter awriter)
133
	{
134
		this.writer = awriter;
135
		if (processingXInclude == 0) {
136
			before(); // if you need to do something before reading the xml
137
		}
138
		try {
139
			for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
140
				switch (event) {
141
					case XMLStreamConstants.NAMESPACE:
142
						processNamespace();
143
						break;
144
					case XMLStreamConstants.START_ELEMENT:
145
						localname = parser.getLocalName();
146
						currentXPath += localname+"/"
147
						processStartElement();
148
						break;		
149
					case XMLStreamConstants.CHARACTERS:
150
						processCharacters();
151
						break;
152
					case XMLStreamConstants.PROCESSING_INSTRUCTION:
153
						processProcessingInstruction();
154
						break;
155
					case XMLStreamConstants.DTD:
156
						processDTD();
157
						break;
158
					case XMLStreamConstants.CDATA:
159
						processCDATA();
160
						break;
161
					case XMLStreamConstants.COMMENT:
162
						processComment();
163
						break;
164
					case XMLStreamConstants.END_ELEMENT:
165
						localname = parser.getLocalName();
166
						processEndElement();	
167
						currentXPath = currentXPath.substring(0, currentXPath.length() - localname.length() -1)
168
						break;
169
					case XMLStreamConstants.END_DOCUMENT:
170
						processEndDocument();
171
						break;
172
					case XMLStreamConstants.ENTITY_REFERENCE:
173
						processEntityReference();
174
						break;
175
				}
176
			}
177
		} catch(Exception e) {
178
			println("Unexpected error while parsing file "+inputurl+" : "+e);
179
			println("Location line: "+parser.getLocation().getLineNumber()+" character: "+parser.getLocation().getColumnNumber());
180
			e.printStackTrace();
181
			//e.printStackTrace();
182
			if (writer != null) writer.close();
183
			if (output != null) output.close();
184
			parser.close();
185
			return false;
186
		}
187
		if (processingXInclude == 0) {
188
			after(); // if you need to do something before closing the parser();
189
		}
190
		return true;
191
	}
192
	
193
	/**
194
	 * The start element has already been written
195
	 * @param tagname
196
	 */
197
	public void goToEnd(String tagname) {
198
		//println "start gotoend $tagname"
199
		def elements = 1;
200
		try {
201
			for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
202
				//println "event "+event
203
				switch (event) {
204
					case XMLStreamConstants.NAMESPACE:
205
						processNamespace();
206
						break;
207
					case XMLStreamConstants.START_ELEMENT:
208
						elements++;
209
						localname = parser.getLocalName();
210
						currentXPath += localname+"/"
211
						_processStartElement();
212
						break;
213
					case XMLStreamConstants.CHARACTERS:
214
						processCharacters();
215
						break;
216
					case XMLStreamConstants.PROCESSING_INSTRUCTION:
217
						processProcessingInstruction();
218
						break;
219
					case XMLStreamConstants.DTD:
220
						processDTD();
221
						break;
222
					case XMLStreamConstants.CDATA:
223
						processCDATA();
224
						break;
225
					case XMLStreamConstants.COMMENT:
226
						processComment();
227
						break;
228
					case XMLStreamConstants.END_ELEMENT:
229
						elements--;
230
						localname = parser.getLocalName();
231
						currentXPath = currentXPath.substring(0, currentXPath.length() - localname.length() -1)
232
						writer.writeEndElement();
233
						if (elements == 0 && localname == tagname)
234
							return;
235
						break;
236
					case XMLStreamConstants.END_DOCUMENT:
237
						processEndDocument();
238
						break;
239
					case XMLStreamConstants.ENTITY_REFERENCE:
240
						processEntityReference();
241
						break;
242
				}
243
			}
244
		} catch(Exception e) {
245
			println("Error while parsing file "+inputurl);
246
			println("Location "+parser.getLocation());
247
			org.txm.utils.logger.Log.printStackTrace(e);
248
			output.close();
249
			parser.close();
250
			return;
251
		}
252
	}
253
	
254
	public def getLocation() {
255
		if (parser != null)
256
			return "Line: "+parser.getLocation().getLineNumber()+" Col: "+parser.getLocation().	getColumnNumber()
257
		return null;
258
	}
259
	
260
	protected void processNamespace() {
261
		writer.writeNamespace(parser.getPrefix(), parser.getNamespaceURI());
262
	}
263
	
264
	public static final String INCLUDE = "include"
265
	public static final String XI = "xi"
266
	
267
	protected void processStartElement()
268
	{
269
		String prefix = parser.getPrefix();
270
		if (INCLUDE == localname && XI == prefix) {
271
			processXInclude();
272
		} else {
273
			if (prefix != null && prefix.length() > 0)
274
				writer.writeStartElement(Nscontext.getNamespaceURI(prefix), localname)
275
			else
276
				writer.writeStartElement(localname);
277
			
278
			for (int i = 0 ; i < parser.getNamespaceCount() ; i++) {
279
				writer.writeNamespace(parser.getNamespacePrefix(i), parser.getNamespaceURI(i));
280
			}
281
			
282
			writeAttributes();
283
		}
284
	}
285
	
286
	private void _processStartElement()
287
	{
288
		String prefix = parser.getPrefix();
289
		if (INCLUDE == localname && XI == prefix) {
290
			processXInclude();
291
		} else {
292
			if (prefix != null && prefix.length() > 0)
293
				writer.writeStartElement(Nscontext.getNamespaceURI(prefix), localname)
294
			else
295
				writer.writeStartElement(localname);
296
			
297
			for (int i = 0 ; i < parser.getNamespaceCount() ; i++) {
298
				writer.writeNamespace(parser.getNamespacePrefix(i), parser.getNamespaceURI(i));
299
			}
300
			
301
			writeAttributes();
302
		}
303
	}
304
	
305
	protected void writeAttributes() {
306
		for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
307
			String attrPrefix = parser.getAttributePrefix(i);
308
			if (attrPrefix != null && attrPrefix.length() > 0)
309
				writer.writeAttribute(attrPrefix+":"+parser.getAttributeLocalName(i), parser.getAttributeValue(i));
310
			else
311
				writer.writeAttribute(parser.getAttributeLocalName(i), parser.getAttributeValue(i));
312
		}
313
	}
314
	
315
	protected void processCharacters()
316
	{
317
		writer.writeCharacters(parser.getText());
318
	}
319
	
320
	protected void processProcessingInstruction()
321
	{
322
		writer.writeProcessingInstruction(parser.getPITarget(), parser.getPIData());
323
	}
324
	
325
	protected void processDTD()
326
	{
327
		writer.writeDTD(parser.getText());
328
	}
329
	
330
	protected void processCDATA()
331
	{
332
		writer.writeCData(parser.getText())	
333
	}
334
	
335
	protected void processComment()
336
	{
337
		writer.writeComment(parser.getText());
338
	}
339
	
340
	protected void processEndElement()
341
	{
342
		if (localname == "include" && parser.getPrefix() == "xi") {
343
			// nothing !!
344
		} else {
345
			writer.writeEndElement();
346
		}
347
	}
348
	
349
	protected void processEndDocument() {
350
		writer.writeEndDocument();
351
	}
352
	
353
	protected void processEntityReference() {
354
		writer.writeEntityRef(parser.getLocalName());
355
	}
356
	/**
357
	 * Process the XInclude elements
358
	 */
359
	protected void processXInclude() {
360
		String url = parser.getAttributeValue(null, "href"); // relative only
361
		File driver = new File(inputurl.getFile());
362
		File ref = new File(driver.getParent(), url);
363
		if (ref.exists()) {
364
			URL includeurl = ref.toURI().toURL();
365
			// save variables before killing them
366
			println "process xi include: "+ref
367
			def parserSave = this.parser // back up current parser
368
			def xiIncludeInputData = includeurl.openStream();
369
			def xiIncludeParser = factory.createXMLStreamReader(xiIncludeInputData);
370
			parser = xiIncludeParser;
371
			processingXInclude++ // to avoid recalling before & after methods
372
			this.process(writer);
373
			processingXInclude-- // end of XInclude processing
374
			this.parser = parserSave // restore parser
375
		} else {
376
			println "Warning referenced file: $ref does not exists"
377
		}
378
	}
379
	
380
	public static void main(String[] args)
381
	{
382
		File input = new File("/home/mdecorde/xml/xiinclude/master.xml")
383
		File output = new File("/home/mdecorde/xml/xiinclude/merged.xml")
384
		if (!(input.exists() && input.canRead())) {
385
			println "cannot found $input";
386
			return;
387
		}
388
		
389
	}
390
}
projets/CMC2ELAN/src/TRS2CSVELAN.groovy (revision 2)
1

  
2
File trsDir = new File("/home/mdecorde/xml/comere/forElan")
3
File outDir = new File("/home/mdecorde/xml/comere/CSVforELAN")
4
outDir.deleteDir()
5
outDir.mkdir()
6

  
7
for (File f : trsDir.listFiles()) {
8
	if (!f.getName().endsWith(".trs")) continue;
9
	File tsvFile = new File(outDir, f.getName()+".csv")
10
	println "$f -> $tsvFile"
11
	
12
	def writer = tsvFile.newWriter("UTF-8")
13
	writer.println("actor\tstart\tend\tduration\tannotation")
14
	def parser = new XmlParser();
15
	parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
16
	parser.setFeature("http://xml.org/sax/features/namespaces", false)
17
	def trs = parser.parse(f)
18

  
19
	String currentEnd = null;
20
	for (def turn : trs.Episode.Section.Turn) {
21
		String actor = turn.@speaker
22
		String start = turn.@startTime
23
		String end = turn.@endTime
24
		String duration = Float.parseFloat(end) - Float.parseFloat(start)
25
		String annotation = turn.text().trim()
26
		writer.println("${actor}\t${start}\t${end}\t${duration}\t${annotation}")
27
	}
28
	writer.close()
29
}
projets/CMC2ELAN/src/FixMissingTimings.groovy (revision 2)
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
import java.text.SimpleDateFormat;
23
import java.util.Date;
24

  
25
class FixMissingTimings {
26

  
27
	File trsInFile = new File("/home/mdecorde/xml/transana/out.xml")
28
	File trsOutFile = new File("/home/mdecorde/xml/transana/TrP1S8_08102010.trs")
29

  
30
	public FixMissingTimings(File trsInFile, File trsOutFile) {
31
		this.trsInFile = trsInFile;
32
		this.trsOutFile = trsOutFile;
33
	}
34

  
35
	public boolean process() {
36
		def slurper = new XmlParser();
37
		def trs = slurper.parse(trsInFile)
38
	
39
		String currentEnd = null;
40
		for (def turn : trs.Episode.Section.Turn) {
41
			def children = turn.children()
42
	
43
			if (children.size() > 0) {
44
				//println "fixing turn start="+turn.@startTime+" end="+turn.@endTime+" previous end="+currentEnd
45
				if (currentEnd != null && currentEnd.length() > 0 && turn.@startTime.length() == 0) { // using last Sync
46
					//println "fixing with previous Turn $currentEnd"
47
					turn.@startTime = currentEnd
48
					setStartTime(children[0], currentEnd)
49
				} else if (!(children[0] instanceof String)) { // no previous Sync, using next Sync
50
					def start = getStartTime(children[0])
51
					if (start != null && start.length() > 0)	turn.@startTime = start
52
				}
53
				currentEnd = null
54
	
55
				if (!(children[children.size() - 1] instanceof String)) { // this is the last Sync
56
					def end = getStartTime(children[children.size() - 1])
57
					if (end != null && end.length() > 0)  {
58
						turn.@endTime = end
59
						currentEnd = end;
60
					}
61
				}
62
			}
63
		}
64
	
65
		def nodes = []
66
		// get Sync nodes to fix
67
		for (def section : trs.Episode.Section) { // all Section
68
			for (def child : section.children()) { // all Section children
69
				if (!(child instanceof String)) { // is a Tag
70
					switch(child.name()) {
71
						case "Turn": // get Sync in Turn
72
							//nodes << child;
73
							for (def sync : child.Sync)
74
								nodes << sync
75
							break;
76
						case "Sync":
77
							nodes << child;
78
							break;
79
						default: break;
80
					}
81
				}
82
			}
83
		}
84
		
85
		//Fixing Sync@time
86
		for (int i = 0 ; i < nodes.size() ; i++) {
87
			def node = nodes[i]
88
			String time = getStartTime(node)	
89
			
90
			if (time.length() == 0) {				
91
				def list = [];
92
				String previous;
93
				if (i > 0) { previous = getStartTime(nodes[i-1]);
94
				} else { previous = "0.0" }
95
				
96
				String next = null;
97
				while ((next == null || next.length() == 0) && i <= nodes.size()) {
98
					list << node
99
					node = nodes[++i]
100
					next = getStartTime(node)
101
				}
102
				if (next != null) {
103
					if (node != null) list << node
104
					fixSyncTimes(list, previous, next)
105
				} else {
106
					println "ERROR: no end time in the transcription"
107
				}
108
			}
109
		}
110
	
111
		// fixing startTime of Turn using next Sync.@time
112
		def turns = trs.Episode.Section.Turn
113
		for (int i = 0 ; i < turns.size() ; i++) {
114
			def turn = turns[i]
115
			def syncs = turn.Sync
116
			if (syncs.size() > 0) {
117
				turn.@startTime = syncs[0].@time
118
			} else {
119
				println "Error: Turn with no Sync milestone"
120
			}
121
		}
122
	
123
		// fixing endTimes of Turn using next Turn.@startTime
124
		for (int i = 0 ; i < turns.size() ; i++) {
125
			def turn = turns[i]
126
			//println "turn start="+turn.@startTime+" end="+turn.@endTime
127
			if (i < turns.size() - 1) {
128
				if (turn.@endTime.length() == 0 && turns[i+1].@startTime.length() > 0) {
129
					//println "fixing turn.@endTime "+turn.@endTime+" with turns[i+1].@startTime "+(turns[i+1]);
130
					turn.@endTime = turns[i+1].@startTime
131
				} 
132
			} else {
133
				Float e = Float.parseFloat(turn.@startTime)
134
				e += turn.text().length()*1.0f 
135
				turn.@endTime = e.toString()
136
			}
137
		}
138
		
139
		// fixing endTimes of Section using last Turn.@endTime
140
		// fixing startTimes of Section using first Turn.@startTime
141
		def sections = trs.Episode.Section
142
		for (int i = 0 ; i < sections.size() ; i++) {
143
			def t = sections[i].Turn
144
			if (t.size() == 0) continue;
145
			sections[i].@startTime = t[0].@startTime
146
			sections[i].@endTime = t[-1].@endTime
147
		}
148
		
149
		trsOutFile.withWriter("UTF-8") { writer ->
150
			writer.write('<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE Trans SYSTEM "trans-14.dtd">\n')
151
			new groovy.util.XmlNodePrinter(new PrintWriter(writer)).print(trs) }
152
		
153
		return true;
154
	}
155
	
156
	def getStartTime(def node) {
157
		def ret = null;
158
		if (node == null) return "0.0"
159
		if (node.name() == null) return "0.0"
160
		switch(node.name()) {
161
			case "Turn":
162
			case "Section":
163
			//			println "Turn"
164
				ret = node.@startTime
165
				break
166
			case "Sync":
167
			//		println "Sync"
168
				ret = node.@time
169
				break
170
			default: break;
171
		}
172
		//println "getStartTime "+node.name()+" $ret"
173
		return ret
174
	}
175

  
176
	def setStartTime(def node, def value) {
177
		switch(node.name()) {
178
			case "Turn":
179
			case "Section":
180
				node.@startTime = ""+value
181
				break;
182
			
183
			case "Sync":
184
				return node.@time = ""+value
185
			default: break;
186
		}
187
	}
188

  
189
	def fixSyncTimes(def list, def start, def end) {
190
		//println "Nfix: "+list.size()+" "+list
191
		//println "$start $end"
192
		
193
		def startf = Double.parseDouble(start)
194
		def endf = Double.parseDouble(end)
195
		def delta = (endf-startf)/list.size()
196
		//println delta
197
		float c = startf;
198
		for (int i = 0 ; i < list.size() ; i++) {
199
			c += delta;
200
			list[i].@time = ""+c
201
		}
202
	}
203
}
projets/CMC2ELAN/src/CheckMultipleVideoInXMLTEICMC.groovy (revision 2)
1

  
2
File splitDir = new File("/home/mdecorde/xml/comere/split")
3
for (File f : splitDir.listFiles()) {
4
	XPathResult xpathProcessor = new XPathResult(f);
5
	def files = xpathProcessor.getXpathResponses("//tei:dateline/tei:name/text()")
6
	files = new HashSet(files)
7
	if (files.size() > 1) println "$f	$files"
8
}
projets/CMC2ELAN/src/ApplyXsl2.groovy (revision 2)
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
// This file is part of the TXM platform.
24
//
25
// The TXM platform is free software: you can redistribute it and/or modif y
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff