Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / importer / perrault / perraultLoader.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.perrault;
34

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

    
46
// TODO: Auto-generated Javadoc
47
/* (non-Javadoc)
48
 * @see groovy.lang.Script#run()
49
 */
50
String userDir = System.getProperty("user.home");
51
String rootDir;
52
String lang;
53
String encoding;
54
String model;
55
try{rootDir = rootDirBinding;lang=langBinding;encoding=encodingBinding;model=modelBinding;}
56
catch(Exception)
57
{        println "DEV MODE";//exception means we debug
58
        if(!org.txm.Toolbox.isInitialized())
59
        {
60
                rootDir = userDir+"/xml/perrault/";
61
                lang="fr";
62
                encoding= "UTF-8"; // not used
63
                model="fr";
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
String corpusSrc = "perrault.xml";
73

    
74
println "-- IMPORTER - Reading source files"
75
File[] files = [new File(rootDir,corpusSrc)];
76
new importer().run(files);
77

    
78
println "-- ANNOTATE - Running NLP tools"
79
new Annotate().run(new File(rootDir), model+".par");//the files in ./txm
80

    
81
println "-- COMPILING - Building Search Engine indexes"
82
files = new File(rootDir,"txm/").listFiles();
83
ArrayList<File> Lfiles = new ArrayList<File>();
84
for(File f : files)
85
        Lfiles.add f
86
def c = new compiler()
87
//c.setCwbPath("")// for developers
88
c.setLang(lang);
89
c.run(Lfiles);
90

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

    
97
Workspace w = org.txm.Toolbox.workspace;
98
Project p = w.getProject("default")
99
p.removeBase("perrault")
100
Base b = p.addBase("perrault");
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
        Edition editionweb = text.addEdition("default","web",resultfile);
122
        //println("pages "+ed.getPageFiles())
123
        //println("idx "+ed.getIdx())
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("bp","integral",resultfile);
132
//        editionbp.addPage(resultfile,ed.getIdx().get(0));
133
}