Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / importer / corptef / corptefLoader.groovy @ 187

History | View | Annotate | Download (4.4 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-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
30
// $LastChangedRevision: 2386 $
31
// $LastChangedBy: mdecorde $ 
32
//
33
package org.txm.importer.corptef;
34

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

    
44
// TODO: Auto-generated Javadoc
45
/* (non-Javadoc)
46
 * @see groovy.lang.Script#run()
47
 */
48
String userDir = System.getProperty("user.home");
49
String rootDir;
50
String lang;
51
String encoding;
52
String model;
53
try{rootDir = rootDirBinding;lang=langBinding;encoding=encodingBinding;model=modelBinding;}
54
catch(Exception)
55
{        println "DEV MODE";//exception means we debug
56
        if(!org.txm.Toolbox.isInitialized())
57
        {
58
                //rootDir = "C:\\Documents and Settings\\alavrent\\TXM\\sources\\corptef\\src";
59
                rootDir = userDir+"/xml/corptef"
60
                lang="fr";
61
                encoding= "UTF-8";
62
                model="rgaqcj";
63
                Toolbox.workspace = new Workspace(new File(userDir,"TXM/workspaces/default.xml"));
64
                Toolbox.setParam(Toolbox.INSTALL_DIR,new File(userDir,"txminstall"));
65
                Toolbox.setParam(Toolbox.TREETAGGER_INSTALL_PATH,new File(userDir,"txminstall/treetagger"));
66
                Toolbox.setParam(Toolbox.TREETAGGER_MODELS_PATH,new File(userDir,"txminstall/treetagger/models"));
67
                Toolbox.setParam(Toolbox.USER_TXM_HOME, new File(System.getProperty("user.home"),"TXM"));
68
        }
69
}
70

    
71
File dir = new File(rootDir);
72

    
73
println "-- IMPORTER - Reading source files"
74
new importer().run(dir);
75

    
76
File binDir = new File(Toolbox.getParam(Toolbox.USER_TXM_HOME),"corpora/corptef");
77
rootDir = binDir.getAbsolutePath();
78
dir = new File(rootDir);
79

    
80
println "-- ANNOTATE - Running NLP tools"
81
new Annotate().run(dir,model+".par");
82

    
83
println "-- COMPILING - Building Search Engine indexes"
84
def c = new compiler();
85
c.setDebug();
86
//c.setCwbPath("C:/Program Files/TXM/cwb/bin");
87
c.setLang(lang);
88
c.run(dir);
89

    
90

    
91
//move registry file to cwb registry dir
92
File registryfile = new File(rootDir+"/registry","corptef");
93
if(registryfile.exists())
94
        org.txm.utils.FileCopy.copy(registryfile,new File(Toolbox.getParam(Toolbox.USER_TXM_HOME),"registry/corptef"))
95

    
96
Workspace w = org.txm.Toolbox.workspace;
97
Project p = w.getProject("default")
98
p.removeBase("corptef")
99
Base b = p.addBase("corptef");
100
b.addDirectory(new File(rootDir,"txm"));
101
b.setAttribute("lang", lang)
102
b.propagateAttribute("lang")
103

    
104
println "-- EDITION"
105
new File(rootDir+"/HTML/").deleteDir()
106
new File(rootDir+"/HTML/").mkdir();
107
new File(rootDir+"/HTML/default/").mkdir();
108
files = new File(rootDir,"txm").listFiles();
109

    
110
for(String textname : b.getTextsID())
111
{
112
        Text text = b .getText(textname);
113
        File srcfile = text.getSource();
114
        File resultfile = new File(rootDir+"/HTML",srcfile.getName().substring(0,srcfile.getName().length()-4)+".html");
115
        List<String> NoSpaceBefore = LangFormater.getNoSpaceBefore(lang);
116
        List<String> NoSpaceAfter = LangFormater.getNoSpaceAfter(lang);
117
        println("Building edition  : "+srcfile+" to : "+resultfile );
118
        
119
        def ed = new pager(srcfile,resultfile, NoSpaceBefore, NoSpaceAfter,600);
120
        ed.writecorrespondancesFile(new File(rootDir,"edition_correspondances.txt"))
121
        Edition editionweb = text.addEdition("default","html",resultfile);
122

    
123
        for(int i = 0 ; i < ed.getPageFiles().size();i++)
124
        {
125
                File f = ed.getPageFiles().get(i);
126
                String idx = ed.getIdx().get(i);
127
                editionweb.addPage(f,idx);
128
        }
129
        
130
//        Edition editionbp = text.addEdition("onepage","html",resultfile);
131
//        editionbp.addPage(resultfile,ed.getIdx().get(0));
132
}
133

    
134
w.save();