Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / importer / graal / BuildGraalGSP.groovy @ 479

History | View | Annotate | Download (6.5 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: 2013-05-06 17:38:43 +0200 (lun. 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.importer.graal;
29

    
30
import org.txm.importer.*
31
// TODO: Auto-generated Javadoc
32

    
33
/**
34
 * The Class BuildGraalGSP.
35
 *
36
 * @author sheiden
37
 */
38

    
39
public class BuildGraalGSP{
40
         
41
         /** The cwb loc. */
42
         String cwbLoc;
43
        
44
        /** The root dir. */
45
        String rootDir;
46
        
47
        /** The in dir. */
48
        String inDir;
49
        
50
        /** The in dir xsl. */
51
        String inDirXsl;
52
                 
53
        //dossier qui contiendra les gsp et vues dipl, cour, facs, trad et wtc
54
        
55
        /** The out dir. */
56
        String outDir;
57
        //dossiers qui contient le registre cqp et le dossier data (qui contient les corpus)
58
        
59
        /** The out dir txm. */
60
        String outDirTxm;
61
        //dossier qui contient les xml sources découpés
62
        
63
        /** The out dir cut. */
64
        String outDirCut;
65
        
66
        /** The in file. */
67
        String inFile;
68
        
69
        /** The in file2. */
70
        String inFile2;
71
        
72
        /** The out file. */
73
        String outFile;
74
        
75
        /** The out file2. */
76
        String outFile2;
77
        
78
        /**
79
         * Instantiates a new builds the graal gsp.
80
         *
81
         * @param rootDir the directory which contains sources and which will contains result files
82
         * @param cwbLoc the location of cwb-encode and cwb-makeall
83
         * @param inFile the path to the graalcm file
84
         * @param inFile2 the path to the graalfrmod file
85
         * @param outFile the prefix of gsp outfiles
86
         * @param outFile2 the prefix of gsp outfiles
87
         */
88
        public BuildGraalGSP(String        rootDir, String cwbLoc, String inFile,
89
        String inFile2,        String outFile,        String outFile2)
90
        {
91
                this.rootDir = rootDir;
92
                this.cwbLoc = cwbLoc;
93
                this.inFile = inFile;
94
                this.inFile2 = inFile2;
95
                this.outFile = outFile;
96
                this.outFile2 = outFile2;
97
                this.inDir = this.rootDir;
98
                this.inDirXsl = this.rootDir + "/src/xsl";
99
                this.outDir = this.rootDir + "/imported/form/";//outdir of the .gsp
100
                this.outDirTxm = this.rootDir + "/imported/corpora/";//outdir for data files & registry
101
                this.outDirCut = this.rootDir + "/imported/cut/";
102
                this.createDirs();
103
        }
104
        
105
        /**
106
         * create outputs dir to prevent from "dir not found" error.
107
         */
108
        private void createDirs()
109
        {
110
                new File(outDir).mkdir();
111
                new File(outDir+"/dipl").mkdir();
112
                new File(outDir+"/trad").mkdir();
113
                new File(outDir+"/facs").mkdir();
114
                new File(outDir+"/cour").mkdir();
115
                new File(outDirTxm).mkdir();
116
                new File(outDirCut).mkdir();
117
        }
118

    
119
        /**
120
         * process !!!.
121
         */
122
        public boolean start()
123
        {
124
                if(!ValidateXml.test(new File(inDir + "src/"+inFile+".xml")))
125
                {
126
                        println "Invalid source: "+inDir + "src/"+inFile+".xml";
127
                        return false;
128
                }
129
                
130
                if(!ValidateXml.test(new File(inDir + "src/"+inFile2+".xml")))
131
                {
132
                        println "Invalid source: "+inDir + "src/"+inFile2+".xml";
133
                        return false;
134
                }
135
                
136
                def timportWTCestG
137
                def nPage;
138
                def temp;
139
                def BBM;
140
                def MAN;
141
                def MAF;
142
                def MAD;
143
                def MTR;
144
                //Ouverture des Xsl
145
                //Decoupe et mise en forme des page
146
                println "start"
147
                for (int index = 1; index < 268; index++) 
148
                {
149
                        println "loop" + index
150
                        
151
                        //URL url = new URL("file:///" + inDirXsl + "/breakByMilestone.xsl");
152
                        BBM = new ApplyXsl( inDirXsl + "/breakByMilestone.xsl");
153
                        //println "xsl applied"
154
                        MAN = new GraalApplyXsl(new URL("file:///" + inDirXsl + "/qgraal_cour.xsl"));
155
                        //println "xsl applied 2"
156
                        MAF = new GraalApplyXsl(new URL("file:///" + inDirXsl + "/qgraal_facs.xsl"));
157
                        //println "xsl applied 3 "
158
                        MAD = new GraalApplyXsl(new URL("file:///" + inDirXsl + "/qgraal_dipl.xsl"));
159
                        //println "xsl applied 4"
160
                        MTR = new GraalApplyXsl(new URL("file:///" + inDirXsl + "/qgraal_frmod.xsl"));
161
                        //println "xsl applied 5"
162
                        def testG = new GraalXpath();
163
                        //println "xpath done"
164
                        
165
                        nPage = testG.getXpathResponse(inDir + "src/"+inFile+ ".xml",  index+"").substring(4);//recuperation du numero de page
166
                        //nPage=index
167
                        println "npage = " + nPage
168
                        
169
                        URL url = new URL("file:///" + inDir + inFile+ ".xml");
170
                        //System.out.println("--Converting " + url.getFile() + " to web pages.");
171
                        
172
                        //BBM.setParam("pbval1", index);
173
                        //println "params set 1 : "
174
                        //BBM.setParams("pbval2", index + 1);
175
                        String[] params = ["pbval1", index,"pbval2", index+1]
176
                        //println "params set 2"
177
                        BBM.process(new URL("file:///" + inDir + "/src/" + inFile+ ".xml").getFile(), outDirCut+"/"+ inFile + "_" + nPage + ".xml",params);//decoupe ancienne version
178
                        println "BBM Done : "+inFile + "_" + nPage + ".xml"
179
                        //System.out.println "L'index est : " + index + " npage " + nPage;
180
                                System.out.println "----Pages gsp";
181
                                if (index<260) {
182
                                BBM.process(new URL("file:///" + inDir + "/src/" + inFile2+ ".xml").getFile(), outDirCut+"/"+ inFile2 + "_" + nPage + ".xml",params);//decoupe nouvelle version
183
                                }
184
                                System.out.println "----Break By MileStone.";
185
                                if(index<10)
186
                                {                                        
187
                                MAF.ApplyXsl(new URL("file:///" + outDirCut + "/" + inFile + "_" + nPage+ ".xml"), outDir + "facs", "_" + outFile + "_facs_" + nPage + ".gsp");//mise en page facsimilaire
188
                                System.out.println "----Building facsimile version.";
189
                                }
190
                                MAD.ApplyXsl(new URL("file:///" + outDirCut + "/" + inFile + "_" + nPage+ ".xml"), outDir + "dipl", "_" + outFile + "_dipl_" + nPage + ".gsp");//mise en page diplomatique
191
                                System.out.println "----Building diplomatic version.";
192
                                if(index<260)
193
                                {                                        
194
                                MTR.ApplyXsl(new URL("file:///" + outDirCut + "/" + inFile2 + "_" + nPage+ ".xml"), outDir + "trad", "_" + outFile2 + "_trad_" + nPage + ".gsp");//mise en forme traduction
195
                                System.out.println "----Building traduction version.";
196
                                }
197

    
198
                        MAN.ApplyXsl(new URL("file:///" + outDirCut + "/" + inFile + "_" + nPage + ".xml"), outDir + "cour", "_" + outFile + "_norm_" + nPage + ".gsp");//mise en forme courante
199
                        System.out.println "----Building current version.";
200
                        System.out.println "--Page " + nPage + " OK";
201
                }
202
                println "end"
203
                return true;
204
        }
205
}