Revision 276

tmp/org.txm.statsengine.core/.project (revision 276)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.statsengine.core</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/data/QuantitativeDataStructure.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core.data;
29

  
30
import org.txm.core.results.ITXMResult;
31

  
32

  
33
// TODO: Auto-generated Javadoc
34
/**
35
 * The root of all other data structures.
36
 * 
37
 * @author sloiseau
38
 */
39
public interface QuantitativeDataStructure extends ITXMResult {
40

  
41
	/**
42
	 * The symbol is a the name of the data structure in a wrapped statistical
43
	 * engine.
44
	 * 
45
	 * @return the symbol of this data structure.
46
	 */
47
	public String getSymbol();
48

  
49
}
0 50

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/data/package.html (revision 276)
1
<html>
2
<body>
3
<p>Definition of quantitative data structures for representing corpus.</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/data/Vector.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core.data;
29

  
30
import java.util.List;
31

  
32
import org.txm.statsengine.core.StatException;
33

  
34
// TODO: Auto-generated Javadoc
35
/**
36
 * The interface Vector.
37
 * 
38
 * @author sloiseau
39
 */
40
public interface Vector extends QuantitativeDataStructure {
41

  
42
	/**
43
	 * Get the sub-vector given index.
44
	 * 
45
	 * @param index
46
	 *            0-based index.
47
	 * 
48
	 * @return a new vector, copy to the selected values (modif ication to the
49
	 *         vector returned does not modif y the vector).
50
	 * 
51
	 * @throws StatException
52
	 *             if anything goes wrong.
53
	 */
54
	public Vector get(int[] index) throws StatException;
55

  
56
	/**
57
	 * Convert the vector to a java array of <code>int</code>, if possible.
58
	 * 
59
	 * @return a java array of <code>int</code>.
60
	 * 
61
	 * @throws StatException
62
	 *             if anything goes wrong, ni particular if this Vector cannot
63
	 *             be converted into <code>int</code>.
64
	 */
65
	public int[] asIntArray() throws StatException;
66

  
67
	/**
68
	 * Convert the vector to a java array of <code>double</code>, if possible.
69
	 * 
70
	 * @return a java array of <code>double</code>.
71
	 * 
72
	 * @throws StatException
73
	 *             if anything goes wrong, ni particular if this Vector cannot
74
	 *             be converted into <code>double</code>.
75
	 */
76
	public double[] asDoubleArray() throws StatException;
77

  
78
	/**
79
	 * Convert the vector to a java array of <code>String</code>, if possible.
80
	 * 
81
	 * @return a java array of <code>String</code>.
82
	 * 
83
	 * @throws StatException
84
	 *             if anything goes wrong, ni particular if this Vector cannot
85
	 *             be converted into <code>String</code>.
86
	 */
87
	public String[] asStringsArray() throws StatException;
88

  
89
	/**
90
	 * Get the length of the vector.
91
	 * 
92
	 * @return the length.
93
	 * 
94
	 * @throws StatException
95
	 *             if anything goes wrong.
96
	 */
97
	public int getLength() throws StatException;
98

  
99
	/**
100
	 * Removes the.
101
	 *
102
	 * @param col the col
103
	 * @return true, if successful
104
	 */
105
	public boolean remove(int col);
106

  
107
	/**
108
	 * Sets the string.
109
	 *
110
	 * @param i the i
111
	 * @param value the value
112
	 */
113
	public void setString(int i, String value);
114

  
115
	/**
116
	 * Sets the int.
117
	 *
118
	 * @param i the i
119
	 * @param value the value
120
	 */
121
	public void setInt(int i, int value);
122

  
123
	/**
124
	 * Sets the double.
125
	 *
126
	 * @param i the i
127
	 * @param value the value
128
	 */
129
	public void setDouble(int i, double value);
130

  
131
	/**
132
	 * Sort.
133
	 *
134
	 * @param reverse the reverse
135
	 */
136
	public void sort(Boolean reverse);
137

  
138
	/**
139
	 * Sets the order.
140
	 *
141
	 * @param neworder the neworder
142
	 * @param reverse the reverse
143
	 */
144
	public void setOrder(List<Integer> neworder, Boolean reverse);
145

  
146
	/**
147
	 * Cut.
148
	 *
149
	 * @param nlines the nlines
150
	 */
151
	public void cut(int nlines);
152

  
153
	// public String get(int i);
154

  
155
}
0 156

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/data/Matrix.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core.data;
29

  
30
import org.txm.statsengine.core.StatException;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * The Interface Matrix, root of all other matrix-like structure.
35
 * 
36
 * @author sloiseau
37
 */
38
public interface Matrix extends QuantitativeDataStructure {
39

  
40
	/**
41
	 * Get the value at the specif ied cell.
42
	 *
43
	 * @param row 0-based row index
44
	 * @param col 0-based column index
45
	 * @return the value as a <code>double</code>
46
	 * @throws StatException the stat exception
47
	 */
48
	public double get(int row, int col) throws StatException;
49

  
50
	/**
51
	 * The number of rows in the contingency table.
52
	 * 
53
	 * @return the number of raw
54
	 */
55
	public abstract int getNRows();
56

  
57
	/**
58
	 * Exchange 2 columns in the lexical table
59
	 * @param c1 1..N+1
60
	 * @param c2 1..N+1
61
	 */
62
	public abstract void exchangeColumns(int c1, int c2);
63
	
64
	/**
65
	 * The number of columns in the contingency table.
66
	 * 
67
	 * @return the number of columns
68
	 */
69
	public abstract int getNColumns();
70

  
71
	/**
72
	 * Get the row names or null if no row names.
73
	 * 
74
	 * Row names are available if the
75
	 *
76
	 * @return the row names
77
	 * {@link #Matrix(DoubleMatrix2D, String[], String[], Header)} constructor
78
	 * has been used for this object.
79
	 */
80
	public abstract Vector getRowNames();
81

  
82
	/**
83
	 * Get the col names or null if no col names.
84
	 * 
85
	 * Col names are available if the
86
	 *
87
	 * @return the col names
88
	 * {@link #Matrix(DoubleMatrix2D, String[], String[], Header)} constructor
89
	 * has been used for this object.
90
	 */
91
	public abstract Vector getColNames();
92

  
93
	/**
94
	 * Gets a row vector as a Vector object.
95
	 *
96
	 * @param index 0-based row index.
97
	 * @return the row
98
	 * @throws StatException the stat exception
99
	 */
100
	public abstract Vector getRow(int index) throws StatException;
101

  
102
	/**
103
	 * Gets a column vector as a Vector object.
104
	 *
105
	 * @param index 0-based index column index.
106
	 * @return the row
107
	 * @throws StatException the stat exception
108
	 */
109
	public abstract Vector getCol(int index) throws StatException;
110

  
111
	/**
112
	 * Gets a column vector as a Vector object.
113
	 *
114
	 * @param column the column name
115
	 * @return the column vector
116
	 * @throws StatException the stat exception
117
	 */
118
	public abstract Vector getCol(String column) throws StatException;
119

  
120
	/**
121
	 * Gets a row vector as a Vector object.
122
	 *
123
	 * @param row the row name
124
	 * @return the row vector
125
	 * @throws StatException the stat exception
126
	 */
127
	public abstract Vector getRow(String row) throws StatException;
128

  
129
}
0 130

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/data/ContingencyTable.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core.data;
29

  
30
import org.txm.statsengine.core.StatException;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * The Interface ContingencyTable.
35
 * 
36
 * @author sloiseau
37
 */
38
public interface ContingencyTable extends Matrix {
39

  
40
	/**
41
	 * Gets the row margin.
42
	 * 
43
	 * @return the row margin
44
	 * 
45
	 * @throws RWorkspaceException
46
	 *             the r workspace exception
47
	 */
48
	public Vector getRowMarginsVector() throws StatException;
49

  
50
	/**
51
	 * Gets the col margin.
52
	 * 
53
	 * @return the col margin
54
	 * 
55
	 * @throws RWorkspaceException
56
	 *             the r workspace exception
57
	 */
58
	public Vector getColMarginsVector() throws StatException;
59
	
60
	/**
61
	 * Gets the col margin.
62
	 * 
63
	 * @return the col margin
64
	 * 
65
	 * @throws RWorkspaceException
66
	 *             the r workspace exception
67
	 */
68
	public int[] getColMargins() throws Exception;
69
	
70
	/**
71
	 * Gets the col margin.
72
	 * 
73
	 * @return the col margin
74
	 * 
75
	 * @throws RWorkspaceException
76
	 *             the r workspace exception
77
	 */
78
	public int[] getRowMargins() throws Exception;
79

  
80
	/**
81
	 * Gets the total.
82
	 * 
83
	 * @return the total
84
	 * 
85
	 * @throws RWorkspaceException
86
	 *             the r workspace exception
87
	 */
88
	public int getTotal() throws StatException;
89

  
90
}
0 91

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/StatException.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core;
29

  
30
// TODO: Auto-generated Javadoc
31
/**
32
 * General exception in statistical computing, the super class of all exceptions
33
 * related to statistical computing.
34
 * 
35
 * @author sloiseau
36
 * 
37
 */
38
public class StatException extends Exception {
39
	
40
	/** The Constant serialVersionUID. */
41
	private static final long serialVersionUID = 7220819361950262761L;
42

  
43
	/**
44
	 * Instantiates a new stat exception.
45
	 */
46
	public StatException() {
47
		super();
48
		// TODO Auto-generated constructor stub
49
	}
50

  
51
	/**
52
	 * Instantiates a new stat exception.
53
	 *
54
	 * @param message the message
55
	 * @param cause the cause
56
	 */
57
	public StatException(String message, Throwable cause) {
58
		super(message, cause);
59
		// TODO Auto-generated constructor stub
60
	}
61

  
62
	/**
63
	 * Instantiates a new stat exception.
64
	 *
65
	 * @param message the message
66
	 */
67
	public StatException(String message) {
68
		super(message);
69
		// TODO Auto-generated constructor stub
70
	}
71

  
72
	/**
73
	 * Instantiates a new stat exception.
74
	 *
75
	 * @param cause the cause
76
	 */
77
	public StatException(Throwable cause) {
78
		super(cause);
79
		// TODO Auto-generated constructor stub
80
	}
81

  
82
}
0 83

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/package.html (revision 276)
1
<html>
2
<body>
3
<p>Root package of all statistical and numeric computing functions of the toolbox.</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/utils/ArrayIndex.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core.utils;
29

  
30
import java.util.HashMap;
31
import java.util.Map;
32

  
33
import org.txm.statsengine.core.messages.StatsEngineCoreMessages;
34

  
35
// TODO: Auto-generated Javadoc
36
/**
37
 * Utilities for managing index of vector.
38
 * 
39
 * @author sloiseau
40
 * 
41
 */
42
public final class ArrayIndex {
43

  
44
	/**
45
	 * Convert an array of zero-based index to an array of one-base index, that
46
	 * is, add <code>1</code> to all elements.
47
	 * 
48
	 * This method check every index (see exception thrown).
49
	 *
50
	 * @param zero_based the zero based index.
51
	 * @param length the number of elements that can be indexed.
52
	 * @return the one base index.
53
	 */
54
	public static final int[] zeroToOneBasedIndex(int[] zero_based, int length) {
55
		if (zero_based == null || zero_based.length == 0) {
56
			throw new IllegalArgumentException(StatsEngineCoreMessages.ArrayIndex_0);
57
		}
58
		int[] one_based = new int[zero_based.length];
59
		for (int i = 0; i < zero_based.length; i++) {
60
			if (zero_based[i] < 0 || zero_based[i] >= length) {
61
				throw new IllegalArgumentException(StatsEngineCoreMessages.ArrayIndex_1);
62
			}
63
			one_based[i] = zero_based[i] + 1;
64
		}
65
		return one_based;
66
	}
67

  
68
	/**
69
	 * Zero to one based index.
70
	 *
71
	 * @param zero_based the zero_based
72
	 * @return the int
73
	 */
74
	public static final int zeroToOneBasedIndex(int zero_based) {
75
		return zero_based + 1;
76
	}
77

  
78
	/**
79
	 * Get the index (0-based) of the element of subvector into vector. Return
80
	 * <code>-1</code> when no element in vector correspond to the element in
81
	 * subvector.
82
	 *
83
	 * @param vector the vector
84
	 * @param subvector the subvector
85
	 * @return the index
86
	 */
87
	public static int[] getIndex(String[] vector, String[] subvector) {
88
		int[] result = new int[subvector.length];
89
		Map<String, Integer> index = new HashMap<String, Integer>();
90
		for (int i = 0; i < subvector.length; i++) {
91
			index.put(subvector[i], i);
92
			result[i] = -1;
93
		}
94
		for (int i = 0; i < vector.length; i++) {
95
			if (index.containsKey(vector[i])) {
96
				result[index.get(vector[i])] = i;
97
			}
98
		}
99
		return result;
100
	}
101
}
0 102

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/utils/ArrayEquals.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core.utils;
29

  
30
import java.util.Arrays;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * Utility methods for testing for equality of arrays.
35
 * 
36
 * @author sloiseau
37
 * 
38
 */
39
public final class ArrayEquals {
40

  
41
	/**
42
	 * Test for equality of both array. For consistency with Arrays.equals
43
	 * contract, the two arrays are equals if both are <code>null</code>.
44
	 *
45
	 * @param array1 the array1
46
	 * @param array2 the array2
47
	 * @return <code>true</code> if (1) both arrays are <code>null</code> or if
48
	 * (2) both arrays have the same length and contain pair of arrays
49
	 * equals to each other according to
50
	 * {@link Arrays#equals(int[], int[])}.
51
	 */
52
	public static final boolean deepEquals(int[][] array1, int[][] array2) {
53
		if (array1 == null && array2 == null)
54
			return true;
55
		if (array1 == null || array2 == null)
56
			return false;
57
		if (array1.length != array2.length)
58
			return false;
59
		for (int i = 0; i < array2.length; i++) {
60
			if (!Arrays.equals(array1[i], array2[i]))
61
				return false;
62
		}
63
		return true;
64
	}
65

  
66
}
0 67

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/utils/VectorizeArray.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core.utils;
29

  
30
import org.txm.statsengine.core.messages.StatsEngineCoreMessages;
31

  
32

  
33
// TODO: Auto-generated Javadoc
34
/**
35
 * Static methods for dealing vectorization of Arrays.
36
 * 
37
 * @author sloiseau
38
 * 
39
 */
40
public final class VectorizeArray {
41

  
42
	/**
43
	 * Convert a <code>double * double</code> array in a <code>double</code>
44
	 * array. Each inner array of the argument is added one after the other into
45
	 * the result array.
46
	 * 
47
	 * <pre>
48
	 * [
49
	 * [1, 2, 3],
50
	 * [4, 5, 6]
51
	 * ]
52
	 * </pre>
53
	 * 
54
	 * result in :
55
	 * 
56
	 * <pre>
57
	 * [1, 2, 3, 4, 5, 6]
58
	 * </pre>
59
	 * 
60
	 * that is, "row first".
61
	 *
62
	 * @param matrix a <code>double * double</code> array where all inner arrays
63
	 * have the same length.
64
	 * @return an array of <code>double</code> produced by vectorization of the
65
	 * matrix.
66
	 */
67
	public final static double[] vectorizeByInner(double[][] matrix) {
68
		if (matrix == null || matrix.length == 0) {
69
			throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_0);
70
		}
71
		int inner_length = matrix[0].length;
72
		if (inner_length < 1) {
73
			throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_1);
74
		}
75
		double[] vector = new double[matrix.length * matrix[0].length];
76
		for (int i = 0; i < matrix.length; i++) {
77
			if (matrix[i] == null) {
78
				throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_10);
79
			}
80
			if (inner_length != matrix[i].length) {
81
				throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_3);
82
			}
83
			System.arraycopy(matrix[i], 0, vector, i * inner_length,
84
					inner_length);
85
		}
86
		return vector;
87
	}
88

  
89
	/**
90
	 * Convert a <code>int * int</code> array in a <code>double</code> array.
91
	 * Each inner array of the argument is added one after the other into the
92
	 * result array.
93
	 * 
94
	 * <pre>
95
	 * [
96
	 * [1, 2, 3],
97
	 * [4, 5, 6]
98
	 * ]
99
	 * </pre>
100
	 * 
101
	 * result in :
102
	 * 
103
	 * <pre>
104
	 * [1, 2, 3, 4, 5, 6]
105
	 * </pre>
106
	 * 
107
	 * that is, "row first".
108
	 *
109
	 * @param matrix a <code>int * int</code> array where all inner arrays have the
110
	 * same length.
111
	 * @return an array of <code>int</code> produced by vectorization of the
112
	 * matrix.
113
	 */
114
	public final static int[] vectorizeByInner(int[][] matrix) {
115
		if (matrix == null || matrix.length == 0) {
116
			throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_4);
117
		}
118
		int inner_length = matrix[0].length;
119
		if (inner_length < 1) {
120
			throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_5);
121
		}
122
		int[] vector = new int[matrix.length * matrix[0].length];
123
		for (int i = 0; i < matrix.length; i++) {
124
			if (matrix[i] == null) {
125
				throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_10);
126
			}
127
			if (inner_length != matrix[i].length) {
128
				throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_7);
129
			}
130
			System.arraycopy(matrix[i], 0, vector, i * inner_length,
131
					inner_length);
132
		}
133
		return vector;
134
	}
135

  
136
	/**
137
	 * Convert a <code>double * double</code> array in a <code>double</code>
138
	 * array. The elements of the input array are assembled in the output array
139
	 * so that elements of same index in the outer array are consecutive. So :
140
	 * 
141
	 * <pre>
142
	 * [
143
	 * [1, 2, 3],
144
	 * [4, 5, 6]
145
	 * ]
146
	 * </pre>
147
	 * 
148
	 * result in :
149
	 * 
150
	 * <pre>
151
	 * [1, 4, 2, 5, 3, 6]
152
	 * </pre>
153
	 * 
154
	 * that is, "column first".
155
	 *
156
	 * @param matrix a <code>double * double</code> array where all inner arrays
157
	 * have the same length.
158
	 * @return an array of <code>double</code> produced by vectorization of the
159
	 * matrix.
160
	 */
161
	public final static double[] vectorizeByOuter(double[][] matrix) {
162
		if (matrix == null || matrix.length == 0) {
163
			throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_8);
164
		}
165
		int inner_length = matrix[0].length;
166
		int outer_length = matrix.length;
167
		if (inner_length < 1) {
168
			throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_9);
169
		}
170
		double[] vector = new double[matrix.length * matrix[0].length];
171
		for (int i = 0; i < matrix.length; i++) {
172
			if (matrix[i] == null) {
173
				throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_10);
174
			}
175
			if (inner_length != matrix[i].length) {
176
				throw new IllegalArgumentException(StatsEngineCoreMessages.VectorizeArray_11);
177
			}
178
			for (int j = 0; j < matrix[i].length; j++) {
179
				vector[(j * outer_length) + i] = matrix[i][j];
180
			}
181

  
182
		}
183
		return vector;
184
	}
185

  
186
}
0 187

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/utils/PrintArray.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core.utils;
29

  
30
import java.util.Arrays;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * Various utilities method for printing arrays.
35
 * 
36
 * @author sloiseau
37
 * 
38
 */
39
public final class PrintArray {
40

  
41
	/**
42
	 * Double array.
43
	 *
44
	 * @param matrix the matrix
45
	 * @return the string
46
	 */
47
	public final static String doubleArray(double[][] matrix) {
48
		// DoubleMatrix2D m = new SparseDoubleMatrix2D(matrix);
49
		// return m.toString();
50
		StringBuffer sb = new StringBuffer();
51
		for (int i = 0; i < matrix.length; i++) {
52
			sb.append(Arrays.toString(matrix[i]));
53
		}
54
		return sb.toString();
55
	}
56

  
57
	/**
58
	 * Int array.
59
	 *
60
	 * @param matrix the matrix
61
	 * @return the string
62
	 */
63
	public final static String intArray(int[][] matrix) {
64
		double[][] doublematrix = new double[matrix.length][matrix[0].length];
65
		for (int i = 0; i < matrix.length; i++) {
66
			for (int j = 0; j < doublematrix[i].length; j++) {
67
				doublematrix[i][j] = matrix[i][j];
68
			}
69
		}
70
		return doubleArray(doublematrix);
71
	}
72

  
73
}
0 74

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/utils/CheckArray.java (revision 276)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.core.utils;
29

  
30
// TODO: Auto-generated Javadoc
31
/**
32
 * Various utility methods for checking consistency of matrix as java array of
33
 * arrays.
34
 * 
35
 * @author sloiseau
36
 * 
37
 */
38
public final class CheckArray {
39

  
40
	/**
41
	 * Check if an array is not null (or 0-length), does not include null inner
42
	 * array (or 0 length), and if all inner arrays have the same length.
43
	 *
44
	 * @param array the array
45
	 * @return <code>true</code> if the condition are satisfied,
46
	 * <code>false</code> otherwise.
47
	 */
48
	public final static boolean checkMatrixRepresentation(int[][] array) {
49
		// same code as in #checkMatrixRepresentation(double[][])
50
		if (array == null)
51
			return false;
52
		int length = array.length;
53
		if (length < 1)
54
			return false;
55
		if (array[0] == null)
56
			return false;
57
		int firstElementLength = array[0].length;
58
		if (firstElementLength == 0)
59
			return false;
60
		for (int i = 0; i < array.length; i++) {
61
			if (array[i] == null)
62
				return false;
63
			if (array[i].length != firstElementLength)
64
				return false;
65
		}
66
		return true;
67
	}
68

  
69
	/**
70
	 * Check if an array is not null (or 0-length), does not include null inner
71
	 * array (or 0 length), and if all inner arrays have the same length.
72
	 *
73
	 * @param array the array
74
	 * @return <code>true</code> if the condition are satisfied,
75
	 * <code>false</code> otherwise.
76
	 */
77
	public final static boolean checkMatrixRepresentation(double[][] array) {
78
		// same code as in #checkMatrixRepresentation(int[][])
79
		if (array == null)
80
			return false;
81
		int length = array.length;
82
		if (length < 1)
83
			return false;
84
		if (array[0] == null)
85
			return false;
86
		int firstElementLength = array[0].length;
87
		if (firstElementLength == 0)
88
			return false;
89
		for (int i = 0; i < array.length; i++) {
90
			if (array[i] == null)
91
				return false;
92
			if (array[i].length != firstElementLength)
93
				return false;
94
		}
95
		return true;
96
	}
97

  
98
}
0 99

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/utils/package.html (revision 276)
1
<html>
2
<body>
3
<p>Utility functions for dealing with array (vectorizing, indexing, checking consistency...).</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/messages/messages.properties (revision 276)
1

  
2

  
3
VectorizeArray_0  = ** Nothing to do with an empty matrix
4
VectorizeArray_1  = ** Inner arrays must be of dimension > 0.
5
VectorizeArray_10 = ** An inner array cannot be null.
6
VectorizeArray_11 = ** All the inner array do not have the same length.
7
VectorizeArray_3  = ** All the inner array do not have the same length.
8
VectorizeArray_4  = ** Nothing to do with an empty matrix
9
VectorizeArray_5  = ** Inner arrays must be of dimension > 0.
10
VectorizeArray_7  = ** All the inner array do not have the same length.
11
VectorizeArray_8  = ** Nothing to do with an empty matrix
12
VectorizeArray_9  = ** Inner arrays must be of dimension > 0.
13

  
14
ArrayIndex_0 = ** The index array can not be null or empty.
15
ArrayIndex_1 = ** A zero-based index cannot be < 0 or > to the number of indexed elements.
16

  
17
Factor_0 = ** Not implemented
18

  
19

  
20
MatrixImpl_0  = A variable ("
21
MatrixImpl_1  = ") does not exist in the R workspace.
22
MatrixImpl_10 = Row index (
23
MatrixImpl_11 = ) too big (max 
24
MatrixImpl_13 = Col index (
25
MatrixImpl_14 = ) too big (max 
26
MatrixImpl_19 = R object evaluated to null.
27
MatrixImpl_2  = dim(
28
MatrixImpl_20 = Unknown type: 
29
MatrixImpl_21 = mode
30
MatrixImpl_22 = Row index (
31
MatrixImpl_23 = ) too big (max 
32
MatrixImpl_28 = Column index (
33
MatrixImpl_29 = ) too big (max 
34
MatrixImpl_4  = Row names of a contingency table cannot be null.
35
MatrixImpl_5  = Row names vector length must be equal to the number of rows of the matrix.
36
MatrixImpl_6  = Column names of a contingency table cannot be null
37
MatrixImpl_67 = Matrix: failed to get nrow: 
38
MatrixImpl_7  = Col names vector length must be equals to the number of columns of the matrix (
39
MatrixImpl_73 = MatrixImpl: Error: column size differs: original
40
MatrixImpl_79 = Failed to get row names
41
MatrixImpl_88 = Cannot delete all lines
42

  
43
QuantitativeDataStructureImpl_0 = No object with name "
44
QuantitativeDataStructureImpl_1 = " in the workspace
45
QuantitativeDataStructureImpl_2 = ** Cannot delete a non-existing object.
46

  
47

  
0 48

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/messages/StatsEngineCoreMessages.java (revision 276)
1
package org.txm.statsengine.core.messages;
2

  
3
import org.txm.utils.messages.Utf8NLS;
4

  
5
public class StatsEngineCoreMessages extends Utf8NLS {
6

  
7
	private static final String BUNDLE_NAME = "org.txm.statsengine.core.messages.messages"; //$NON-NLS-1$
8

  
9
	
10
	public static String VectorizeArray_0;
11
	public static String VectorizeArray_1;
12
	public static String VectorizeArray_10;
13
	public static String VectorizeArray_11;
14
	public static String VectorizeArray_3;
15
	public static String VectorizeArray_4;
16
	public static String VectorizeArray_5;
17
	public static String VectorizeArray_7;
18
	public static String VectorizeArray_8;
19
	public static String VectorizeArray_9;
20

  
21
	public static String ArrayIndex_0;
22
	public static String ArrayIndex_1;
23
	public static String Factor_0;
24
	public static String MatrixImpl_0;
25
	public static String MatrixImpl_1;
26
	public static String MatrixImpl_10;
27
	public static String MatrixImpl_11;
28
	public static String MatrixImpl_13;
29
	public static String MatrixImpl_14;
30
	public static String MatrixImpl_19;
31
	public static String MatrixImpl_2;
32
	public static String MatrixImpl_20;
33
	public static String MatrixImpl_21;
34
	public static String MatrixImpl_22;
35
	public static String MatrixImpl_23;
36
	public static String MatrixImpl_28;
37
	public static String MatrixImpl_29;
38
	public static String MatrixImpl_4;
39
	public static String MatrixImpl_5;
40
	public static String MatrixImpl_6;
41
	public static String MatrixImpl_67;
42
	public static String MatrixImpl_7;
43
	public static String MatrixImpl_73;
44
	public static String MatrixImpl_79;
45
	public static String MatrixImpl_88;
46

  
47
	public static String QuantitativeDataStructureImpl_0;
48
	public static String QuantitativeDataStructureImpl_1;
49
	public static String QuantitativeDataStructureImpl_2;
50

  
51
	
52
	static {
53
		// initialize resource bundle
54
		Utf8NLS.initializeMessages(BUNDLE_NAME, StatsEngineCoreMessages.class);
55
	}
56

  
57
	private StatsEngineCoreMessages() {
58
	}
59
}
0 60

  
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/messages/messages_fr.properties (revision 276)
1

  
2
VectorizeArray_0  = ** Rien à faire avec une matrice vide
3
VectorizeArray_1  = ** Les tableaux internes doivent avoir une dimension supérieure à 0
4
VectorizeArray_10 = ** Un tableau interne ne peut pas être nul
5
VectorizeArray_11 = ** Les tableaux internes n'ont pas tous la même dimension.
6
VectorizeArray_3  = ** Les tableaux internes n'ont pas tous la même dimension.
7
VectorizeArray_4  = ** Rien à faire avec une matrice vide
8
VectorizeArray_5  = ** Les tableaux internes doivent avoir une dimension supérieure à 0
9
VectorizeArray_7  = * Les tableaux internes n'ont pas tous la même dimension.
10
VectorizeArray_8  = ** Rien à faire avec une matrice vide
11
VectorizeArray_9  = ** Les tableaux internes doivent avoir une dimension supérieure à 0
12

  
13
ArrayIndex_0 = ** Le tableau d'index ne peut pas être nul ou vide.
14
ArrayIndex_1 = ** Un index commençant à 0 ne peut pas être inférieur à 0 ou supérieur au nombre d'éléments indexés.
15

  
16
Factor_0 = ** Non implémenté
17

  
18

  
19
MatrixImpl_0  = Une variable ("
20
MatrixImpl_1  = ") n'existe pas dans l'espace de travail R.
21
MatrixImpl_10 = Index de ligne (
22
MatrixImpl_11 = ) trop grand (max 
23
MatrixImpl_13 = Index de colonne (
24
MatrixImpl_14 = ) trop grand (max 
25
MatrixImpl_19 = L'objet R a une valeur nulle.
26
MatrixImpl_2  = dim(
27
MatrixImpl_20 = Type inconnu : 
28
MatrixImpl_21 = mode
29
MatrixImpl_22 = Index de ligne (
30
MatrixImpl_23 = ) trop grand (max 
31
MatrixImpl_28 = Index de colonne (
32
MatrixImpl_29 = ) trop grand (max 
33
MatrixImpl_4  = Les noms de lignes d'une matrice de contingence ne peuvent pas être nuls.
34
MatrixImpl_5  = La dimension du vecteur des noms de lignes doit être égale au nombre de lignes de la matrice.
35
MatrixImpl_6  = Les noms de colonnes d'une matrice de contingence ne peuvent pas être nuls.
36
MatrixImpl_67 = Matrice: impossible d'obtenir le nombre de lignes: 
37
MatrixImpl_7  = La dimension du vecteur des noms de colonnes doit être égale au nombre de colonnes de la matrice (
38
MatrixImpl_73 = MatrixImpl: Erreur: la taille des colonnes diffère de l'originale
39
MatrixImpl_79 = Impossible d'obtenir les noms de lignes
40
MatrixImpl_88 = Impossible de supprimer toutes les lignes
41

  
42
QuantitativeDataStructureImpl_0 = Aucun objet de nom "
43
QuantitativeDataStructureImpl_1 = " dans l'espace de travail
44
QuantitativeDataStructureImpl_2 = ** Impossible de supprimer un objet qui n'existe pas.
45

  
0 46

  
tmp/org.txm.statsengine.core/build.properties (revision 276)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .
0 5

  
tmp/org.txm.statsengine.core/.settings/org.eclipse.jdt.core.prefs (revision 276)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4
org.eclipse.jdt.core.compiler.compliance=1.6
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.6
0 8

  
tmp/org.txm.statsengine.core/.classpath (revision 276)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
0 8

  
tmp/org.txm.statsengine.core/META-INF/MANIFEST.MF (revision 276)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Statistics Engine Core
4
Bundle-SymbolicName: org.txm.statsengine.core
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
7
Export-Package: org.txm.statsengine.core,
8
 org.txm.statsengine.core.data,
9
 org.txm.statsengine.core.messages,
10
 org.txm.statsengine.core.utils
11
Require-Bundle: org.txm.core;bundle-version="0.7.0",
12
 org.txm.utils;bundle-version="1.0.0"
13
Bundle-Vendor: Textometrie.org
0 14

  

Also available in: Unified diff