Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / importer / graal / ImportInCWB.groovy @ 187

History | View | Annotate | Download (5.2 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: 2016-05-26 17:42:36 +0200 (Thu, 26 May 2016) $
25
// $LastChangedRevision: 3219 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.importer.graal;
29

    
30
import java.net.URL;
31
import java.lang.Boolean
32
import org.txm.importer.cwb.CwbEncode
33
import org.txm.importer.cwb.CwbMakeAll
34

    
35

    
36
// TODO: Auto-generated Javadoc
37
/**
38
 * The Class ImportInCWB.
39
 *
40
 * @author sheiden,mdecorde
41
 * 
42
 * import graal wtc fiel into cwb
43
 */
44
public class ImportInCWB{
45

    
46
         /** The cwb loc. */
47
         def cwbLoc;//chemin vers executable cqp
48
        
49
        /** The root dir. */
50
        def rootDir;//chemin du dossier qui contien src/ et xsl/
51
        
52
        /** The in dir. */
53
        def inDir;
54
                 
55
        //dossier qui contiendra les gsp et vues dipl, cour, facs, trad et wtc
56
        
57
        /** The out dir. */
58
        def outDir;
59
        //dossiers qui contient le registre cqp et le dossier data (qui contient les corpus)
60
        
61
        /** The out dir txm. */
62
        def outDirTxm;
63
        
64
         /** The in file. */
65
         def inFile;
66
        
67
        /** The in file2. */
68
        def inFile2;
69
        
70
        /** The out file. */
71
        def outFile;
72
        
73
        /** The out file2. */
74
        def outFile2;
75
        
76
        /**
77
         * same args as GraalInportCqp.
78
         *
79
         * @param rootDir the root dir
80
         * @param cwbLoc the cwb loc
81
         * @param inFile the in file
82
         * @param inFile2 the in file2
83
         * @param outFile the out file
84
         * @param outFile2 the out file2
85
         */
86
        public ImportInCWB(        rootDir,
87
                                                cwbLoc,
88
                                                inFile,
89
                                                inFile2,
90
                                                outFile,
91
                                                outFile2)
92
        {
93
                this.rootDir = rootDir;
94
                if(cwbLoc == null)
95
                        cwbLoc = org.txm.Toolbox.getParam(org.txm.Toolbox.CQI_SERVER_PATH_TO_CQPLIB)+File.separator;
96
                else
97
                        this.cwbLoc = cwbLoc;
98
                this.inFile = inFile;
99
                this.inFile2 = inFile2;
100
                this.outFile = outFile;
101
                this.outFile2 = outFile2;
102
                this.inDir = this.rootDir+"src" ;
103
                this.outDir = this.rootDir ;//outdir of the .gsp
104
                this.outDirTxm = this.rootDir ;//outdir for data files & registry
105
                this.createDirs();
106
        }
107
        
108
        /**
109
         * create dirs to prevent errors.
110
         */
111
        private void createDirs()
112
        {
113
                new File(outDir).mkdir();
114
                new File(outDir+"/wtc").mkdir();
115
                new File(outDirTxm).mkdir();
116
                new File(outDirTxm+"registry").mkdir();
117
                new File(outDirTxm+"data").mkdir();
118
        }
119
        
120
        /**
121
         * call :
122
         * GraalImportCqp
123
         * cwb-encode
124
         * cwb-makeall.
125
         */
126
        public void start()
127
        {//transfome en wtc et compile les index
128
                System.out.println "file:///"+ inDir + "/" + inFile+ ".xml";
129
                CwbEncode cwbEn = new CwbEncode();
130
                CwbMakeAll cwbMa = new CwbMakeAll();
131
                
132
                GraalImportCqp traitTxt = new GraalImportCqp(new URL("file:///"+ inDir + "/" + inFile+ ".xml"));
133
                traitTxt.transfomFileWtc(outDir+"/wtc/", outFile + ".wtc");
134
                
135
                traitTxt = new GraalImportCqp(new URL("file:///"+ inDir + "/" + inFile2+ ".xml"));
136
                traitTxt.transfomFileWtcBrut(outDir+"/wtc/", outFile2 + ".wtc");
137
                
138
                System.out.println("--Building index files ...") 
139
                String[] pAttributecm = ["pos", "q", "supplied", "col", "line", "id", "dipl", "facs"];
140
                String[] sAttributecm = ["p:0+n", "q:1+n", "s:0+n+id"];
141
                
142
                String[] pAttributes = ["pos", "id", "col"];
143
                String[] sAttributes = ["p:0+n", "s:0+n"];
144
                try {
145
                        if (System.getProperty("os.name").contains("Windows"))
146
                        {
147
                                cwbEn.run(cwbLoc + "cwb-encode.exe", outDirTxm + "data/"+outFile, outDir +"/wtc/"+outFile+".wtc", outDirTxm + "registry/"+outFile,pAttributecm, sAttributecm);
148
                                cwbMa.run(cwbLoc + "cwb-makeall.exe", outFile.toUpperCase(), outDirTxm + "registry");
149
                                
150
                                cwbEn.run(cwbLoc + "cwb-encode.exe", outDirTxm + "data/"+outFile2, outDir + "/wtc/"+outFile2+".wtc", outDirTxm + "registry/"+outFile2, pAttributes, sAttributes);
151
                                cwbMa.run(cwbLoc + "cwb-makeall.exe", outFile2.toUpperCase(), outDirTxm + "registry");
152
                        }
153
                        else
154
                        {
155
                                cwbEn.run(cwbLoc + "cwb-encode", outDirTxm + "data/"+outFile, outDir + "/wtc/"+outFile+".wtc", outDirTxm + "registry/"+outFile,pAttributecm, sAttributecm);
156
                                cwbMa.run(cwbLoc + "cwb-makeall", outFile.toUpperCase(), outDirTxm + "registry");
157
                                
158
                                cwbEn.run(cwbLoc + "cwb-encode", outDirTxm + "data/"+outFile2, outDir +"/wtc/"+ outFile2+".wtc", outDirTxm + "registry/"+outFile2, pAttributes, sAttributes);
159
                                cwbMa.run(cwbLoc + "cwb-makeall", outFile2.toUpperCase(), outDirTxm + "registry");
160
                        }
161
                } catch (Exception ex) {System.out.println(ex);}
162
                                System.out.println("Done.") 
163
        }
164
        
165
        /**
166
         * test.
167
         */
168
        public void run() 
169
        {
170
                System.out.println "Starting script : importWTC.groovy ...";
171
                System.setProperty("javax.xml.transform.TransformerFactory",  
172
                                                         "net.sf.saxon.TransformerFactoryImpl");  
173
                this.importWTC();
174
                System.out.println "GraalImport.groovy done."
175
        }
176
}