Statistics
| Revision:

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

History | View | Annotate | Download (3.8 kB)

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