Statistics
| Revision:

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

History | View | Annotate | Download (4.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: 2016-05-26 17:42:36 +0200 (jeu. 26 mai 2016) $
25
// $LastChangedRevision: 3219 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.scripts.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 cqp fiel into cwb
43
 */
44
public class ImportInCWB{
45

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