Index: tmp/org.txm.lexicaltable.core/src/org/txm/functions/intertextualdistance/InterTextDistance.java
===================================================================
--- tmp/org.txm.lexicaltable.core/src/org/txm/functions/intertextualdistance/InterTextDistance.java	(revision 243)
+++ tmp/org.txm.lexicaltable.core/src/org/txm/functions/intertextualdistance/InterTextDistance.java	(revision 244)
@@ -8,11 +8,11 @@
 import org.rosuda.REngine.REXP;
 import org.rosuda.REngine.REXPMismatchException;
 import org.txm.functions.Function;
+import org.txm.lexicaltable.core.statsengine.data.LexicalTable;
 import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
 import org.txm.searchengine.cqp.clientExceptions.InvalidCqpIdException;
-import org.txm.stat.StatException;
-import org.txm.stat.data.LexicalTable;
-import org.txm.stat.engine.r.RWorkspace;
+import org.txm.statsengine.core.StatException;
+import org.txm.statsengine.r.core.RWorkspace;
 
 public class InterTextDistance extends Function {
 	
Index: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/r/data/LexicalTableImpl.java
===================================================================
--- tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/r/data/LexicalTableImpl.java	(revision 0)
+++ tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/r/data/LexicalTableImpl.java	(revision 244)
@@ -0,0 +1,768 @@
+// Copyright © 2010-2013 ENS de Lyon.
+// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
+// Lyon 2, University of Franche-Comté, University of Nice
+// Sophia Antipolis, University of Paris 3.
+// 
+// The TXM platform is free software: you can redistribute it
+// and/or modify it under the terms of the GNU General Public
+// License as published by the Free Software Foundation,
+// either version 2 of the License, or (at your option) any
+// later version.
+// 
+// The TXM platform is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied
+// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more
+// details.
+// 
+// You should have received a copy of the GNU General
+// Public License along with the TXM platform. If not, see
+// http://www.gnu.org/licenses.
+// 
+// 
+// 
+// $LastChangedDate: 2016-09-19 10:31:00 +0200 (Mon, 19 Sep 2016) $
+// $LastChangedRevision: 3298 $
+// $LastChangedBy: mdecorde $ 
+//
+package org.txm.lexicaltable.core.statsengine.r.data;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+
+//import org.txm.functions.queryindex.*;
+import org.txm.index.core.functions.Index;
+import org.txm.index.core.functions.Line;
+import org.txm.lexicaltable.core.messages.LexicalTableCoreMessages;
+import org.txm.lexicaltable.core.statsengine.data.LexicalTable;
+import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
+import org.txm.searchengine.cqp.corpus.Corpus;
+import org.txm.searchengine.cqp.corpus.Lexicon;
+import org.txm.searchengine.cqp.corpus.Partition;
+import org.txm.searchengine.cqp.corpus.Property;
+import org.txm.statsengine.core.StatException;
+import org.txm.statsengine.core.data.QuantitativeDataStructure;
+import org.txm.statsengine.core.data.Vector;
+import org.txm.statsengine.r.core.RException;
+import org.txm.statsengine.r.core.RWorkspace;
+import org.txm.statsengine.r.core.RWorkspaceException;
+import org.txm.statsengine.r.core.data.ContingencyTableImpl;
+
+import cern.colt.matrix.DoubleFactory2D;
+import cern.colt.matrix.DoubleMatrix2D;
+
+
+
+
+// TODO: Auto-generated Javadoc
+/**
+ * Implementation of the {@link LexicalTable} interface, wrapping a R matrix.
+ * 
+ * A lexical table is a contingency table representing the frequencies of
+ * linguistic types accross several sub-parts of a corpus.
+ * 
+ * Each column of the lexical table stand for a parts. Each row stand for a
+ * linguistic type. Each cell give the frequency of the corresponding unit into
+ * the corresponding part.
+ * 
+ * @author Sylvain Loiseau &lt;sloiseau@ens-lsh.fr&gt;
+ * 
+ */
+public class LexicalTableImpl extends ContingencyTableImpl implements LexicalTable {
+
+	/** The partition. */
+	private Partition partition;
+
+	/** The corpus. */
+	private Corpus corpus;
+
+	/** The property. */
+	private Property property;
+
+	/** The sortedindex. */
+	private int[] sortedindex;
+
+	/** The constructor_fmin. */
+	private int constructor_fmin;
+
+
+	/**
+	 * Instantiates a new lexical table impl.
+	 *
+	 * @param matrix the matrix
+	 * @param partition the partition
+	 * @param property the property
+	 * @param formNames the form names
+	 * @param partNames the part names
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	private LexicalTableImpl(DoubleMatrix2D matrix, Partition partition,
+			Property property, String[] formNames, String[] partNames)
+					throws RWorkspaceException {
+		super(matrix, formNames, partNames);
+
+		this.partition = partition;
+		this.partition.addResult(this);
+		this.property = property;
+		initSortedIndex();
+	}
+
+	/**
+	 * Instantiates a new lexical table impl.
+	 *
+	 * @param matrix the matrix
+	 * @param property the property
+	 * @param formNames the form names
+	 * @param partNames the part names
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	private LexicalTableImpl(DoubleMatrix2D matrix, Property property,
+			String[] formNames, String[] partNames) throws RWorkspaceException {
+		super(matrix, formNames, partNames);
+
+		this.property = property;
+		initSortedIndex();
+
+	}
+
+	/**
+	 * Instantiates a new lexical table impl.
+	 *
+	 * @param mat the mat
+	 * @param partition the partition
+	 * @param property the property
+	 * @param array the array
+	 * @param array2 the array2
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	public LexicalTableImpl(int[][] mat, Partition partition,
+			Property property, String[] array, String[] array2) throws RWorkspaceException {
+		this(mat,property, array, array2);
+		this.partition = partition;
+		this.partition.addResult(this);
+	}
+
+	/**
+	 * Instantiates a new lexical table impl.
+	 *
+	 * @param matrix the matrix
+	 * @param property the property
+	 * @param formNames the form names
+	 * @param partNames the part names
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	private LexicalTableImpl(int[][] matrix, Property property,
+			String[] formNames, String[] partNames) throws RWorkspaceException {
+		super(matrix, formNames, partNames);
+
+		this.property = property;
+		initSortedIndex();
+
+	}
+
+	/**
+	 * Instantiates a new lexical table impl.
+	 *
+	 * @param table the table
+	 * @param symbol the symbol
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	public LexicalTableImpl(LexicalTableImpl table, String symbol)
+			throws RWorkspaceException {
+		super(symbol);
+		this.partition = table.getPartition();
+		this.partition.addResult(this);
+		this.property = table.getProperty();
+		initSortedIndex();
+	}
+
+	
+	/**
+	 * Instantiates a new lexical table impl.
+	 *
+	 * @param table the table
+	 * @param symbol the symbol
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	public LexicalTableImpl(String symbol)
+			throws RWorkspaceException {
+		super(symbol);
+		this.partition = null;
+		this.property = null;
+	}
+
+	public LexicalTableImpl(String symbol, Lexicon corpusLexicon, Lexicon subcorpusLexicon) throws StatException {
+		super(symbol);
+		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
+		Vector corpusLexiconV = corpusLexicon.asVector();
+		Vector subcorpusLexiconV = subcorpusLexicon.asVector();
+		
+		rw.callFunction("lexicons2LexicalTable", new QuantitativeDataStructure[] { corpusLexiconV, subcorpusLexiconV }, symbol); //$NON-NLS-1$
+		
+		this.property = corpusLexicon.getProperty();
+		this.corpus = corpusLexicon.getCorpus();
+		this.corpus.addResult(this);
+	}
+
+	/**
+	 * Inits the sorted index.
+	 */
+	public void initSortedIndex() {
+		int ncol = this.getNColumns();
+		sortedindex = new int[ncol];
+		for (int i = 0; i < ncol; i++)
+			sortedindex[i] = i;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.txm.stat.data.LexicalTable#getPartition()
+	 */
+	@Override
+	public Partition getPartition() {
+		return partition;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.txm.stat.data.LexicalTable#getProperty()
+	 */
+	@Override
+	public Property getProperty() {
+		return property;
+	}
+
+	/**
+	 * Create a Complete Lexical Table according to a Partition and a Property.
+	 *
+	 * @param partition the partition
+	 * @param analysisProperty the analysis property
+	 * @param Fmin the fmin
+	 * @return the lexical table
+	 * @throws CqiClientException the cqi client exception
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	public static final LexicalTable getLexicalTable(Partition partition,
+			Property analysisProperty, int Fmin) throws CqiClientException,
+			RWorkspaceException {
+		//long time = System.currentTimeMillis();
+		List<Lexicon> lexicons = new ArrayList<Lexicon>();
+		// Set<String> allLexiconEntry = new HashSet<String>();
+		for (int i = 0; i < partition.getNPart(); i++) {
+			Lexicon l = partition.getParts().get(i).getLexicon(analysisProperty);
+			lexicons.add(l);
+			// allLexiconEntry.addAll(Arrays.asList(l.getForms()));
+		}
+		//System.out.println("time lexicon build "+(System.currentTimeMillis()-time));
+		//time = System.currentTimeMillis();
+		// String[] entries = allLexiconEntry.toArray(new String[]{});
+		Corpus c = partition.getCorpus();
+		Lexicon ll = c.getLexicon(analysisProperty);
+
+		ArrayList<String> filteredForms = new ArrayList<String>();
+		//create a copy and filter line with Fmin;
+		for (int i = 0 ; i < ll.getFreq().length ; i++) {
+			if (ll.getFreq()[i] >= Fmin) {
+				filteredForms.add(ll.getForms()[i]);
+			}
+		}
+		//System.out.println("remove freq too low "+(System.currentTimeMillis()-time));
+		//time = System.currentTimeMillis();
+		Map<String, Integer> entries2index = new HashMap<String, Integer>();
+		for (int i = 0; i < filteredForms.size(); i++) {
+			entries2index.put(filteredForms.get(i), i);
+		}
+
+		//System.out.println("entries2index "+(System.currentTimeMillis()-time));
+		//time = System.currentTimeMillis();
+		int[][] mat = new int[filteredForms.size()][lexicons.size()];//DoubleFactory2D.sparse.make(filteredForms.size(), lexicons.size(), 0);
+
+
+		Integer id= null;
+		for (int i = 0; i < lexicons.size(); i++) {
+			Lexicon l = lexicons.get(i);
+			String[] ents = l.getForms();
+			int[] freqs = l.getFreq();
+			for (int j = 0; j < freqs.length; j++) {
+				id = entries2index.get(ents[j]);
+				// if (entriesFreqs[id] >= 2)
+				if (id != null)
+					mat[id][i] = freqs[j]; //mat.setQuick(id, i, freqs[j]);
+			}
+		}
+		//System.out.println("time build matrix "+(System.currentTimeMillis()-time));
+		//time = System.currentTimeMillis();
+		//System.out.println("Entries size " + filteredForms.size());
+		//System.out.println("mat size " + mat.rows());
+		//System.out.println("mat columns " + mat.columns());
+
+		LexicalTableImpl table = new LexicalTableImpl(mat, partition,
+				analysisProperty, filteredForms.toArray(new String[]{}), partition.getPartShortNames()
+				.toArray(new String[] {}));
+		table.constructor_fmin = Fmin;
+		//System.out.println("time build table lexical "+(System.currentTimeMillis()-time));
+		return table;
+	}
+
+	/**
+	 * Creates the lexical table impl.
+	 *
+	 * @param partindex the partindex
+	 * @param symbol the symbol
+	 * @return the lexical table
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	static public LexicalTable createLexicalTableImpl(Index partindex,
+			String symbol) throws RWorkspaceException {
+		List<Index> vocabularies = new ArrayList<Index>();
+		vocabularies.add(partindex);
+		
+		LexicalTable lt = createLexicalTableImpl(vocabularies, symbol, false);
+		lt.setParent(partindex);
+		return lt;
+	}
+
+	private static int getNline(File f) {
+		try {
+			BufferedReader reader = new BufferedReader(new FileReader(f));
+			int i = 0;
+
+			while(reader.readLine() != null) i++;
+			return i;
+		} catch (Exception e) { return 0; }
+
+	}
+	
+//	/**
+//	 * Creates the lexical table impl.
+//	 *
+//	 * @param partindex the partindex
+//	 * @param symbol the symbol
+//	 * @return the lexical table
+//	 * @throws RWorkspaceException the r workspace exception
+//	 */
+//	static public LexicalTable createLexicalTableImpl(QueryIndex partindex,
+//			String symbol) throws RWorkspaceException {
+//		List<QueryIndex> qindexes = new ArrayList<QueryIndex>();
+//		qindexes.add(partindex);
+//
+//		return createLexicalTableImpl(qindexes, symbol);
+//	}
+	
+//	/**
+//	 * Creates the lexical table impl.
+//	 *
+//	 * @param query indexes 
+//	 * @param symbol the symbol
+//	 * @param useAllOccurrences 
+//	 * @return the lexical table
+//	 * @throws RWorkspaceException the r workspace exception
+//	 */
+//	static public LexicalTable createLexicalTableImpl(
+//		List<QueryIndex> qindexes, String symbol)
+//					throws RWorkspaceException {
+//
+//		System.out.println(Messages.LexicalTableImpl_1 + qindexes);
+//		QueryIndex partindex = qindexes.get(0);// FRIGO
+//		if (!partindex.isComputedWithPartition())
+//			return null;
+//
+//		Partition partition = partindex.getPartition();
+//		Property property = null;
+//		try {
+//			property = partindex.getCorpus().getProperties().get(0);
+//		} catch (CqiClientException e) {
+//			// TODO Auto-generated catch block
+//			org.txm.utils.logger.Log.printStackTrace(e);
+//		}
+//
+//		HashMap<String, QueryIndexLine> alllines = new HashMap<String, QueryIndexLine>();
+//		// merge lines of all indexes
+//		for (QueryIndex voc : qindexes) {
+//			for (QueryIndexLine l : voc.getLines()) {
+//				alllines.put(l.getName(), l);
+//			}
+//		}
+//
+//		List<String> colnames = partindex.getPartnames();
+//
+//		Collection<QueryIndexLine> lines = alllines.values();
+//		List<String> rownames = new ArrayList<String>(lines.size());
+//		for (QueryIndexLine l : lines) {
+//			rownames.add(l.getName());
+//		}
+//
+//		String[] entries = new String[alllines.size()];
+//
+//		int[][] mat = new int[rownames.size()][colnames.size()];
+//		int[] margins = new int[colnames.size()]; // compute margins
+//		int i = 0;
+//		for (QueryIndexLine l : lines) {
+//			for (int j = 0; j < colnames.size(); j++) {
+//				mat[i][j] = l.getFrequency(j);
+//				margins[j] += l.getFrequency(j);
+//			}
+//			entries[i++] = l.toString();
+//		}
+//
+//		//System.out.println("mat size : ["+(rownames.size() + extra)+"]["+colnames.size()+"]");
+//		//System.out.println("rownames size : "+rownames.size());
+//		//System.out.println("colnames size : "+colnames.size());
+//		LexicalTableImpl table = new LexicalTableImpl(mat, partition, property,
+//				rownames.toArray(new String[] {}), colnames
+//				.toArray(new String[] {}));
+//		table.constructor_fmin = qindexes.get(0).getFmin();
+//		return table;
+//	}
+	
+
+	static public LexicalTable createLexicalTableImpl(File tsvFile) throws IOException, RWorkspaceException {
+		
+		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(tsvFile) , "UTF-8")); //$NON-NLS-1$
+		String line = reader.readLine();
+		String[] split = line.split("\t"); //$NON-NLS-1$
+		int ncol = split.length;
+		if (ncol <= 1) {
+			throw new IOException(LexicalTableCoreMessages.LexicalTableImpl_5+ncol+")"); //$NON-NLS-1$
+		}
+		
+		int nlines = getNline(tsvFile);
+		String[] forms = new String[nlines];
+		int[][] freqs = new int[nlines][ncol-1];
+		
+		int i = 0;
+		while(line != null) {
+			split = line.split("\t"); //$NON-NLS-1$
+			if (split.length == ncol) {
+				forms[i] = split[0];
+				for( int j = 1 ; j < ncol ; j++)
+					freqs[i][j-1] = Integer.parseInt(split[j]);
+			} else {
+				throw new IOException(LexicalTableCoreMessages.LexicalTableImpl_8+i+LexicalTableCoreMessages.LexicalTableImpl_9+ncol+LexicalTableCoreMessages.LexicalTableImpl_10);
+			}
+			i++;
+			line = reader.readLine();
+		}
+		
+		String[] colnames = new String[ncol-1];
+		for( int j = 0 ; j < ncol - 1 ; j++) colnames[j] = "forms"+(j+1); //$NON-NLS-1$
+		
+		LexicalTable lt = LexicalTableImpl.createLexicalTable(freqs, null, forms, colnames, 1);
+		
+		return lt;
+	}
+
+	/**
+	 * Creates the lexical table impl.
+	 *
+	 * @param vocabularies the vocabularies
+	 * @param symbol the symbol
+	 * @param useAllOccurrences 
+	 * @return the lexical table
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	static public LexicalTable createLexicalTableImpl(
+			List<Index> vocabularies, String symbol, boolean useAllOccurrences)
+					throws RWorkspaceException {
+
+		System.out.println(LexicalTableCoreMessages.LexicalTableImpl_1 + vocabularies);
+		Index partindex = vocabularies.get(0);// FRIGO
+		if (!partindex.isComputedWithPartition())
+			return null;
+
+		Partition partition = partindex.getPartition();
+		Property property = partindex.getProperties().get(0);
+
+		HashMap<String, Line> alllines = new HashMap<String, Line>();
+		// merge lines of all indexes
+		for (Index voc : vocabularies) {
+			for (Line l : voc.getAllLines()) {
+				if (alllines.containsKey(l.getSignature())) {
+					Line ll = alllines.get(l.getSignature());
+					int[] c1 = ll.getFrequencies();
+					int[] c2 = l.getFrequencies();
+					for (int i = 0; i < c1.length; i++)
+						c2[i] += c1[i];
+					ll.setCounts(c2, 0.0f);
+				} else
+					alllines.put(l.toString(), l);
+			}
+		}
+
+		List<String> colnames = partindex.getPartnames();
+
+		Collection<Line> lines = alllines.values();
+		List<String> rownames = new ArrayList<String>(lines.size());
+		for (Line l : lines) {
+			rownames.add(l.toString());
+		}
+		int extra = 0;
+		if(useAllOccurrences)
+			extra = 1;
+
+		String[] entries = new String[alllines.size() + extra];
+
+
+		int[][] mat = new int[rownames.size() + extra][colnames.size()];
+		int[] margins = new int[colnames.size()]; // compute margins
+		int i = 0;
+		for (Line l : lines) {
+			for (int j = 0; j < colnames.size(); j++) {
+				mat[i][j] = l.getFrequency(j);
+				margins[j] += l.getFrequency(j);
+			}
+			entries[i++] = l.toString();
+		}
+
+		if (useAllOccurrences) {
+			try {
+				int[] partitionSizes = partition.getPartSizes();
+				int[] reste = new int[partitionSizes.length];
+
+				//System.out.println("margins : "+Arrays.toString(margins));
+				//System.out.println("partsizes : "+Arrays.toString(partitionSizes));
+
+				for(i = 0 ; i < reste.length ; i++)
+				{
+					reste[i] = partitionSizes[i] - margins[i];
+					if(reste[i] < 0)
+					{
+						System.out.println(LexicalTableCoreMessages.LexicalTableImpl_12+i+LexicalTableCoreMessages.LexicalTableImpl_13);
+						return null;
+					}
+					mat[lines.size()][i] = reste[i];
+				}
+				entries[lines.size()] = "#RESTE#"; //$NON-NLS-1$
+				rownames.add("#RESTE#"); //$NON-NLS-1$
+				//System.out.println("rownames: "+rownames);
+				//System.out.println("reste : "+Arrays.toString(reste));
+			} catch (CqiClientException e) {
+				// TODO Auto-generated catch block
+				org.txm.utils.logger.Log.printStackTrace(e);
+			}
+
+		}
+		//System.out.println("mat size : ["+(rownames.size() + extra)+"]["+colnames.size()+"]");
+		//System.out.println("rownames size : "+rownames.size());
+		//System.out.println("colnames size : "+colnames.size());
+		LexicalTableImpl table = new LexicalTableImpl(mat, partition, property,
+				rownames.toArray(new String[] {}), colnames
+				.toArray(new String[] {}));
+		table.constructor_fmin = vocabularies.get(0).getFmin();
+		return table;
+	}
+
+	/**
+	 * Creates the lexical table.
+	 *
+	 * @param freqs the freqs
+	 * @param prop the prop
+	 * @param rownames the rownames
+	 * @param colnames the colnames
+	 * @param Fmin the fmin
+	 * @return the lexical table
+	 * @throws RWorkspaceException the r workspace exception
+	 */
+	public static LexicalTable createLexicalTable(int[][] freqs, Property prop,
+			String[] rownames, String[] colnames, int Fmin) throws RWorkspaceException {
+
+		ArrayList<Integer> idx = new ArrayList<Integer>();
+		for (int j = 0; j < rownames.length; j++) 
+		{
+			int sum = 0;
+			for (int i = 0; i < colnames.length; i++) 
+			{
+				sum += freqs[j][i];
+			}
+			if (sum >= Fmin)
+				idx.add(j);
+		}
+
+		DoubleMatrix2D mat = DoubleFactory2D.sparse.make(idx.size(), colnames.length, 0);
+
+		int countline = 0;
+		for (int j : idx) 
+		{
+			for (int i = 0; i < colnames.length; i++) 
+			{
+				mat.setQuick(countline, i, freqs[j][i]);
+			}
+			countline++;
+		}
+
+		String[] filteredrownames = new String[idx.size()];
+		for(int i = 0 ; i < idx.size() ; i++)
+			filteredrownames[i] = rownames[idx.get(i)];
+
+		LexicalTableImpl table = new LexicalTableImpl(mat, prop, filteredrownames, colnames);
+		table.constructor_fmin = Fmin;
+		return table;
+	}
+
+
+	@Override
+	public LexicalTable getCopy() {
+		try {
+			if (partition != null)
+				return getLexicalTable(this.partition, this.property,this.constructor_fmin);
+			else
+				return null;
+		} catch (Exception e) {
+			org.txm.utils.logger.Log.printStackTrace(e);
+		}
+		return null;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.txm.stat.data.LexicalTable#getFmax()
+	 */
+	@Override
+	public int getFmax() {
+		List<Integer> freqs = getFreqs();
+		int max = 0;
+		for (int i : freqs)
+			if (max < i)
+				max = i;
+		return max;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.txm.stat.data.LexicalTable#getFmin()
+	 */
+	@Override
+	public int getFmin() {
+		List<Integer> freqs = getFreqs();
+		int min = 999999;
+		for (int i : freqs)
+			if (min > i)
+				min = i;
+		return min;
+	}
+
+	/* (non-Javadoc)
+	 * 
+	 * TODO: = rowmargins ?
+	 * @see org.txm.stat.data.LexicalTable#getFreqs()
+	 */
+	@Override
+	public List<Integer> getFreqs() {
+		ArrayList<Integer> freqs = new ArrayList<Integer>();
+		ArrayList<double[]> cols = new ArrayList<double[]>();
+		int Nrows = this.getNRows();
+		int Ncols = this.getNColumns();
+		for (int i = 0; i < Ncols; i++)
+			try {
+				cols.add(this.getCol(i).asDoubleArray());
+			} catch (RException e) {
+				// TODO Auto-generated catch block
+				org.txm.utils.logger.Log.printStackTrace(e);
+			} catch (RWorkspaceException e) {
+				// TODO Auto-generated catch block
+				org.txm.utils.logger.Log.printStackTrace(e);
+			} catch (StatException e) {
+				// TODO Auto-generated catch block
+				org.txm.utils.logger.Log.printStackTrace(e);
+			}
+		int sum = 0;
+
+		for (int i = 0; i < Nrows; i++) {
+			sum = 0;
+			for (int j = 0; j < Ncols; j++)
+				sum += (int) cols.get(j)[i];
+			freqs.add(sum);
+		}
+		return freqs;
+	}
+
+	public void setReference(String refSymbol) {
+		try {
+			RWorkspace rw = RWorkspace.getRWorkspaceInstance();
+			rw.voidEval("missingrownames <- rownames("+symbol+")[!rownames("+symbol+")%in%rownames("+refSymbol+")]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			rw.voidEval("missingrows <- matrix(ncol=1, nrow=length(missingrownames))"); //$NON-NLS-1$
+			rw.voidEval("missingrows[,] <- 0"); //$NON-NLS-1$
+			rw.voidEval("rownames(missingrows) <- missingrownames"); //$NON-NLS-1$
+			rw.voidEval(refSymbol+" <- t(t(rbind("+refSymbol+", t(t(missingrows)))))"); //$NON-NLS-1$ //$NON-NLS-2$
+			rw.voidEval("refLines <- t(t("+refSymbol+"[rownames("+symbol+"),]))"); // only keep the same lines  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+			rw.voidEval("rmargins <-  t(t(margin.table("+symbol+", 1)))"); //  //$NON-NLS-1$ //$NON-NLS-2$
+			rw.voidEval("refmargin <- margin.table(refLines)"); //$NON-NLS-1$
+			rw.voidEval(symbol+" <- cbind("+symbol+", abs(refLines - rmargins))"); // use abs if refLine does not contains a line from 'symbol' //$NON-NLS-1$ //$NON-NLS-2$
+			rw.voidEval("colnames("+symbol+")[length(colnames("+symbol+"))] <- \"##RESTE##\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			org.txm.utils.logger.Log.printStackTrace(e);
+		}
+	}
+
+	/* (non-Javadoc)
+	 * @see org.txm.stat.data.LexicalTable#getConstructorFmin()
+	 */
+	@Override
+	public int getConstructorFmin() {
+		return constructor_fmin;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.txm.stat.data.LexicalTable#getCorpus()
+	 */
+	@Override
+	public Corpus getCorpus() {
+		try {
+			return ((Partition)this.parent).getCorpus();
+		}
+		catch(Exception e) {
+		}
+		return (Corpus) this.parent;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.txm.stat.data.LexicalTable#setCorpus(org.txm.searchengine.cqp.corpus.Corpus)
+	 */
+	@Override
+	public void setCorpus(Corpus corpus)
+	{
+		this.corpus = corpus;
+	}
+
+	@Override
+	public int getRowsCount() {
+		return this.getNRows();
+	}
+
+	@Override
+	public int getColumnsCount() {
+		return this.getNColumns();
+	}
+
+	
+	@Override
+	public String getName() {
+		return this.getPartition().getSimpleName() + ":" + this.getSimpleName(); //$NON-NLS-1$
+	}
+
+	@Override
+	public String getSimpleName() {
+		return property.getName() + " (" + this.getFmin() + " / " + this.getNRows() + ")";
+	}
+
+	@Override
+	public String getDetails() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void clean() {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

Property changes on: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/r/data/LexicalTableImpl.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/data/LexicalTable.java
===================================================================
--- tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/data/LexicalTable.java	(revision 0)
+++ tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/data/LexicalTable.java	(revision 244)
@@ -0,0 +1,272 @@
+// Copyright © 2010-2013 ENS de Lyon.
+// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
+// Lyon 2, University of Franche-Comté, University of Nice
+// Sophia Antipolis, University of Paris 3.
+// 
+// The TXM platform is free software: you can redistribute it
+// and/or modify it under the terms of the GNU General Public
+// License as published by the Free Software Foundation,
+// either version 2 of the License, or (at your option) any
+// later version.
+// 
+// The TXM platform is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied
+// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more
+// details.
+// 
+// You should have received a copy of the GNU General
+// Public License along with the TXM platform. If not, see
+// http://www.gnu.org/licenses.
+// 
+// 
+// 
+// $LastChangedDate: 2016-09-19 10:31:00 +0200 (Mon, 19 Sep 2016) $
+// $LastChangedRevision: 3298 $
+// $LastChangedBy: mdecorde $ 
+//
+package org.txm.lexicaltable.core.statsengine.data;
+
+import java.io.File;
+import java.util.List;
+
+import org.rosuda.REngine.REXPMismatchException;
+import org.txm.core.results.ITXMResult;
+import org.txm.searchengine.cqp.corpus.Corpus;
+import org.txm.searchengine.cqp.corpus.Partition;
+import org.txm.searchengine.cqp.corpus.Property;
+import org.txm.statsengine.core.StatException;
+import org.txm.statsengine.core.data.ContingencyTable;
+import org.txm.statsengine.core.data.Vector;
+import org.txm.statsengine.r.core.RWorkspaceException;
+
+// TODO: Auto-generated Javadoc
+/**
+ * A LexicalTable is a special kind of {@link ContingencyTable} extracted from a
+ * corpora given a {@link Partition} (the columns) and a {@link Property} (the
+ * rows).
+ * 
+ * Can be edited, rows can be deleted cols can be deleted
+ * 
+ * can be exported of imported from/to a file
+ * 
+ * @author sloiseau
+ */
+public interface LexicalTable extends ContingencyTable, ITXMResult {
+
+	/**
+	 * Get the partition this lexical table is bound to.
+	 * 
+	 * @return the partition
+	 */
+	public abstract Partition getPartition();
+
+	/**
+	 * Get the property this lexical table is bound to.
+	 * 
+	 * @return the property.
+	 */
+	public abstract Property getProperty();
+
+	/**
+	 * Insert a column representing the reference corpus
+	 * @param symbol
+	 */
+	public abstract void setReference(String symbol);
+	
+	/**
+	 * Gets the copy.
+	 *
+	 * @return the copy
+	 */
+	public abstract LexicalTable getCopy();
+
+	/**
+	 * Sort.
+	 *
+	 * @param colindex the colindex
+	 * @param reverse the reverse
+	 */
+	public abstract void sort(int colindex, Boolean reverse);
+
+	/**
+	 * Sort row names.
+	 *
+	 * @param reverse the reverse
+	 */
+	public void sortRowNames(Boolean reverse);
+
+	/**
+	 * Removes the col.
+	 *
+	 * @param col the col
+	 * @param checkEmptyLines the check empty lines
+	 */
+	public abstract void removeCol(int col, boolean checkEmptyLines);
+
+	/**
+	 * Removes the cols.
+	 *
+	 * @param cols the cols
+	 */
+	public abstract void removeCols(List<Integer> cols);
+
+	/**
+	 * Removes the cols.
+	 *
+	 * @param coltodelete the coltodelete
+	 */
+	public abstract void removeCols(int[] coltodelete);
+
+	/**
+	 * Removes the row.
+	 *
+	 * @param row the row
+	 */
+	public abstract void removeRow(int row);
+
+	/**
+	 * Removes the rows.
+	 *
+	 * @param row the row
+	 */
+	public abstract void removeRows(List<Integer> row);
+
+	/**
+	 * Removes the rows.
+	 *
+	 * @param selectionIndices the selection indices
+	 */
+	public abstract void removeRows(int[] selectionIndices);
+
+	/**
+	 * Sets the.
+	 *
+	 * @param row the row
+	 * @param col the col
+	 * @param value the value
+	 */
+	public abstract void set(int row, int col, double value);
+
+	/**
+	 * Gets the fmin.
+	 *
+	 * @return the fmin
+	 */
+	public abstract int getFmin();
+	
+	/**
+	 * Gets the constructor fmin.
+	 *
+	 * @return the constructor fmin
+	 */
+	public abstract int getConstructorFmin();
+
+	/**
+	 * Gets the fmax.
+	 *
+	 * @return the fmax
+	 */
+	public abstract int getFmax();
+
+	/**
+	 * Removes the rows.
+	 *
+	 * @param i the i
+	 * @param j the j
+	 */
+	public abstract void removeRows(int i, int j);
+
+	/**
+	 * Cut.
+	 * TODO: must be done after calling copy(), check why.
+	 *
+	 * @param nlines the number of lines to keep
+	 */
+	public abstract void cut(int nlines);
+
+	/**
+	 * Filter.
+	 *
+	 * @param freqs the freqs
+	 * @param nlines the nlines
+	 * @param fmin the fmin
+	 */
+	public abstract void filter(int nlines, int fmin) throws Exception;
+
+	/**
+	 * Sets the order.
+	 *
+	 * @param neworder the neworder
+	 * @param reverse the reverse
+	 */
+	abstract public void setOrder(List<Integer> neworder, Boolean reverse);
+
+	/**
+	 * Gets the freqs.
+	 *
+	 * @return the freqs
+	 */
+	public abstract List<Integer> getFreqs();
+
+	/**
+	 * Export data.
+	 *
+	 * @param file the file
+	 * @param colseparator the colseparator
+	 * @param txtseparator the txtseparator
+	 */
+	public abstract void exportData(File file, String colseparator, String txtseparator);
+	public abstract void toTxt(File outfile, String encoding, String colseparator, String txtseparator);
+	
+	/**
+	 * Import data.
+	 *
+	 * @param file the file
+	 */
+	public abstract boolean importData(File file) throws RWorkspaceException, REXPMismatchException;
+
+	/**
+	 * Gets the corpus.
+	 *
+	 * @return the corpus
+	 */
+	public abstract Corpus getCorpus();
+
+	/**
+	 * Sets the corpus.
+	 *
+	 * @param corpus the new corpus
+	 */
+	public abstract void setCorpus(Corpus corpus);
+
+	public abstract void sortByFreqs(boolean reverse) throws Exception;
+
+	@Override
+	public abstract Vector getRowMarginsVector() throws StatException;
+	
+	@Override
+	public abstract Vector getColMarginsVector() throws StatException;
+	
+	@Override
+	public abstract int[] getRowMargins() throws Exception;
+	
+	@Override
+	public abstract int[] getColMargins() throws Exception;
+	
+	
+	/**
+	 * Gets the number of rows.
+	 * @return the number of rows
+	 */
+	public abstract int getRowsCount();
+
+	
+	/**
+	 * Gets the number of columns.
+	 * @return the number of columns
+	 */
+	public abstract int getColumnsCount();
+
+
+}

Property changes on: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/data/LexicalTable.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages_fr.properties
===================================================================
--- tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages_fr.properties	(revision 0)
+++ tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages_fr.properties	(revision 244)
@@ -0,0 +1,9 @@
+
+LexicalTableImpl_1  = Construction de la table lexicale avec : 
+LexicalTableImpl_10 = colonnes
+LexicalTableImpl_12 = Erreur: les marges
+LexicalTableImpl_13 = \ sont plus grandes que la taille des parties
+LexicalTableImpl_3  = \ <sans partition> /
+LexicalTableImpl_5  = pas assez de colonnes : minimum 2 (ici : 
+LexicalTableImpl_8  = ligne
+LexicalTableImpl_9  = n'a pas 

Property changes on: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages_fr.properties
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/LexicalTableCoreMessages.java
===================================================================
--- tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/LexicalTableCoreMessages.java	(revision 0)
+++ tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/LexicalTableCoreMessages.java	(revision 244)
@@ -0,0 +1,30 @@
+package org.txm.lexicaltable.core.messages;
+
+import org.eclipse.osgi.util.NLS;
+import org.txm.core.messages.TXMCoreMessages;
+
+public class LexicalTableCoreMessages extends NLS {
+	
+	private static final String BUNDLE_NAME = "org.txm.lexicaltable.core.messages.messages"; //$NON-NLS-1$
+	
+	public static String LexicalTableImpl_1;
+	public static String LexicalTableImpl_10;
+	public static String LexicalTableImpl_12;
+	public static String LexicalTableImpl_13;
+	public static String LexicalTableImpl_5;
+	public static String LexicalTableImpl_8;
+	public static String LexicalTableImpl_9;
+
+	
+	//FIXME: unused key
+	public static String LexicalTableImpl_3;
+	// end of fixme
+	
+	static {
+		// initialize resource bundle
+		TXMCoreMessages.initializeMessages(BUNDLE_NAME, LexicalTableCoreMessages.class);
+	}
+
+	private LexicalTableCoreMessages() {
+	}
+}

Property changes on: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/LexicalTableCoreMessages.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages.properties
===================================================================
--- tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages.properties	(revision 0)
+++ tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages.properties	(revision 244)
@@ -0,0 +1,9 @@
+
+LexicalTableImpl_1  = Building lexical table with: 
+LexicalTableImpl_10 = columns
+LexicalTableImpl_12 = Error: margin 
+LexicalTableImpl_13 = is higher than the partition size
+LexicalTableImpl_3  = \ <no partition> /
+LexicalTableImpl_5  = not enough columns: minimum 2 (here: 
+LexicalTableImpl_8  = line
+LexicalTableImpl_9  = does not have 

Property changes on: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages.properties
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages_ru.properties
===================================================================

Property changes on: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/messages/messages_ru.properties
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTableFactory.java
===================================================================
--- tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTableFactory.java	(revision 0)
+++ tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTableFactory.java	(revision 244)
@@ -0,0 +1,37 @@
+package org.txm.lexicaltable.core.functions;
+
+import org.txm.lexicaltable.core.statsengine.data.LexicalTable;
+import org.txm.lexicaltable.core.statsengine.r.data.LexicalTableImpl;
+import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
+import org.txm.searchengine.cqp.corpus.Partition;
+import org.txm.searchengine.cqp.corpus.Property;
+import org.txm.statsengine.core.StatException;
+
+public class LexicalTableFactory {
+	/**
+	 * Create a lexical table for this partition given an analysis property.
+	 * Lexical table are cached and recycled. In order to drop from memory a
+	 * lexical table, use {@link #dropLexicalTable(Property)}.
+	 *
+	 * @param analysisProperty the analysis property
+	 * @param Fmin the fmin
+	 * @return the lexical table
+	 * @throws StatException the stat exception
+	 * @throws CqiClientException the cqi client exception
+	 * @author sloiseau
+	 */
+	public static LexicalTable getLexicalTable(Partition partition, Property analysisProperty, int Fmin)
+	throws StatException, CqiClientException {
+		// System.out.println("CL : test si déja existant ds cache");
+		/*if (lexicalTables.containsKey(analysisProperty.getName())) {
+			if (lexicalTables.get(analysisProperty.getName()).getConstructorFmin() == Fmin)
+				return lexicalTables.get(analysisProperty.getName());
+		}*/
+		// System.out.println("CL : fait un new lexique");
+		LexicalTable t = LexicalTableImpl.getLexicalTable(partition, analysisProperty, Fmin);
+
+		// System.out.println("CL : put results ds le cache");
+		//partition.storeResult(t);
+		return t;
+	}
+}

Property changes on: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTableFactory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/functions/LexicalTableFactory.java
===================================================================
--- tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/functions/LexicalTableFactory.java	(revision 243)
+++ tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/functions/LexicalTableFactory.java	(revision 244)
@@ -1,37 +0,0 @@
-package org.txm.lexicaltable.functions;
-
-import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
-import org.txm.searchengine.cqp.corpus.Partition;
-import org.txm.searchengine.cqp.corpus.Property;
-import org.txm.stat.StatException;
-import org.txm.stat.data.LexicalTable;
-import org.txm.stat.engine.r.data.LexicalTableImpl;
-
-public class LexicalTableFactory {
-	/**
-	 * Create a lexical table for this partition given an analysis property.
-	 * Lexical table are cached and recycled. In order to drop from memory a
-	 * lexical table, use {@link #dropLexicalTable(Property)}.
-	 *
-	 * @param analysisProperty the analysis property
-	 * @param Fmin the fmin
-	 * @return the lexical table
-	 * @throws StatException the stat exception
-	 * @throws CqiClientException the cqi client exception
-	 * @author sloiseau
-	 */
-	public static LexicalTable getLexicalTable(Partition partition, Property analysisProperty, int Fmin)
-	throws StatException, CqiClientException {
-		// System.out.println("CL : test si déja existant ds cache");
-		/*if (lexicalTables.containsKey(analysisProperty.getName())) {
-			if (lexicalTables.get(analysisProperty.getName()).getConstructorFmin() == Fmin)
-				return lexicalTables.get(analysisProperty.getName());
-		}*/
-		// System.out.println("CL : fait un new lexique");
-		LexicalTable t = LexicalTableImpl.getLexicalTable(partition, analysisProperty, Fmin);
-
-		// System.out.println("CL : put results ds le cache");
-		//partition.storeResult(t);
-		return t;
-	}
-}
Index: tmp/org.txm.lexicaltable.core/META-INF/MANIFEST.MF
===================================================================
--- tmp/org.txm.lexicaltable.core/META-INF/MANIFEST.MF	(revision 243)
+++ tmp/org.txm.lexicaltable.core/META-INF/MANIFEST.MF	(revision 244)
@@ -3,14 +3,15 @@
 Bundle-Name: LexicalTable Core
 Bundle-SymbolicName: org.txm.lexicaltable.core;singleton:=true
 Bundle-Version: 1.0.0.qualifier
-Require-Bundle: org.txm.core;bundle-version="0.7.0",
+Require-Bundle: org.txm.statsengine.r.core;bundle-version="1.0.0",
+ org.txm.core;bundle-version="0.7.0",
  org.eclipse.core.runtime,
- org.txm.r;bundle-version="1.0.0",
  org.txm.index.core;bundle-version="1.0.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Export-Package: org.txm.functions.intertextualdistance,
+ org.txm.lexicaltable.core.functions,
+ org.txm.lexicaltable.core.messages,
  org.txm.lexicaltable.core.preferences,
- org.txm.lexicaltable.functions,
- org.txm.stat.data,
- org.txm.stat.engine.r.data
+ org.txm.lexicaltable.core.statsengine.data,
+ org.txm.lexicaltable.core.statsengine.r.data
