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

alcesteLoader.groovy (revision 1094)
43 43
String userDir = System.getProperty("user.home");
44 44

  
45 45
def MONITOR;
46
Project project;
46 47
boolean debug = org.txm.utils.logger.Log.isPrintingErrors();
47
BaseParameters params;
48
try {params = paramsBinding;MONITOR=monitor} catch (Exception)
49
{	println "DEV MODE";//exception means we debug
50
	debug = true
51
	params = new BaseParameters(new File(userDir, "xml/TESTS/alceste2/import.xml"))
52
	params.load()
53
	if (!org.txm.Toolbox.isInitialized()) {
54
		Toolbox.setParam(Toolbox.INSTALL_DIR,new File("/usr/lib/TXM"));
55
		Toolbox.setParam(Toolbox.METADATA_ENCODING, "UTF-8");
56
		Toolbox.setParam(Toolbox.METADATA_COLSEPARATOR, ",");
57
		Toolbox.setParam(Toolbox.METADATA_TXTSEPARATOR, "\"");
58
		Toolbox.setParam(Toolbox.USER_TXM_HOME, new File(System.getProperty("user.home"), "TXM"));
59
	}
60
}
61
if (params == null) { println "no parameters. Aborting"; return; }
62 48

  
63
String corpusname = params.getCorpusName();
49
try {project=projectBinding;MONITOR=monitor} catch (Exception)
50
{	}
51
if (project == null) { println "no project set. Aborting"; return; }
64 52

  
65
Element corpusElem = params.corpora.get(corpusname);
66
String basename = params.name;
67
String rootDir = params.rootDir;
68
String lang = corpusElem.getAttribute("lang");
53
String corpusname = project.getName();
54
String basename = corpusname
55
String rootDir = project.getSrcdir();
56
String lang = project.getLang()
69 57
String model = lang
70
String encoding = corpusElem.getAttribute("encoding");
71
boolean annotate = "true" == corpusElem.getAttribute("annotate");
72
String xsl = params.getXsltElement(corpusElem).getAttribute("xsl")
73
def xslParams = params.getXsltParams(corpusElem);
74
int wordsPerPage = params.getWordsPerPage("default")
75
boolean build_edition = params.getDoEdition("default")
58
String encoding = project.getEncoding()
59
boolean annotate = project.getAnnotate()
60
String xsl = project.getFrontXSL();
61
def xslParams = project.getXsltParameters();
62
int wordsPerPage = project.getEditionDefinition("default").getWordsPerPage()
63
boolean build_edition = project.getEditionDefinition("default").getBuildEdition()
76 64

  
77 65
File srcDir = new File(rootDir);
78
File binDir = new File(Toolbox.getTxmHomePath(),"corpora/"+basename);
79
binDir.deleteDir();
66
File binDir = project.getProjectDirectory();
80 67
binDir.mkdirs();
81 68
if (!binDir.exists()) {
82 69
	println "Could not create binDir "+binDir
......
115 102
c.setAnnotationSuccess(annotationSuccess)
116 103
if (debug) c.setDebug();
117 104
c.setLang(lang);
118
if (!c.run(binDir, txmDir, corpusname)) {
105
if (!c.run(project)) {
119 106
	println "import process stopped";
120 107
	return;
121 108
}
......
146 133
		List<String> NoSpaceBefore = LangFormater.getNoSpaceBefore(lang);
147 134
		List<String> NoSpaceAfter = LangFormater.getNoSpaceAfter(lang);
148 135

  
149
		Element text = params.addText(params.corpora.get(corpusname), txtname, srcfile);
150

  
136
		//Element text = params.addText(params.corpora.get(corpusname), txtname, srcfile);
137
		Text t = new Text(project);
138
		t.setName(txtname);
139
		t.setSourceFile(srcfile)
140
		t.setTXMFile(srcfile)
151 141
		def ed = new pager_old(srcfile, outdir, txtname, NoSpaceBefore, NoSpaceAfter, wordsPerPage, basename, "pb");
152
		Element edition = params.addEdition(text, "default", outdir.getAbsolutePath(), "html");
153

  
142
		//Element edition = params.addEdition(text, "default", outdir.getAbsolutePath(), "html");
143
		Edition edition = new Edition(t);
144
		edition.setName("default");
145
		edition.setIndex(outdir.getAbsolutePath());
154 146
		for (i = 0 ; i < ed.getPageFiles().size();) {
155 147
			File f = ed.getPageFiles().get(i);
156 148
			String wordid = ed.getIdx().get(i);
157
			params.addPage(edition, ""+(++i), wordid);
149
			edition.addPage(""+(++i), wordid);
158 150
		}
159 151
	}
160 152
}
161 153

  
162 154
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); }
163 155
if (MONITOR != null) MONITOR.worked(20, "FINALIZING")
164
File paramFile = new File(binDir, "import.xml");
165
DomUtils.save(params.root.getOwnerDocument(), paramFile);readyToLoad = true;
156
//File paramFile = new File(binDir, "import.xml");
157
//DomUtils.save(params.root.getOwnerDocument(), paramFile);readyToLoad = true;
158
readyToLoad = project.save();

Also available in: Unified diff