Statistics
| Revision:

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

History | View | Annotate | Download (4.5 kB)

1
/**
2
 * Main.
3
 *
4
 * @param args the args
5
 */
6
// Copyright © 2010-2013 ENS de Lyon.
7
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
8
// Lyon 2, University of Franche-Comté, University of Nice
9
// Sophia Antipolis, University of Paris 3.
10
// 
11
// The TXM platform is free software: you can redistribute it
12
// and/or modify it under the terms of the GNU General Public
13
// License as published by the Free Software Foundation,
14
// either version 2 of the License, or (at your option) any
15
// later version.
16
// 
17
// The TXM platform is distributed in the hope that it will be
18
// useful, but WITHOUT ANY WARRANTY; without even the implied
19
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20
// PURPOSE. See the GNU General Public License for more
21
// details.
22
// 
23
// You should have received a copy of the GNU General
24
// Public License along with the TXM platform. If not, see
25
// http://www.gnu.org/licenses.
26
// 
27
// 
28
// 
29
// $LastChangedDate: 2013-09-16 14:31:48 +0200 (lun., 16 sept. 2013) $
30
// $LastChangedRevision: 2535 $
31
// $LastChangedBy: mdecorde $ 
32
//
33
package org.txm.importer.bvh;
34

    
35
import java.io.File;
36
import org.txm.importer.bvh.importer;
37
import org.txm.importer.bvh.compiler;
38
import org.txm.importer.bvh.annotate;
39
import org.txm.importer.bvh.pager;
40
import org.txm.objects.*;
41
import org.txm.*;
42
import org.txm.scripts.teitxm.*;
43
import org.txm.utils.i18n.*;
44

    
45
// TODO: Auto-generated Javadoc
46
/**
47
 * Run.
48
 *
49
 * @return the java.lang. object
50
 * @author mdecorde
51
 */
52

    
53
String userDir = System.getProperty("user.home");
54
String lang;
55
String encoding;
56
String rootDir;
57
String model;
58
String basename;
59
try{rootDir = rootDirBinding;lang=langBinding;encoding=encodingBinding;model=modelBinding;basename=basenameBinding}
60
catch(Exception)
61
{        println "DEV MODE";//exception means we debug
62
        if(!org.txm.Toolbox.isInitialized())
63
        {
64
                rootDir = userDir+"/xml/bvh/";
65
                lang="fr";
66
                encoding= "UTF-8";// not used by bvh
67
                model="rgaqcj"; //not used by bvh
68
                basename="bvh"
69
                Toolbox.workspace = new Workspace(new File(userDir,"TXM/workspaces/default.xml"));
70
                Toolbox.setParam(Toolbox.INSTALL_DIR,new File(userDir,"TXM"));
71
                Toolbox.setParam(Toolbox.TREETAGGER_INSTALL_PATH,new File(userDir,"treetagger"));
72
                Toolbox.setParam(Toolbox.TREETAGGER_MODELS_PATH,new File(userDir,"treetagger/models"));
73
                Toolbox.setParam(Toolbox.METADATA_ENCODING, "UTF-8");
74
                Toolbox.setParam(Toolbox.METADATA_COLSEPARATOR, ",");
75
                Toolbox.setParam(Toolbox.METADATA_TXTSEPARATOR, "\"");
76
                Toolbox.setParam(Toolbox.USER_TXM_HOME, new File(System.getProperty("user.home"),"TXM"));
77
        }
78
}
79

    
80
println "IMPORTER"
81
new importer().run(new File(rootDir), basename);
82

    
83
File binDir = new File(Toolbox.getParam(Toolbox.USER_TXM_HOME),"corpora/"+basename);
84
rootDir = binDir.getAbsolutePath();
85

    
86
println "ANNOTATE - fr "
87
new Annotate().run(new File(rootDir),"fr.par");//the files in ./txm
88

    
89
println "ANNOTATE - afr"
90
def secondannotator = new Annotate()
91
secondannotator.run(new File(rootDir),"afr.par");//the files in ./txm
92

    
93
println "--COMPILING"
94
File dir = new File(rootDir);
95
def c = new compiler();
96
c.setDebug();
97
//c.setCwbPath("~/TXM/cwb/bin");
98
c.setLang(lang);
99
if (!c.run(dir)) {
100
        println "Compiler failed"
101
        return;
102
}
103

    
104
//move registry file to cwb registry dir
105
File registryfile = new File(rootDir+"/registry",basename);
106
if(registryfile.exists())
107
        org.txm.utils.FileCopy.copy(registryfile,new File(Toolbox.getParam(Toolbox.USER_TXM_HOME),"registry/"+basename))
108

    
109
Workspace w = org.txm.Toolbox.workspace;
110
Project p = w.getProject("default")
111
p.removeBase(basename)
112
Base b = p.addBase(basename);
113
b.addDirectory(new File(rootDir,"txm"));
114
b.setAttribute("lang", lang)
115
b.propagateAttribute("lang")
116

    
117
println "-- EDITION"
118
new File(rootDir+"/HTML/").deleteDir()
119
new File(rootDir+"/HTML/").mkdir();
120
new File(rootDir+"/HTML/default/").mkdir();
121
files = new File(rootDir,"txm").listFiles();
122

    
123
for(Text text : b.getTexts())
124
{
125
        File srcfile = text.getSource();
126
        File resultfile = new File(rootDir+"/HTML",srcfile.getName().substring(0,srcfile.getName().length()-4)+".html");
127
        List<String> NoSpaceBefore = LangFormater.getNoSpaceBefore(lang);
128
        List<String> NoSpaceAfter = LangFormater.getNoSpaceAfter(lang);
129
        println("Building edition  : "+srcfile+" to : "+resultfile );
130
        
131
        def ed = new pager(srcfile,resultfile, NoSpaceBefore, NoSpaceAfter,600);
132
        Edition editionweb = text.addEdition("default","html",resultfile);
133

    
134
        for(int i = 0 ; i < ed.getPageFiles().size();i++)
135
        {
136
                File f = ed.getPageFiles().get(i);
137
                String idx = ed.getIdx().get(i);
138
                editionweb.addPage(f,idx);
139
        }
140
        
141
//        Edition editionbp = text.addEdition("onepage","html",resultfile);
142
//        editionbp.addPage(resultfile,ed.getIdx().get(0));
143
}
144

    
145
w.save();