Statistics
| Revision:

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

History | View | Annotate | Download (3.7 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
        /**
34
         * Do a XTZ Import then build the TIGERSearch indexes in the binary corpus "tiger" directory
35
         */
36
        @Override
37
        public void start() throws InterruptedException {                
38
                File tigerSrcDir = sourceDirectory
39
                
40
                def xmlFiles = []
41
                sourceDirectory.listFiles(new FileFilter() {
42
                        boolean accept(File file) {
43
                                if (file.isDirectory()) return false;
44
                                if (file.isHidden()) return false;
45
                                if (file.getName().equals("import.xml")) return false;
46
                                if (!file.getName().endsWith(".xml")) return false;
47
                                
48
                                xmlFiles << file
49
                        }
50
                });
51
                
52
                xmlFiles.remove(new File(sourceDirectory, "import.xml"))
53
                
54
                if (xmlFiles.size() == 0) {
55
                        println "Error no XML file found in $sourceDirectory"
56
                        isSuccessful = false;
57
                        return;
58
                }
59
                
60
                File master = xmlFiles[0];
61
                println "Main TIGER XML file found: $master"
62
                
63
                File tsXSLFile = new File(Toolbox.getTXMHOMEPATH(), "xsl/ts.xsl");
64
                BundleUtils.copyFiles("TIGERSearchRCP", "src", "org/txm/importer/tigersearch", "ts.xsl", tsXSLFile.getParentFile());
65
                
66
                File xmltxmSrcDir = new File(binaryDirectory, "src"); // output directory of the TS XSL transformation
67
                xmltxmSrcDir.mkdirs();
68
                FileCopy.copy(master, new File(xmltxmSrcDir, master.getName()));
69
                        
70
                if (!ApplyXsl2.processImportSources(tsXSLFile, xmltxmSrcDir, xmltxmSrcDir)) {
71
                        println "Error while applying TS XSL file to $tigerSrcDir"
72
                        isSuccessful = false;
73
                        return;
74
                }
75
                
76
                File[] files = xmltxmSrcDir.listFiles();
77
                if (files == null || files.length == 0) {
78
                        println "Error while applying TS XSL file to $xmltxmSrcDir is empty"
79
                        isSuccessful = false;
80
                        return;
81
                }
82
                
83
                sourceDirectory = xmltxmSrcDir; // hop
84
                File txmDir = new File(binaryDirectory, "txm/"+corpusName); 
85
                txmDir.mkdirs();
86
                FileCopy.copyFiles(sourceDirectory, txmDir) // the compiler step will use these files
87
                
88
                super.start(); // call the usual XTZ import 
89
                
90
                if (isSuccessful) {
91
                        
92
                        File tigerDir = new File(binaryDirectory, "tiger");
93
                        tigerDir.mkdir();
94
                        
95
                                
96
                                File logprop = new File(tigerDir, "tigersearch.logprop");
97
                                
98
                                logprop.withWriter("UTF-8") { writer ->
99
                                        writer.write("""# Default log configuration of the TIGERSearch suite
100
log4j.rootLogger=WARN,Logfile
101
log4j.logger.ims.tiger.gui.tigersearch.TIGERSearch=WARNING
102
log4j.appender.Logfile=org.apache.log4j.RollingFileAppender
103
log4j.appender.Logfile.File=\${user.home}/tigersearch/tigersearch.log
104
log4j.appender.Logfile.MaxFileSize=500KB
105
log4j.appender.Logfile.MaxBackupIndex=1
106
log4j.appender.Logfile.layout=org.apache.log4j.PatternLayout
107
log4j.appender.Logfile.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n""")        
108
                                }
109
                                
110
                                BasicConfigurator.configure();
111
                                String uri = master.getAbsolutePath();
112
                                File tigerBinDir = new File(tigerDir, corpusName)
113
                                tigerBinDir.mkdir()
114
                                try {
115
                                        IndexBuilderErrorHandler handler = new SimpleErrorHandler(tigerBinDir.getAbsolutePath());
116
                                        XMLIndexing indexing = new XMLIndexing(corpusName, uri, tigerBinDir.getAbsolutePath(), handler,false);
117
                                        indexing.startIndexing();
118
                                }
119
                                catch (Exception e) { System.out.println(e.getMessage()); }
120
                        }
121
        }
122
}