Revision 1094 tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/alceste/compiler.groovy

compiler.groovy (revision 1094)
27 27
//
28 28
package org.txm.scripts.importer.alceste;
29 29

  
30
import org.txm.objects.*
30 31
import org.txm.importer.cwb.CwbAlign;
31 32
import org.txm.importer.cwb.CwbEncode
32 33
import org.txm.importer.cwb.CwbMakeAll
......
36 37
import org.txm.utils.treetagger.TreeTagger;
37 38
import org.txm.core.preferences.TXMPreferences
38 39
import org.txm.libs.cqp.CQPLibPreferences
39

  
40
import org.txm.searchengine.cqp.corpus.*
40 41
import javax.xml.stream.*;
41 42

  
42 43
import java.net.URL;
......
53 54
 *
54 55
 * @author mdecorde
55 56
 */
56
class compiler 
57
{
57
class compiler {
58 58
	/** The debug. */
59
	private boolean debug = false;
59
	boolean debug = false;
60 60
	
61 61
	/** The input data. */
62 62
	private def inputData;
......
85 85
	/** The base. */
86 86
	String base = "";
87 87
	
88
	/** The project. */
89
	String project = "";
90
	
91
	/** The text attributes. */
92
	String[] textAttributes = null;
93
	
94 88
	/** The lang. */
95 89
	String lang = "fr";
96 90
	
......
109 103
	 * @param base the base
110 104
	 * @param project the project
111 105
	 */
112
	public compiler(URL url, String text, String base, String project)
106
	public compiler(URL url, String text, String base, String projectName)
113 107
	{
114 108
		this.text = text
115 109
		this.base = base;
116
		this.project = project;
117
		this.textAttributes = textAttributes;
118 110
		try {
119 111
			this.url = url;
120 112
			inputData = url.openStream();
......
171 163
	 *
172 164
	 * @param rootDirFile the root dir file
173 165
	 * @param basename the basename
174
	 * @param textAttributes the text attributes
175 166
	 * @return true, if successful
176 167
	 */
177
	public boolean run(File binDir, File txmDir, String corpusname, String[] textAttributes) 
168
	public boolean run(Project project) 
178 169
	{
170
		File binDir = project.getProjectDirectory()
171
		String corpusname = project.getName();
172
		File txmDir = new File(binDir, "txm/"+corpusname)
179 173
		if (!(CwbEncode.isExecutableAvailable() && CwbMakeAll.isExecutableAvailable())) {
180 174
			println ("Error: CWB executables not well set.")
181 175
			return false;
182 176
		}
183
		if (!binDir.exists()) {
184
			println ("binary directory does not exists: "+binDir)
185
			return false;
177
		
178
		CorpusBuild corpus = project.getCorpusBuild(project.getName());
179
		if (corpus != null) {
180
			println "CLEAN PREVIOUS CORPUS"
181
			corpus.delete(); // remove old files
186 182
		}
183
			
184
		// make new one
185
		corpus = new MainCorpus(project);
186
		corpus.setID(project.getName());
187
		corpus.setName(project.getName());
188
		corpus.setDescription("Build the alceste import module");
189
		
187 190
		File cqpFile = new File(binDir,"cqp/"+corpusname+".cqp");
188
		new File(binDir, "cqp").deleteDir();
189
		new File(binDir, "cqp").mkdir();
190
		new File(binDir, "data/$corpusname").deleteDir();
191
		new File(binDir, "data/$corpusname").mkdir();
192
		new File(binDir, "registry").mkdir();
191
		new File(binDir,"cqp").mkdirs()
192
		new File(binDir,"data").mkdirs()
193
		new File(binDir,"registry").mkdirs()
193 194
		
194 195
		String textid = "";
195 196
		int counttext = 0;
......
241 242
		}
242 243
		
243 244
		//2- Import into CWB
244
		String rootDir = binDir.getAbsolutePath();
245
		def outDir = binDir.getAbsolutePath();
245 246
		CwbEncode cwbEn = new CwbEncode();
246 247
		cwbEn.setDebug(debug);
247 248
		CwbMakeAll cwbMa = new CwbMakeAll();
......
255 256
		String[] sAttributes = sAttributesList.toArray(new String[sAttributesList.size()])
256 257
		
257 258
		try {
258
			String regPath = rootDir + "/registry/"+corpusname.toLowerCase(); // CQP wants lowercase registry name
259
			cwbEn.run(rootDir + "/data/${corpusname}", rootDir + "/cqp/"+corpusname+".cqp", regPath,pAttributes, sAttributes);
259
			String regPath = outDir + "/registry/"+corpusname.toLowerCase(); // CQP wants lowercase registry name
260
			cwbEn.run(outDir + "/data/${corpusname}", outDir + "/cqp/"+corpusname+".cqp", regPath,pAttributes, sAttributes);
260 261
			if (!new File(regPath).exists()) {
261
				println "The registry file was not created: $regPath. See https://groupes.renater.fr/wiki/txm-users/public/faq"
262
				println "Error: The registry file was not created: $regPath. See https://groupes.renater.fr/wiki/txm-users/public/faq"
262 263
				return false;
263 264
			}
264
			cwbMa.run(corpusname.toUpperCase(), rootDir + "/registry");
265
			cwbMa.run(corpusname.toUpperCase(), outDir + "/registry");
266
			
265 267
		} catch (Exception ex) {System.out.println(ex); return false;}
266 268

  
267 269
		return true;

Also available in: Unified diff