Index: TXM/trunk/bundles/org.txm.conllu.core/groovy/org/txm/scripts/importer/conllu/CoNLLUImport.groovy
===================================================================
--- TXM/trunk/bundles/org.txm.conllu.core/groovy/org/txm/scripts/importer/conllu/CoNLLUImport.groovy	(revision 3704)
+++ TXM/trunk/bundles/org.txm.conllu.core/groovy/org/txm/scripts/importer/conllu/CoNLLUImport.groovy	(revision 3705)
@@ -17,6 +17,7 @@
 import org.txm.scripts.importer.xtz.*
 import org.txm.scripts.importer.tigersearch.TSImport
 import org.txm.utils.*
+import org.txm.searchengine.cqp.corpus.MainCorpus
 import org.txm.searchengine.ts.TIGERSearchEngine
 import org.txm.conllu.core.preferences.UDPreferences
 import org.txm.tigersearch.preferences.TigerSearchPreferences
@@ -116,6 +117,13 @@
 			if (isSuccessful) {
 				// read from the 'tiger-xml' and write to the 'tiger' directory
 				TIGERSearchEngine.buildTIGERCorpus(tigerXMLDirectory, this.binaryDirectory, corpusName);
+				
+				// re-align TIGER word indexes with the CQP word indexes using the TS@editionId and CQP@id properties
+				File tigerDirectory = new File(this.binaryDirectory, "tiger");
+				File tigerCorpusExistingDirectory = new File(this.binaryDirectory, "tiger/"+corpusName);
+				MainCorpus corpus = this.project.getFirstChild(MainCorpus.class);
+				corpus.compute(false); // load  the corpus in CQP
+				TIGERSearchEngine.writeOffsetDataFiles(corpus, "editionId", tigerCorpusExistingDirectory, tigerDirectory, tigerCorpusExistingDirectory)
 			}
 		} else {
 			println "Can not do the TIGER indexes step."
Index: TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java
===================================================================
--- TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java	(revision 3704)
+++ TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java	(revision 3705)
@@ -5,8 +5,10 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.RandomAccessFile;
 import java.io.UnsupportedEncodingException;
 import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
@@ -29,19 +31,25 @@
 import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
 import org.txm.searchengine.cqp.clientExceptions.UnexpectedAnswerException;
 import org.txm.searchengine.cqp.corpus.CQPCorpus;
+import org.txm.searchengine.cqp.corpus.MainCorpus;
 import org.txm.searchengine.cqp.serverException.CqiServerError;
 import org.txm.tigersearch.preferences.TigerSearchPreferences;
 import org.txm.tigersearch.preferences.TigerSearchTreePreferences;
+import org.txm.utils.ConsoleProgressBar;
 import org.txm.utils.DeleteDir;
 import org.txm.utils.io.IOUtils;
 import org.txm.utils.logger.Log;
 
+import ims.tiger.corpus.Sentence;
+import ims.tiger.corpus.T_Node;
 import ims.tiger.index.reader.Index;
 import ims.tiger.index.reader.IndexException;
 import ims.tiger.index.writer.IndexBuilderErrorHandler;
 import ims.tiger.index.writer.SimpleErrorHandler;
 import ims.tiger.index.writer.XMLIndexing;
 import ims.tiger.query.api.MatchResult;
+import ims.tiger.query.api.QueryIndexException;
+import ims.tiger.query.processor.CorpusQueryProcessor;
 
 public class TIGERSearchEngine extends SearchEngine {
 	
@@ -392,4 +400,130 @@
 		}
 		return true;
 	}
+	
+
+	public static int writeOffsetDataFiles(MainCorpus corpus, String wordIdAttribute, File tigerCorpusDirectory, File tigerDirectory, File tigerCorpusExistingDirectory) throws IndexException, QueryIndexException, UnexpectedAnswerException, IOException, CqiServerError, CqiClientException {
+		
+		// TXM corpus files
+		File configfile = new File(tigerDirectory, "tigersearch.logprop");
+		
+		TSCorpusManager manager = new TSCorpusManager(tigerCorpusDirectory.getParentFile(), configfile);
+		TSCorpus tcorpus = manager.getCorpus(tigerCorpusDirectory.getName());
+		InternalCorpusQueryManagerLocal2 tigermanager = tcorpus.manager;
+		CorpusQueryProcessor processor = tigermanager.getQueryProcessor();
+		AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
+		
+		Index index = processor.getIndex();
+		int size = 0;
+		for (int nr = 0; nr < index.getNumberOfGraphs(); nr++) {
+			size += index.getNumberOfTNodes(nr);
+		}
+		
+		if (size == 0) {
+			Log.warning("No word found in the TIGERSearch corpus: " + tigerCorpusDirectory + ". Aborting.");
+			return 0;
+		}
+		
+		Log.info("Importing " + size + " word annotations...");
+		
+		// compute start position of sentences
+		int[] starts = new int[index.getNumberOfGraphs()];
+		for (int i = 0; i < index.getNumberOfGraphs(); i++) {
+			starts[i] = 0;
+			if (i > 0) {
+				starts[i] += index.getNumberOfTNodes(i - 1) + starts[i - 1];
+			}
+		}
+		
+		File offsetsFile = new File(tigerCorpusExistingDirectory, "offsets.data");
+		RandomAccessFile offsetsRAFile = new RandomAccessFile(offsetsFile, "rw");
+		FileChannel offsetsFileChannel = offsetsRAFile.getChannel();
+		MappedByteBuffer offsetsMapped = offsetsFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, size * Integer.BYTES);
+		// out.putInt(positions[i])
+		
+		File presencesFile = new File(tigerCorpusExistingDirectory, "presences.data");
+		RandomAccessFile presencesRAFile = new RandomAccessFile(presencesFile, "rw");
+		FileChannel presencesFileChannel = presencesRAFile.getChannel();
+		MappedByteBuffer presencesMapped = presencesFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, size);
+		
+		int numberOfWordsAnnotated = 0;
+		
+		// for each sentence
+		ConsoleProgressBar cpb = new ConsoleProgressBar(index.getNumberOfGraphs());
+		for (int nr = 0; nr < index.getNumberOfGraphs(); nr++) {
+			cpb.tick();
+			int sent_size = index.getNumberOfTNodes(nr);
+			Sentence sent = tcorpus.manager.getSentence(nr);
+			
+			String[] ids = new String[sent_size];
+			int[] tigerPositions = new int[sent_size];
+			for (int t = 0; t < sent_size; t++) {
+				T_Node terminal = (T_Node) sent.getTerminalAt(t);
+				ids[t] = terminal.getFeature(wordIdAttribute);
+				
+				// try fixing ID
+				if (ids[t].startsWith("w")) {
+					if (!ids[t].startsWith("w_")) {
+						ids[t] = "w_" + ids[t].substring(1);
+					}
+				}
+				else {
+					ids[t] = "w_" + ids[t];
+				}
+				tigerPositions[t] = starts[nr] + t;
+				// System.out.println("T id="+terminal.getID());
+			}
+			
+			int[] ids_idx = CQI.str2Id(corpus.getProperty("id").getQualifiedName(), ids);
+			Integer[] cqpPositions = new Integer[sent_size];
+			Integer[] offsets = new Integer[sent_size];
+			for (int t = 0; t < sent_size; t++) {
+				if (ids_idx[t] >= 0) {
+					int[] positions = CQI.id2Cpos(corpus.getProperty("id").getQualifiedName(), ids_idx[t]);
+					if (positions.length > 1) {
+						Log.warning("Warning: multiple CQP positions for word_id=" + ids[t]);
+					}
+					cqpPositions[t] = positions[0]; // take the first position
+				}
+				else { // word not in the CQP corpus
+					Log.warning("Could not find word for id=" + ids[t]);
+					cqpPositions[t] = null;
+				}
+				
+				if (cqpPositions[t] != null) {
+					offsets[t] = cqpPositions[t] - tigerPositions[t];
+				}
+				else {
+					offsets[t] = null;
+				}
+			}
+			// System.out.println("ids="+Arrays.toString(ids));
+			// System.out.println("cqp indexes="+Arrays.toString(ids_idx));
+			// System.out.println("tiger positions="+Arrays.toString(tigerPositions));
+			// System.out.println("cqp positions="+Arrays.toString(cqpPositions));
+			// System.out.println("offsets="+Arrays.toString(offsets));
+			
+			// writing data to offset and presences files
+			for (int t = 0; t < sent_size; t++) {
+				
+				if (offsets[t] != null) {
+					numberOfWordsAnnotated++;
+					presencesMapped.put((byte) 1);
+					offsetsMapped.putInt(offsets[t]);
+				}
+				else {
+					presencesMapped.put((byte) 0);
+					offsetsMapped.putInt(0);
+				}
+			}
+		}
+		cpb.done();
+		
+		offsetsFileChannel.close();
+		offsetsRAFile.close();
+		presencesFileChannel.close();
+		presencesRAFile.close();
+		
+		return numberOfWordsAnnotated;
+	}
 }
Index: TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/tigersearch/commands/ImportTIGERAnnotations.java
===================================================================
--- TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/tigersearch/commands/ImportTIGERAnnotations.java	(revision 3704)
+++ TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/tigersearch/commands/ImportTIGERAnnotations.java	(revision 3705)
@@ -28,6 +28,7 @@
 package org.txm.tigersearch.commands;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.nio.MappedByteBuffer;
@@ -50,6 +51,7 @@
 import org.txm.searchengine.cqp.corpus.MainCorpus;
 import org.txm.searchengine.cqp.serverException.CqiServerError;
 import org.txm.searchengine.ts.InternalCorpusQueryManagerLocal2;
+import org.txm.searchengine.ts.TIGERSearchEngine;
 import org.txm.searchengine.ts.TSCorpus;
 import org.txm.searchengine.ts.TSCorpusManager;
 import org.txm.utils.ConsoleProgressBar;
@@ -213,7 +215,8 @@
 			CqiServerError,
 			CqiClientException {
 		
-		// TXM corpus files
+
+		
 		File tigerDirectory = new File(corpus.getProjectDirectory(), "tiger");
 		File tigerCorpusExistingDirectory = new File(tigerDirectory, corpus.getName());
 		DeleteDir.deleteDirectory(tigerCorpusExistingDirectory);
@@ -223,128 +226,11 @@
 		if (!configfile.exists()) {
 			TSCorpus.createLogPropFile(tigerDirectory);
 		}
+	
+		int numberOfWordsAnnotated = TIGERSearchEngine.writeOffsetDataFiles(corpus, wordIdAttribute, tigerCorpusDirectory, tigerDirectory, tigerCorpusExistingDirectory);
 		
-		AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
-		
-		TSCorpusManager manager = new TSCorpusManager(tigerCorpusDirectory.getParentFile(), configfile);
-		
-		TSCorpus tcorpus = manager.getCorpus(tigerCorpusDirectory.getName());
-		InternalCorpusQueryManagerLocal2 tigermanager = tcorpus.manager;
-		CorpusQueryProcessor processor = tigermanager.getQueryProcessor();
-		
-		Index index = processor.getIndex();
-		int size = 0;
-		for (int nr = 0; nr < index.getNumberOfGraphs(); nr++) {
-			size += index.getNumberOfTNodes(nr);
-		}
-		
-		if (size == 0) {
-			Log.warning("No word found in the TIGERSearch corpus: " + tigerCorpusDirectory + ". Aborting.");
-			return 0;
-		}
-		
-		Log.info("Importing " + size + " word annotations...");
-		
-		// compute start position of sentences
-		int[] starts = new int[index.getNumberOfGraphs()];
-		for (int i = 0; i < index.getNumberOfGraphs(); i++) {
-			starts[i] = 0;
-			if (i > 0) {
-				starts[i] += index.getNumberOfTNodes(i - 1) + starts[i - 1];
-			}
-		}
-		
-		File offsetsFile = new File(tigerCorpusExistingDirectory, "offsets.data");
-		RandomAccessFile offsetsRAFile = new RandomAccessFile(offsetsFile, "rw");
-		FileChannel offsetsFileChannel = offsetsRAFile.getChannel();
-		MappedByteBuffer offsetsMapped = offsetsFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, size * Integer.BYTES);
-		// out.putInt(positions[i])
-		
-		File presencesFile = new File(tigerCorpusExistingDirectory, "presences.data");
-		RandomAccessFile presencesRAFile = new RandomAccessFile(presencesFile, "rw");
-		FileChannel presencesFileChannel = presencesRAFile.getChannel();
-		MappedByteBuffer presencesMapped = presencesFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, size);
-		
-		int numberOfWordsAnnotated = 0;
-		
-		// for each sentence
-		ConsoleProgressBar cpb = new ConsoleProgressBar(index.getNumberOfGraphs());
-		for (int nr = 0; nr < index.getNumberOfGraphs(); nr++) {
-			cpb.tick();
-			int sent_size = index.getNumberOfTNodes(nr);
-			Sentence sent = tcorpus.manager.getSentence(nr);
-			
-			String[] ids = new String[sent_size];
-			int[] tigerPositions = new int[sent_size];
-			for (int t = 0; t < sent_size; t++) {
-				T_Node terminal = (T_Node) sent.getTerminalAt(t);
-				ids[t] = terminal.getFeature(wordIdAttribute);
-				
-				// try fixing ID
-				if (ids[t].startsWith("w")) {
-					if (!ids[t].startsWith("w_")) {
-						ids[t] = "w_" + ids[t].substring(1);
-					}
-				}
-				else {
-					ids[t] = "w_" + ids[t];
-				}
-				tigerPositions[t] = starts[nr] + t;
-				// System.out.println("T id="+terminal.getID());
-			}
-			
-			int[] ids_idx = CQI.str2Id(corpus.getProperty("id").getQualifiedName(), ids);
-			Integer[] cqpPositions = new Integer[sent_size];
-			Integer[] offsets = new Integer[sent_size];
-			for (int t = 0; t < sent_size; t++) {
-				if (ids_idx[t] >= 0) {
-					int[] positions = CQI.id2Cpos(corpus.getProperty("id").getQualifiedName(), ids_idx[t]);
-					if (positions.length > 1) {
-						Log.warning("Warning: multiple CQP positions for word_id=" + ids[t]);
-					}
-					cqpPositions[t] = positions[0]; // take the first position
-				}
-				else { // word not in the CQP corpus
-					Log.warning("Could not find word for id=" + ids[t]);
-					cqpPositions[t] = null;
-				}
-				
-				if (cqpPositions[t] != null) {
-					offsets[t] = cqpPositions[t] - tigerPositions[t];
-				}
-				else {
-					offsets[t] = null;
-				}
-			}
-			// System.out.println("ids="+Arrays.toString(ids));
-			// System.out.println("cqp indexes="+Arrays.toString(ids_idx));
-			// System.out.println("tiger positions="+Arrays.toString(tigerPositions));
-			// System.out.println("cqp positions="+Arrays.toString(cqpPositions));
-			// System.out.println("offsets="+Arrays.toString(offsets));
-			
-			// writing data to offset and presences files
-			for (int t = 0; t < sent_size; t++) {
-				
-				if (offsets[t] != null) {
-					numberOfWordsAnnotated++;
-					presencesMapped.put((byte) 1);
-					offsetsMapped.putInt(offsets[t]);
-				}
-				else {
-					presencesMapped.put((byte) 0);
-					offsetsMapped.putInt(0);
-				}
-			}
-		}
-		cpb.done();
-		
-		offsetsFileChannel.close();
-		offsetsRAFile.close();
-		presencesFileChannel.close();
-		presencesRAFile.close();
-		
 		Log.info("Finalizing TIGERSearch corpus");
-		if (numberOfWordsAnnotated > 0) {
+		if (numberOfWordsAnnotated > 0) { // copy the TIGERcorpus to import
 			FileCopy.copyFiles(tigerCorpusDirectory, tigerCorpusExistingDirectory);
 			Log.info("Done. " + numberOfWordsAnnotated + " words annotated.");
 		}
@@ -354,4 +240,5 @@
 		
 		return numberOfWordsAnnotated;
 	}
+
 }
