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