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 321 mdecorde
// Copyright © 2010-2013 ENS de Lyon.
2 321 mdecorde
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3 321 mdecorde
// Lyon 2, University of Franche-Comté, University of Nice
4 321 mdecorde
// Sophia Antipolis, University of Paris 3.
5 321 mdecorde
//
6 321 mdecorde
// The TXM platform is free software: you can redistribute it
7 321 mdecorde
// and/or modify it under the terms of the GNU General Public
8 321 mdecorde
// License as published by the Free Software Foundation,
9 321 mdecorde
// either version 2 of the License, or (at your option) any
10 321 mdecorde
// later version.
11 321 mdecorde
//
12 321 mdecorde
// The TXM platform is distributed in the hope that it will be
13 321 mdecorde
// useful, but WITHOUT ANY WARRANTY; without even the implied
14 321 mdecorde
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 321 mdecorde
// PURPOSE. See the GNU General Public License for more
16 321 mdecorde
// details.
17 321 mdecorde
//
18 321 mdecorde
// You should have received a copy of the GNU General
19 321 mdecorde
// Public License along with the TXM platform. If not, see
20 321 mdecorde
// http://www.gnu.org/licenses.
21 321 mdecorde
//
22 321 mdecorde
//
23 321 mdecorde
//
24 479 mdecorde
// $LastChangedDate: 2016-05-26 17:42:36 +0200 (jeu. 26 mai 2016) $
25 321 mdecorde
// $LastChangedRevision: 3219 $
26 321 mdecorde
// $LastChangedBy: mdecorde $
27 321 mdecorde
//
28 986 mdecorde
package org.txm.scripts.importer.graal;
29 321 mdecorde
30 321 mdecorde
import java.net.URL;
31 321 mdecorde
import java.lang.Boolean
32 1000 mdecorde
import org.txm.importer.cwb.CwbEncode
33 1000 mdecorde
import org.txm.importer.cwb.CwbMakeAll
34 321 mdecorde
35 321 mdecorde
36 321 mdecorde
// TODO: Auto-generated Javadoc
37 321 mdecorde
/**
38 321 mdecorde
 * The Class ImportInCWB.
39 321 mdecorde
 *
40 321 mdecorde
 * @author sheiden,mdecorde
41 321 mdecorde
 *
42 803 mdecorde
 * import graal cqp fiel into cwb
43 321 mdecorde
 */
44 321 mdecorde
public class ImportInCWB{
45 321 mdecorde
46 321 mdecorde
        /** The root dir. */
47 321 mdecorde
        def rootDir;//chemin du dossier qui contien src/ et xsl/
48 321 mdecorde
49 321 mdecorde
        /** The in dir. */
50 321 mdecorde
        def inDir;
51 321 mdecorde
52 803 mdecorde
        //dossier qui contiendra les gsp et vues dipl, cour, facs, trad et cqp
53 321 mdecorde
54 321 mdecorde
        /** The out dir. */
55 321 mdecorde
        def outDir;
56 321 mdecorde
        //dossiers qui contient le registre cqp et le dossier data (qui contient les corpus)
57 321 mdecorde
58 321 mdecorde
        /** The out dir txm. */
59 321 mdecorde
        def outDirTxm;
60 321 mdecorde
61 321 mdecorde
         /** The in file. */
62 321 mdecorde
         def inFile;
63 321 mdecorde
64 321 mdecorde
        /** The in file2. */
65 321 mdecorde
        def inFile2;
66 321 mdecorde
67 321 mdecorde
        /** The out file. */
68 321 mdecorde
        def outFile;
69 321 mdecorde
70 321 mdecorde
        /** The out file2. */
71 321 mdecorde
        def outFile2;
72 321 mdecorde
73 321 mdecorde
        /**
74 321 mdecorde
         * same args as GraalInportCqp.
75 321 mdecorde
         *
76 321 mdecorde
         * @param rootDir the root dir
77 321 mdecorde
         * @param inFile the in file
78 321 mdecorde
         * @param inFile2 the in file2
79 321 mdecorde
         * @param outFile the out file
80 321 mdecorde
         * @param outFile2 the out file2
81 321 mdecorde
         */
82 321 mdecorde
        public ImportInCWB(        rootDir,
83 321 mdecorde
                                                inFile,
84 321 mdecorde
                                                inFile2,
85 321 mdecorde
                                                outFile,
86 321 mdecorde
                                                outFile2)
87 321 mdecorde
        {
88 321 mdecorde
                this.rootDir = rootDir;
89 714 mdecorde
90 321 mdecorde
                this.inFile = inFile;
91 321 mdecorde
                this.inFile2 = inFile2;
92 321 mdecorde
                this.outFile = outFile;
93 321 mdecorde
                this.outFile2 = outFile2;
94 321 mdecorde
                this.inDir = this.rootDir+"src" ;
95 321 mdecorde
                this.outDir = this.rootDir ;//outdir of the .gsp
96 321 mdecorde
                this.outDirTxm = this.rootDir ;//outdir for data files & registry
97 321 mdecorde
                this.createDirs();
98 321 mdecorde
        }
99 321 mdecorde
100 321 mdecorde
        /**
101 321 mdecorde
         * create dirs to prevent errors.
102 321 mdecorde
         */
103 321 mdecorde
        private void createDirs()
104 321 mdecorde
        {
105 321 mdecorde
                new File(outDir).mkdir();
106 803 mdecorde
                new File(outDir+"/cqp").mkdir();
107 321 mdecorde
                new File(outDirTxm).mkdir();
108 321 mdecorde
                new File(outDirTxm+"registry").mkdir();
109 321 mdecorde
                new File(outDirTxm+"data").mkdir();
110 321 mdecorde
        }
111 321 mdecorde
112 321 mdecorde
        /**
113 321 mdecorde
         * call :
114 321 mdecorde
         * GraalImportCqp
115 321 mdecorde
         * cwb-encode
116 321 mdecorde
         * cwb-makeall.
117 321 mdecorde
         */
118 321 mdecorde
        public void start()
119 803 mdecorde
        {//transfome en cqp et compile les index
120 321 mdecorde
                System.out.println "file:///"+ inDir + "/" + inFile+ ".xml";
121 321 mdecorde
                CwbEncode cwbEn = new CwbEncode();
122 321 mdecorde
                CwbMakeAll cwbMa = new CwbMakeAll();
123 321 mdecorde
124 321 mdecorde
                GraalImportCqp traitTxt = new GraalImportCqp(new URL("file:///"+ inDir + "/" + inFile+ ".xml"));
125 804 mdecorde
                traitTxt.transfomFileCqp(outDir+"/cqp/", outFile + ".cqp");
126 321 mdecorde
127 321 mdecorde
                traitTxt = new GraalImportCqp(new URL("file:///"+ inDir + "/" + inFile2+ ".xml"));
128 804 mdecorde
                traitTxt.transfomFileCqpBrut(outDir+"/cqp/", outFile2 + ".cqp");
129 321 mdecorde
130 321 mdecorde
                System.out.println("--Building index files ...")
131 321 mdecorde
                String[] pAttributecm = ["pos", "q", "supplied", "col", "line", "id", "dipl", "facs"];
132 321 mdecorde
                String[] sAttributecm = ["p:0+n", "q:1+n", "s:0+n+id"];
133 321 mdecorde
134 321 mdecorde
                String[] pAttributes = ["pos", "id", "col"];
135 321 mdecorde
                String[] sAttributes = ["p:0+n", "s:0+n"];
136 321 mdecorde
                try {
137 321 mdecorde
                        if (System.getProperty("os.name").contains("Windows"))
138 321 mdecorde
                        {
139 803 mdecorde
                                cwbEn.run(outDirTxm + "data/"+outFile, outDir +"/cqp/"+outFile+".cqp", outDirTxm + "registry/"+outFile,pAttributecm, sAttributecm);
140 714 mdecorde
                                cwbMa.run(outFile.toUpperCase(), outDirTxm + "registry");
141 321 mdecorde
142 803 mdecorde
                                cwbEn.run(outDirTxm + "data/"+outFile2, outDir + "/cqp/"+outFile2+".cqp", outDirTxm + "registry/"+outFile2, pAttributes, sAttributes);
143 714 mdecorde
                                cwbMa.run(outFile2.toUpperCase(), outDirTxm + "registry");
144 321 mdecorde
                        }
145 321 mdecorde
                        else
146 321 mdecorde
                        {
147 803 mdecorde
                                cwbEn.run(outDirTxm + "data/"+outFile, outDir + "/cqp/"+outFile+".cqp", outDirTxm + "registry/"+outFile,pAttributecm, sAttributecm);
148 714 mdecorde
                                cwbMa.run(outFile.toUpperCase(), outDirTxm + "registry");
149 321 mdecorde
150 803 mdecorde
                                cwbEn.run(outDirTxm + "data/"+outFile2, outDir +"/cqp/"+ outFile2+".cqp", outDirTxm + "registry/"+outFile2, pAttributes, sAttributes);
151 714 mdecorde
                                cwbMa.run(outFile2.toUpperCase(), outDirTxm + "registry");
152 321 mdecorde
                        }
153 321 mdecorde
                } catch (Exception ex) {System.out.println(ex);}
154 321 mdecorde
                                System.out.println("Done.")
155 321 mdecorde
        }
156 321 mdecorde
157 321 mdecorde
        /**
158 321 mdecorde
         * test.
159 321 mdecorde
         */
160 321 mdecorde
        public void run()
161 321 mdecorde
        {
162 804 mdecorde
                System.out.println "Starting script : importCQP.groovy ...";
163 321 mdecorde
                System.setProperty("javax.xml.transform.TransformerFactory",
164 321 mdecorde
                                                         "net.sf.saxon.TransformerFactoryImpl");
165 804 mdecorde
                this.importCQP();
166 321 mdecorde
                System.out.println "GraalImport.groovy done."
167 321 mdecorde
        }
168 321 mdecorde
}