Statistics
| Revision:

root / tmp / org.txm.tigersearch.rcp / src / org / txm / importer / tigersearch / TSImport.groovy @ 715

History | View | Annotate | Download (2.9 kB)

1
package org.txm.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.BaseParameters
13
import org.txm.utils.BundleUtils;
14
import org.txm.utils.io.FileCopy;
15
import org.apache.log4j.BasicConfigurator;
16

    
17
class TSImport extends XTZImport {
18
        
19
        public TSImport(BaseParameters params) {
20
                super(params);
21
        }
22
        
23
        @Override
24
        public void init(BaseParameters p) {
25
                super.init(p);
26
                
27
                importer = new TSImporter(this); // only to build metadata
28
                compiler = new XTZCompiler(this)
29
                annotater = null; // no annotater step to do
30
                pager = new XTZPager(this)
31
        }
32
        
33
        @Override
34
        public void start() throws InterruptedException {                
35
                File tigerSrcDir = sourceDirectory
36
                File tsXSLFile = new File(Toolbox.getTXMHOMEPATH(), "xsl/ts.xsl");
37
                BundleUtils.copyFiles("TIGERSearchRCP", "src", "org/txm/importer/tigersearch", "ts.xsl", tsXSLFile.getParentFile());
38
                
39
                File xmltxmSrcDir = new File(binaryDirectory, "src"); // output directory of the TS XSL transformation
40
                
41
                if (!ApplyXsl2.processImportSources(tsXSLFile, sourceDirectory, xmltxmSrcDir)) {
42
                        println "Error while applying TS XSL file to $tigerSrcDir"
43
                        isSuccessful = false;
44
                        return;
45
                }
46
                
47
                File[] files = xmltxmSrcDir.listFiles();
48
                if (files == null || files.length == 0) {
49
                        println "Error while applying TS XSL file to $xmltxmSrcDir is empty"
50
                        isSuccessful = false;
51
                        return;
52
                }
53
                
54
                sourceDirectory = xmltxmSrcDir; // hop
55
                File txmDir = new File(binaryDirectory, "txm/"+corpusName); 
56
                txmDir.mkdirs();
57
                FileCopy.copyFiles(sourceDirectory, txmDir) // the compiler step will use these files
58
                super.start();
59
                
60
                if (isSuccessful) {
61
                        
62
                        File tigerDir = new File(binaryDirectory, "tiger");
63
                        tigerDir.mkdir();
64
                        File master = new File(tigerSrcDir, "master.xml");
65
                        
66
                        File logprop = new File(tigerDir, "tigersearch.logprop");
67
                        
68
                        logprop.withWriter("UTF-8") { writer ->
69
                                writer.write("""# Default log configuration of the TIGERSearch suite
70
log4j.rootLogger=WARN,Logfile
71
log4j.logger.ims.tiger.gui.tigersearch.TIGERSearch=INFO
72
log4j.appender.Logfile=org.apache.log4j.RollingFileAppender
73
log4j.appender.Logfile.File=\${user.home}/tigersearch/tigersearch.log
74
log4j.appender.Logfile.MaxFileSize=500KB
75
log4j.appender.Logfile.MaxBackupIndex=1
76
log4j.appender.Logfile.layout=org.apache.log4j.PatternLayout
77
log4j.appender.Logfile.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n""")        
78
                        }
79
                        
80
                        BasicConfigurator.configure();
81
                        String uri = master.getAbsolutePath();
82
                        File tigerBinDir = new File(tigerDir, corpusName)
83
                        tigerBinDir.mkdir()
84
                        try {
85
                                IndexBuilderErrorHandler handler = new SimpleErrorHandler(tigerBinDir.getAbsolutePath());
86
                                XMLIndexing indexing = new XMLIndexing(corpusName, uri, tigerBinDir.getAbsolutePath(), handler,false);
87
                                indexing.startIndexing();
88
                        }
89
                        catch (Exception e) { System.out.println(e.getMessage()); }
90
                }
91
        }
92
}