Révision 2057

tmp/org.txm.groovy.core/src/groovy/org/txm/macro/edition/refaireEditionTRS.xsl (revision 2057)
1
<?xml version="1.0"?>
2

  
3

  
4
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:atilf="http://www.atilf.fr" version="2.0">
5

  
6
  <xsl:output method="xml"/>
7
  
8
  <xsl:param name="soundFile"/>
9

  
10

  
11
  
12
  
13
  <xsl:function name="atilf:traduireTemps">
14
    <xsl:param name="t"/>
15

  
16
    <xsl:choose>
17
      <xsl:when test="count($t) != 0">
18
	<xsl:analyze-string select="$t" regex="([0-9]+):([0-9]+):([0-9]+)">
19
	  <xsl:matching-substring>
20
	    <xsl:value-of select="number(regex-group(1))*3600+number(regex-group(2))*60+number(regex-group(3))"/>
21
	  </xsl:matching-substring>
22
	  <xsl:non-matching-substring><xsl:text>0</xsl:text></xsl:non-matching-substring>
23
	</xsl:analyze-string>
24
      </xsl:when>
25
      <xsl:otherwise>
26
	<xsl:text>0</xsl:text>
27
      </xsl:otherwise>
28
    </xsl:choose>
29
  </xsl:function>
30

  
31
  <xsl:template match="/">
32
    <xsl:apply-templates/>
33
  </xsl:template>
34

  
35

  
36
  <xsl:template match="html">
37
    <xsl:copy>
38
      <xsl:apply-templates select="meta"/>
39
      <xsl:apply-templates select="head"/>
40
      <xsl:apply-templates select="link"/>
41
      <xsl:apply-templates select="*[not(self::meta) and not(self::head) and
42
				   not(self::link) and not(self::body) and not(self::tei:body)]"/>
43
      <xsl:apply-templates select="tei:body"/>
44
    </xsl:copy>
45
  </xsl:template>
46
  
47
  <xsl:template match="*">
48
    <xsl:copy>
49
      <xsl:apply-templates select="@* | node()"/>
50
    </xsl:copy>
51
  </xsl:template>
52

  
53
  <xsl:template match="@* | text() | comment() | processing-instruction()">
54
    <xsl:copy/>
55
  </xsl:template>
56

  
57
 
58

  
59
  <xsl:template match="tei:body">
60
    <xsl:copy>
61
	<script>
62
	  <!-- Element.prototype.documentOffsetTop = function () {
63
	  return this.offsetTop + ( this.offsetParent ? this.offsetParent.documentOffsetTop() : 0 );
64
	  };
65
	  
66
	 
67
	  function myFunc2(event) {
68
	  document.getElementById('tracktime').innerHTML = Math.floor(event.currentTime) + ' / ' + Math.floor(event.duration);
69
	  };
70
	     function myFunc3(event) {
71
	     var x = document.getElementsByTagName("span");
72
	     for (index = 0; index &lt; x.length; index++){
73
	     if ((x[index].getAttribute("begin") &lt; event.currentTime)
74
	        &amp;&amp;
75
	        (x[index].getAttribute("end") &gt; event.currentTime)){
76
	    
77
		x[index].className = "spk_hi";
78
		/*x[index].scrollIntoView( true );*/
79
		/*var top = x[index].documentOffsetTop() - ( window.innerHeight / 2 );
80
	
81
		window.scrollTo(0, top );*/
82
		
83
		var topPos = x[index].offsetTop;
84
		document.getElementById('scrollDiv').scrollTop = topPos-110;
85
		}
86
		else{
87
		x[index].className="spk";
88
		}
89
	     };
90
	    };-->
91
	    
92
	       function moveInSound(t){
93
	       var player = document.getElementById("audioPlay");
94
	       
95
	       if (player.paused){
96
	          player.currentTime = t;
97
	          player.play();
98
		  }
99
		  else{
100
		  player.pause();
101
		  }
102
	       };
103

  
104
	        function stopSound(t){
105
	       var player = document.getElementById("audioPlay");
106

  
107
	       player.pause();
108
	     };
109
	</script>
110
	 <audio id="audioPlay" controls="controls" style="height:100px; display:none">
111
	    <source src="{$soundFile}"/>
112
	  </audio>
113
	<xsl:apply-templates/>
114
    </xsl:copy>
115
  </xsl:template>
116

  
117

  
118
  <!-- En fait, on veut mettre un bouton play, stop -->
119
  <xsl:template match="span[@class='spk']">
120

  
121
    <!-- <button type="button" style='background: url("play.png") no-repeat; width:25px;height:25px;background-size:100%;'>
122
       <xsl:attribute name="onclick">
123
	<xsl:text>moveInSound(</xsl:text><xsl:value-of select="atilf:traduireTemps(following::span[@class='sync'][1]/text())"/><xsl:text>)</xsl:text>
124
      </xsl:attribute>
125
      <xsl:text> </xsl:text>
126
    </button> -->
127
      
128
 
129
    <xsl:copy>
130
      <xsl:apply-templates select="@*"/>
131
      <xsl:attribute name="onclick">
132
	<xsl:text>moveInSound(</xsl:text><xsl:value-of select="atilf:traduireTemps(following::span[@class='sync'][1]/text())"/><xsl:text>)</xsl:text>
133
      </xsl:attribute>
134
      <xsl:apply-templates select="node()"/>
135

  
136
    </xsl:copy>
137
    
138
    <!-- <button type="button"  style='background: url("pause.png") no-repeat; width:25px;height:25px;background-size:100%;'>
139
       <xsl:attribute name="onclick">
140
	<xsl:text>stopSound(</xsl:text><xsl:value-of select="atilf:traduireTemps(following::span[@class='sync'][1]/text())"/><xsl:text>)</xsl:text>
141
      </xsl:attribute>
142
      <xsl:text> </xsl:text>
143
</button> -->
144
 
145
  </xsl:template>
146

  
147
  <xsl:template match="span[@class='sync']">
148

  
149
    <!-- <button type="button" style='background: url("play.png") no-repeat; width:25px;height:25px;background-size:100%;'>
150
       <xsl:attribute name="onclick">
151
	<xsl:text>moveInSound(</xsl:text><xsl:value-of select="atilf:traduireTemps(following::span[@class='sync'][1]/text())"/><xsl:text>)</xsl:text>
152
      </xsl:attribute>
153
      <xsl:text> </xsl:text>
154
    </button> -->
155
      
156
 
157
    <xsl:copy>
158
      <xsl:apply-templates select="@*"/>
159
      <xsl:attribute name="onclick">
160
	<xsl:text>moveInSound(</xsl:text><xsl:value-of select="atilf:traduireTemps(./text())"/><xsl:text>)</xsl:text>
161
      </xsl:attribute>
162
      <xsl:apply-templates select="node()"/>
163

  
164
    </xsl:copy>
165
    
166
    <!-- <button type="button"  style='background: url("pause.png") no-repeat; width:25px;height:25px;background-size:100%;'>
167
       <xsl:attribute name="onclick">
168
	<xsl:text>stopSound(</xsl:text><xsl:value-of select="atilf:traduireTemps(following::span[@class='sync'][1]/text())"/><xsl:text>)</xsl:text>
169
      </xsl:attribute>
170
      <xsl:text> </xsl:text>
171
</button> -->
172
 
173
  </xsl:template>
174

  
175
  <xsl:template match="span[@class='word']">
176

  
177
    <!-- <button type="button" style='background: url("play.png") no-repeat; width:25px;height:25px;background-size:100%;'>
178
       <xsl:attribute name="onclick">
179
	<xsl:text>moveInSound(</xsl:text><xsl:value-of select="atilf:traduireTemps(following::span[@class='sync'][1]/text())"/><xsl:text>)</xsl:text>
180
      </xsl:attribute>
181
      <xsl:text> </xsl:text>
182
    </button> -->
183
      
184
 
185
    <xsl:copy>
186
      <xsl:apply-templates select="@*"/>
187
      <xsl:attribute name="onclick">
188
	<xsl:text>moveInSound(</xsl:text><xsl:value-of select="atilf:traduireTemps(preceding::span[@class='sync'][1]/text())"/><xsl:text>)</xsl:text>
189
      </xsl:attribute>
190
      <xsl:apply-templates select="node()"/>
191

  
192
    </xsl:copy>
193
    
194
    <!-- <button type="button"  style='background: url("pause.png") no-repeat; width:25px;height:25px;background-size:100%;'>
195
       <xsl:attribute name="onclick">
196
	<xsl:text>stopSound(</xsl:text><xsl:value-of select="atilf:traduireTemps(following::span[@class='sync'][1]/text())"/><xsl:text>)</xsl:text>
197
      </xsl:attribute>
198
      <xsl:text> </xsl:text>
199
</button> -->
200
 
201
  </xsl:template>
202

  
203
  
204
</xsl:stylesheet>
0 205

  
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/edition/RebuildTRSEditionMacro.groovy (revision 2057)
1
//package org.txm.macro.xsl;
2
// STANDARD DECLARATIONS
3

  
4
//import org.kohsuke.args4j.*
5
//import groovy.transform.Field
6
//import org.txm.rcpapplication.swt.widget.parameters.*
7
//import org.txm.importer.ApplyXsl2;
8

  
9
package org.txm.macro.edition
10
// STANDARD DECLARATIONS
11

  
12
import org.kohsuke.args4j.*
13
import groovy.transform.Field
14
import org.txm.rcpapplication.swt.widget.parameters.*
15
import org.txm.objects.*
16
import org.txm.searchengine.cqp.corpus.*;
17
import org.w3c.dom.*
18
import org.txm.importer.*
19
import org.txm.Toolbox
20
import java.io.*
21

  
22
import org.w3c.dom.Document;
23
import org.xml.sax.SAXException;
24
import org.txm.rcpapplication.commands.*
25
import javax.xml.parsers.*;
26
import javax.xml.transform.*;
27
import javax.xml.transform.dom.DOMSource;
28
import javax.xml.transform.stream.StreamResult;
29
import org.txm.utils.io.FileCopy
30

  
31
try { println "ARGS=$args";} catch(Exception e) {args = [:]}
32

  
33
def corpus = null
34
if (args.size() == 0) {
35
	if (!(corpusViewSelection instanceof MainCorpus)) {
36
		println "This marcro works with a MainCorpus selection. Aborting"
37
		return;
38
	}
39
	println "Working on $corpusViewSelection corpus"
40
	corpus = corpusViewSelection
41
} else {
42
	monitor = args["monitor"];
43
}
44

  
45
// Les paramètres dont on a besoin :
46
// Nom du Corpus dans TXM on le récupère de l amême façon que EditionUpdaterMacro...
47
// Nom du répertoire dans lequel sont les trs utilisables avec transcriber (i.e. ceux à partir desquels on trouve les fichiers sons).
48
// Nom de l'édition à modifier.
49

  
50

  
51
println "Corpora selection: "+corpusViewSelection
52
println "corpusName ="+corpus.getName()
53
def corpusName=corpusViewSelection.getName()
54

  
55
//Je voudrais mettre en dur la feuille xsl ? (ou pas....)
56
// BEGINNING OF PARAMETERS
57
//@Field @Option(name="corpusTXM",usage="nom du corpus dans TXM", widget="String", required=true, def="")
58
def corpusTXM=corpusViewSelection
59

  
60
@Field @Option(name="placeInitCorpus", usage="directory où se trouve/trouvait initialement le corpus : trs et fichiers Sons", widget="Folder", required=true, def="")
61
def placeInitCorpus
62

  
63
@Field @Option(name="editionName",usage="The edition name to produce", widget="String", required=false, def="default")
64
String editionName
65

  
66
// BEGINNING OF PARAMETERS
67
//@Field @Option(name="XSLFile",usage="an example file", widget="File", required=true, def="file.xsl")
68
//def XSLFile = new File(System.getProperty("user.home"),"TXM/xsl/identity.xsl")
69
//def XSLFile
70

  
71
//@Field @Option(name="intputDirectory",usage="an example folder", widget="Folder", required=true, def="in")
72
//def intputDirectory = new File(System.getProperty("user.home"),"xml/TESTS2/xml")
73
//def intputDirectory
74

  
75
//@Field @Option(name="outputDirectory",usage="an example folder", widget="Folder", required=true, def="out")
76
////def outputDirectory = new File("/tmp/xsltest")
77
//def outputDirectory
78

  
79
//@Field @Option(name="parameters",usage="an example folder", widget="Text", required=false, def="")
80
//def parameters = ""
81

  
82
//@Field @Option(name="debug",usage="Show debug messages, value = true|false", widget="String", required=true, def="false")
83
//def debug
84

  
85
if (!ParametersDialog.open(this)) return;
86
// END OF PARAMETERS
87

  
88
binDirectory = corpus.getProjectDirectory()
89
File HTMLDirectory = new File(binDirectory, "HTML")
90
File HTMLCorpusDirectory = new File(HTMLDirectory, corpusName)
91
println HTMLCorpusDirectory
92
File defaultEditionDirectory = new File(HTMLCorpusDirectory, editionName)
93
println defaultEditionDirectory
94

  
95
//On cherche récursivement les trs dans placeInitCorpus
96

  
97
println "place init corpus : "+placeInitCorpus.getAbsolutePath()
98

  
99
placeInitCorpus.eachFileRecurse{ AFile ->
100
	String name = AFile.getName()
101
    if (name.matches(/.+\.trs/)){
102
		println name
103
		println "Path absolu :"+AFile.getAbsolutePath()
104
		//on le parse pour trouver le audio file name
105
		parser=new XmlSlurper();
106
		parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
107
		parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
108
		list=parser.parse(AFile)
109
		def transNode=list
110
		def fichierSon=transNode.@audio_filename
111
		println "   fichierSon : ->"+fichierSon
112
		
113
		File parentFolder = new File(AFile.getParent());
114
		File soundF = new File(parentFolder, ""+fichierSon);
115
		String fichierSonAbsolu = soundF.getCanonicalPath(); // may throw IOException
116
		//String fichierSonAbsolu="toto"
117
		println "Son absolu :"+fichierSonAbsolu
118
		
119
		//maintenant, on veut trouver le fichier son pour de vrai !
120
		//C'est là qu'il faut voir si on trouve : 
121
		// fichierSonAbsolu, ou fichierSonAbsolu+.mp3 ou fichierSonAbsolu+.MP3 ou
122
		// fichierSonAbsolu+.wav ou fichierSonAbsolu+.WAV
123
		//Deux types de problèmes possibles : n'en trouver aucun
124
		//                                    en trouver plusieurs !
125
		File sonFichier=new File(fichierSonAbsolu)
126
		if (sonFichier.exists()){
127
			println "   OK, fichierSon trouvé";
128
			found = true;
129
		}
130
		else{
131
			String[] exts = [".wav", ".WAV", ".mp3", ".MP3"];
132
			found = false;
133
			fini = false;
134
			index=0;
135
			while (!found && !fini){
136
				fichierSonAbsoluTest=fichierSonAbsolu+exts[index];
137
				println("   On teste "+fichierSonAbsoluTest);
138
				sonFichier=new File(fichierSonAbsoluTest);
139
				found=sonFichier.exists();
140
				if (found){
141
					fichierSonAbsolu = fichierSonAbsoluTest;
142
				}
143
				else{
144
					index = index +1;
145
					fini = (index >= exts.length);
146
				}
147
			}
148
		}
149
		if (!found){
150
			println(" Pas de fichier son trouvé pour : "+name);
151
		}	
152
		else{
153
		
154
				baseN = name[0..-4]
155
				htmlRegex = ".*${baseN}.*\\.html"
156
				println "HtmlRegex = "+htmlRegex
157
		
158
				String xslPath = Toolbox.getTxmHomePath()+"/scripts/groovy/user/org/txm/macro/edition/"+"refaireEditionTRS.xsl"
159
				ApplyXsl2 a = new ApplyXsl2(xslPath)
160
				outputDirectory = defaultEditionDirectory
161
				defaultEditionDirectory.eachFileRecurse{ HtmlFile ->
162
				//println "   ?"+HtmlFile
163
				if (HtmlFile ==~ /${htmlRegex}/){
164
					println "   OK "+HtmlFile
165
					a.SetParam("soundFile", fichierSonAbsolu)
166
					def outFile = new File(outputDirectory, HtmlFile.getName()+".bis")
167
					a.process(HtmlFile, outFile);
168
					// On renome les fichiers :
169
					println "nouveau nom : "+defaultEditionDirectory.getCanonicalPath()+"/"+HtmlFile.getName()+".orig"
170
					oldName=HtmlFile.getCanonicalPath()
171
					//HtmlFile.renameTo (defaultEditionDirectory.getCanonicalPath()+"/"+HtmlFile.getName()+".orig")
172
					HtmlFile.renameTo (defaultEditionDirectory.getCanonicalPath()+File.separator+HtmlFile.getName()+".orig")
173
					// Il semble que windows n'aime pas le renomage....
174
					//outFile.renameTo oldName
175
					//donc on teste une copie...
176
					HtmlFile << outFile.text
177
				
178
					a.resetParams()
179
				
180
				}
181
			
182
			}
183
		}
184
	}
185
}
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/alceste/importer.groovy (revision 2057)
34 34
import org.txm.scripts.*;
35 35
import org.txm.importer.cwb.CwbEncode
36 36
import org.txm.importer.cwb.CwbMakeAll
37
import org.txm.utils.ConsoleProgressBar
37 38
import org.txm.utils.io.FileCopy;
38 39
import org.txm.importer.scripts.xmltxm.*;
39 40

  
......
102 103
		println (srcfiles.size()+ " texts found in "+srcfile)
103 104

  
104 105
		println("Tokenizing files ("+srcfiles.size()+")")
106
		ConsoleProgressBar cpb = new ConsoleProgressBar(srcfiles.size())
105 107
		for (File f : srcfiles) {
106
			print "."
108
			cpb.tick()
107 109
			File resultfile = new File(tokenizeDir, f.getName());
108 110
			try {
109 111
				def builder = new SimpleTokenizerXml(f, resultfile, lang);
......
115 117
			}
116 118
			catch(Exception e){org.txm.utils.logger.Log.printStackTrace(e); println "Failed to tokenize: "+f; return false;}
117 119
		}
118
		println ""
120
		cpb.done()
119 121
		
120 122
		List<File> stokenfiles = tokenizeDir.listFiles();	
121 123
		println("Tagging sentences of "+stokenfiles.size()+" files")
124
		cpb = new ConsoleProgressBar(stokenfiles.size())
122 125
		for (File f : stokenfiles) {
123
			print "."
126
			cpb.tick()
124 127
			Sequence S = new Sequence();
125 128
			Filter F1 = new CutHeader();
126 129
			Filter F7 = new TagSentences();
......
144 147
			S.clean();
145 148
			headerfile.delete();//remove the prepared file to clean
146 149
		}
147
		println ""
150
		cpb.done()
148 151

  
149 152
		//TRANSFORM INTO XML-TEI-TXM
150 153
		List<File> tokenfiles = stokenizeDir.listFiles()
151 154
		println("Building xml-tei-txm ("+tokenfiles.size()+" files)")
155
		cpb = new ConsoleProgressBar(tokenfiles.size())
152 156
		for (File f : tokenfiles) {
153
			print "."
157
			cpb.tick()
154 158
			File file = f;
155 159
			File txmfile = new File(txmDir, f.getName());
156 160

  
......
179 183
				txmfile.delete();
180 184
			}
181 185
		}
182
		println ""
186
		cpb.done()
183 187
		return true;
184 188
	}
185 189
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/CorporaView.java (revision 2057)
297 297
				if (sel.length == 0)
298 298
					return;
299 299

  
300
				CorporaView.this.setFocus(); // force focus on the corpora view -> ensure the active selection is the corpora view selection
301
				
300 302
				ISelection tsel = treeViewer.getSelection();
301 303
				if (!(tsel instanceof TreeSelection)) return;
302 304

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 2057)
1010 1010
				return null;
1011 1011
			}
1012 1012

  
1013
			//TODO until the TXMResult don't know if its parameters are set by the user or by the default preference value, we need to use the AUTO_COMPUTE_ON_EDITOR_OPEN preference
1014
			// compute the result only if the editor wasn't already opened
1015
			if (!wasAlreadyOpened && (RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_COMPUTE_ON_EDITOR_OPEN)))	{
1016
				editor.compute(false);
1013
			if (wasAlreadyOpened) {
1014
				
1017 1015
			} else {
1018
				editor.refresh(false);
1016
				//TODO until the TXMResult don't know if its parameters are set by the user or by the default preference value, we need to use the AUTO_COMPUTE_ON_EDITOR_OPEN preference
1017
				// compute the result only if the editor wasn't already opened
1018
				if ((RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_COMPUTE_ON_EDITOR_OPEN)))	{
1019
					editor.compute(false);
1020
				} else {
1021
					editor.refresh(false);
1022
				}
1019 1023
			}
1020 1024
		}
1021 1025
		catch (Exception e) {

Formats disponibles : Unified diff