Statistics
| Revision:

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

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.scripts.importer.corptef;
34

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

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

    
72
File dir = new File(rootDir);
73

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

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

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

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

    
91

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

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

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

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

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

    
135
w.save();