Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / importer / bvh / bvhLoader.groovy @ 1000

History | View | Annotate | Download (4.4 kB)

1 321 mdecorde
/**
2 321 mdecorde
 * Main.
3 321 mdecorde
 *
4 321 mdecorde
 * @param args the args
5 321 mdecorde
 */
6 321 mdecorde
// Copyright © 2010-2013 ENS de Lyon.
7 321 mdecorde
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
8 321 mdecorde
// Lyon 2, University of Franche-Comté, University of Nice
9 321 mdecorde
// Sophia Antipolis, University of Paris 3.
10 321 mdecorde
//
11 321 mdecorde
// The TXM platform is free software: you can redistribute it
12 321 mdecorde
// and/or modify it under the terms of the GNU General Public
13 321 mdecorde
// License as published by the Free Software Foundation,
14 321 mdecorde
// either version 2 of the License, or (at your option) any
15 321 mdecorde
// later version.
16 321 mdecorde
//
17 321 mdecorde
// The TXM platform is distributed in the hope that it will be
18 321 mdecorde
// useful, but WITHOUT ANY WARRANTY; without even the implied
19 321 mdecorde
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 321 mdecorde
// PURPOSE. See the GNU General Public License for more
21 321 mdecorde
// details.
22 321 mdecorde
//
23 321 mdecorde
// You should have received a copy of the GNU General
24 321 mdecorde
// Public License along with the TXM platform. If not, see
25 321 mdecorde
// http://www.gnu.org/licenses.
26 321 mdecorde
//
27 321 mdecorde
//
28 321 mdecorde
//
29 479 mdecorde
// $LastChangedDate: 2013-09-16 14:31:48 +0200 (lun. 16 sept. 2013) $
30 321 mdecorde
// $LastChangedRevision: 2535 $
31 321 mdecorde
// $LastChangedBy: mdecorde $
32 321 mdecorde
//
33 986 mdecorde
package org.txm.scripts.importer.bvh;
34 321 mdecorde
35 321 mdecorde
import java.io.File;
36 986 mdecorde
import org.txm.scripts.importer.bvh.importer;
37 986 mdecorde
import org.txm.scripts.importer.bvh.compiler;
38 986 mdecorde
import org.txm.scripts.importer.bvh.annotate;
39 986 mdecorde
import org.txm.scripts.importer.bvh.pager;
40 321 mdecorde
import org.txm.objects.*;
41 321 mdecorde
import org.txm.*;
42 927 mdecorde
import org.txm.core.engines.*;
43 1000 mdecorde
import org.txm.importer.scripts.xmltxm.*;
44 321 mdecorde
import org.txm.utils.i18n.*;
45 321 mdecorde
46 321 mdecorde
// TODO: Auto-generated Javadoc
47 321 mdecorde
/**
48 321 mdecorde
 * Run.
49 321 mdecorde
 *
50 321 mdecorde
 * @return the java.lang. object
51 321 mdecorde
 * @author mdecorde
52 321 mdecorde
 */
53 321 mdecorde
54 321 mdecorde
String userDir = System.getProperty("user.home");
55 321 mdecorde
String lang;
56 321 mdecorde
String encoding;
57 321 mdecorde
String rootDir;
58 321 mdecorde
String model;
59 321 mdecorde
String basename;
60 321 mdecorde
try{rootDir = rootDirBinding;lang=langBinding;encoding=encodingBinding;model=modelBinding;basename=basenameBinding}
61 321 mdecorde
catch(Exception)
62 321 mdecorde
{        println "DEV MODE";//exception means we debug
63 321 mdecorde
        if(!org.txm.Toolbox.isInitialized())
64 321 mdecorde
        {
65 321 mdecorde
                rootDir = userDir+"/xml/bvh/";
66 321 mdecorde
                lang="fr";
67 321 mdecorde
                encoding= "UTF-8";// not used by bvh
68 321 mdecorde
                model="rgaqcj"; //not used by bvh
69 321 mdecorde
                basename="bvh"
70 321 mdecorde
                Toolbox.workspace = new Workspace(new File(userDir,"TXM/workspaces/default.xml"));
71 321 mdecorde
                Toolbox.setParam(Toolbox.INSTALL_DIR,new File(userDir,"TXM"));
72 321 mdecorde
                Toolbox.setParam(Toolbox.METADATA_ENCODING, "UTF-8");
73 321 mdecorde
                Toolbox.setParam(Toolbox.METADATA_COLSEPARATOR, ",");
74 321 mdecorde
                Toolbox.setParam(Toolbox.METADATA_TXTSEPARATOR, "\"");
75 321 mdecorde
                Toolbox.setParam(Toolbox.USER_TXM_HOME, new File(System.getProperty("user.home"),"TXM"));
76 321 mdecorde
        }
77 321 mdecorde
}
78 321 mdecorde
79 321 mdecorde
println "IMPORTER"
80 321 mdecorde
new importer().run(new File(rootDir), basename);
81 321 mdecorde
82 878 sjacqu01
File binDir = new File(Toolbox.getTxmHomePath(),"corpora/"+basename);
83 321 mdecorde
rootDir = binDir.getAbsolutePath();
84 321 mdecorde
85 321 mdecorde
println "ANNOTATE - fr "
86 321 mdecorde
new Annotate().run(new File(rootDir),"fr.par");//the files in ./txm
87 321 mdecorde
88 321 mdecorde
println "ANNOTATE - afr"
89 321 mdecorde
def secondannotator = new Annotate()
90 321 mdecorde
secondannotator.run(new File(rootDir),"afr.par");//the files in ./txm
91 321 mdecorde
92 321 mdecorde
println "--COMPILING"
93 321 mdecorde
File dir = new File(rootDir);
94 321 mdecorde
def c = new compiler();
95 321 mdecorde
c.setDebug();
96 321 mdecorde
//c.setCwbPath("~/TXM/cwb/bin");
97 321 mdecorde
c.setLang(lang);
98 321 mdecorde
if (!c.run(dir)) {
99 321 mdecorde
        println "Compiler failed"
100 321 mdecorde
        return;
101 321 mdecorde
}
102 321 mdecorde
103 321 mdecorde
//move registry file to cwb registry dir
104 321 mdecorde
File registryfile = new File(rootDir+"/registry",basename);
105 321 mdecorde
if(registryfile.exists())
106 927 mdecorde
        org.txm.utils.io.FileCopy.copy(registryfile,new File(Toolbox.getTxmHomePath(),"registry/"+basename))
107 321 mdecorde
108 321 mdecorde
Workspace w = org.txm.Toolbox.workspace;
109 321 mdecorde
Project p = w.getProject("default")
110 321 mdecorde
p.removeBase(basename)
111 321 mdecorde
Base b = p.addBase(basename);
112 321 mdecorde
b.addDirectory(new File(rootDir,"txm"));
113 321 mdecorde
b.setAttribute("lang", lang)
114 321 mdecorde
b.propagateAttribute("lang")
115 321 mdecorde
116 321 mdecorde
println "-- EDITION"
117 321 mdecorde
new File(rootDir+"/HTML/").deleteDir()
118 321 mdecorde
new File(rootDir+"/HTML/").mkdir();
119 321 mdecorde
new File(rootDir+"/HTML/default/").mkdir();
120 321 mdecorde
files = new File(rootDir,"txm").listFiles();
121 321 mdecorde
122 321 mdecorde
for(Text text : b.getTexts())
123 321 mdecorde
{
124 321 mdecorde
        File srcfile = text.getSource();
125 321 mdecorde
        File resultfile = new File(rootDir+"/HTML",srcfile.getName().substring(0,srcfile.getName().length()-4)+".html");
126 321 mdecorde
        List<String> NoSpaceBefore = LangFormater.getNoSpaceBefore(lang);
127 321 mdecorde
        List<String> NoSpaceAfter = LangFormater.getNoSpaceAfter(lang);
128 321 mdecorde
        println("Building edition  : "+srcfile+" to : "+resultfile );
129 321 mdecorde
130 321 mdecorde
        def ed = new pager(srcfile,resultfile, NoSpaceBefore, NoSpaceAfter,600);
131 321 mdecorde
        Edition editionweb = text.addEdition("default","html",resultfile);
132 321 mdecorde
133 321 mdecorde
        for(int i = 0 ; i < ed.getPageFiles().size();i++)
134 321 mdecorde
        {
135 321 mdecorde
                File f = ed.getPageFiles().get(i);
136 321 mdecorde
                String idx = ed.getIdx().get(i);
137 321 mdecorde
                editionweb.addPage(f,idx);
138 321 mdecorde
        }
139 321 mdecorde
140 321 mdecorde
//        Edition editionbp = text.addEdition("onepage","html",resultfile);
141 321 mdecorde
//        editionbp.addPage(resultfile,ed.getIdx().get(0));
142 321 mdecorde
}
143 321 mdecorde
144 927 mdecorde
w.save();