Statistics
| Revision:

root / tmp / org.txm.tigersearch.rcp / groovy / org / txm / scripts / importer / tigersearch / TSImport.groovy @ 2129

History | View | Annotate | Download (3 kB)

1
package org.txm.scripts.importer.tigersearch;
2

    
3
import java.io.File;
4
import java.util.ArrayList;
5

    
6
import ims.tiger.index.writer.*
7
import ims.tiger.system.*
8

    
9
import org.txm.Toolbox;
10
import org.txm.importer.ApplyXsl2;
11
import org.txm.importer.xtz.*
12
import org.txm.objects.Project
13
import org.txm.utils.BundleUtils;
14
import org.txm.utils.io.FileCopy;
15
import org.txm.utils.io.IOUtils
16
import org.apache.log4j.BasicConfigurator;
17
import org.txm.importer.xtz.*
18
import org.txm.scripts.importer.xtz.*
19

    
20
class TSImport extends XTZImport {
21

    
22
        public TSImport(Project params) {
23
                super(params);
24
        }
25

    
26
        @Override
27
        public void init(Project p) {
28
                super.init(p);
29

    
30
                importer = new TSImporter(this); // select TIGER XML files then do XTZImporter step
31
                compiler = new XTZCompiler(this)
32
                annotater = null; // no annotater step to do
33
                pager = new XTZPager(this)
34
        }
35

    
36
        /**
37
         * Do a XTZ Import then build the TIGERSearch indexes in the binary corpus "tiger" directory
38
         */
39
        @Override
40
        public void start() throws InterruptedException {
41
                
42
                super.start(); // call the usual XTZ import
43
                
44
                if (isSuccessful) {
45

    
46
                        File tigerDir = new File(this.binaryDirectory, "tiger");
47
                        tigerDir.mkdir();
48

    
49
                        File logprop = new File(tigerDir, "tigersearch.logprop");
50

    
51
                        logprop.withWriter("UTF-8") { writer ->
52
                                writer.write("""# Default log configuration of the TIGERSearch suite
53
log4j.rootLogger=SEVERE,Logfile
54
log4j.logger.ims.tiger.gui.tigersearch.TIGERSearch=SEVERE
55
log4j.appender.Logfile=org.apache.log4j.RollingFileAppender
56
log4j.appender.Logfile.File=\${user.home}/tigersearch/tigersearch.log
57
log4j.appender.Logfile.MaxFileSize=500KB
58
log4j.appender.Logfile.MaxBackupIndex=1
59
log4j.appender.Logfile.layout=org.apache.log4j.PatternLayout
60
log4j.appender.Logfile.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n""")
61
                        }
62

    
63
                        BasicConfigurator.configure();
64
                        File master = new File(this.sourceDirectory, "main.xml");
65
                        if (!master.exists()) {
66
                                def xmlFiles = sourceDirectory.listFiles(new FileFilter() {
67
                                        boolean accept(File file) {
68
                                                if (file.isDirectory()) return false;
69
                                                if (file.isHidden()) return false;
70
                                                String filename = file.getName()
71
                                                if (filename.equals("import.xml")) return false;
72
                                                if (!filename.endsWith(".xml")) return false;
73
                                                
74
                                                return true;
75
                                        }
76
                                });
77
                        
78
                                master = xmlFiles[0]
79
                        }
80
                        String uri = master.getAbsolutePath(); // TIGER corpus source root file
81
                        File tigerBinDir = new File(tigerDir, corpusName)
82
                        tigerBinDir.mkdir()
83
                        try {
84
                                IndexBuilderErrorHandler handler = new SimpleErrorHandler(tigerBinDir.getAbsolutePath());
85
                                XMLIndexing indexing = new XMLIndexing(corpusName, uri, tigerBinDir.getAbsolutePath(), handler,false);
86
                                indexing.startIndexing();
87
                                File logs = new File(tigerBinDir, "indexing.log");
88
                                String txt = IOUtils.getText(logs);
89
                                if (txt.contains("Error in corpus graph ")) {
90
                                        println  "Error while importing TIGER corpus: "+txt;
91
                                        isSuccessful = false;
92
                                }
93
                        }
94
                        catch (Exception e) { System.out.println(e.getMessage()); }
95
                }
96
        }
97
        
98
        ArrayList<File> orderedFiles= null;
99
        protected ArrayList<File> getTXMFilesOrder() {
100
                orderedFiles;
101
        }
102
}