Révision 2583
tmp/org.txm.specificities.core/src/org/txm/specificities/core/statsengine/r/function/SpecificitiesR.java (revision 2583) | ||
---|---|---|
56 | 56 |
* |
57 | 57 |
*/ |
58 | 58 |
public class SpecificitiesR extends MatrixImpl implements ISpecificities { |
59 |
|
|
59 |
|
|
60 | 60 |
protected static int specif_counter = 1; |
61 |
|
|
61 | 62 |
/** The DEFAULT symbol. */ |
62 | 63 |
public static final String prefixR = "SpecifResult"; //$NON-NLS-1$ |
63 |
|
|
64 |
|
|
64 | 65 |
protected double[][] specIndex; |
65 |
|
|
66 |
|
|
66 | 67 |
/** |
67 | 68 |
* With an already computed specificities score matrix |
69 |
* |
|
68 | 70 |
* @param symbol |
69 | 71 |
* @throws RWorkspaceException |
70 | 72 |
*/ |
71 | 73 |
public SpecificitiesR(String symbol) throws RWorkspaceException { |
72 | 74 |
super(symbol); |
73 | 75 |
} |
74 |
|
|
76 |
|
|
75 | 77 |
/** |
76 | 78 |
* |
77 | 79 |
* @param lt |
78 | 80 |
* @throws StatException |
79 | 81 |
*/ |
80 | 82 |
public SpecificitiesR(ILexicalTable lt) throws StatException { |
81 |
super(prefixR+(specif_counter++));
|
|
82 |
|
|
83 |
//System.out.println("Av specif "); |
|
83 |
super(prefixR + (specif_counter++));
|
|
84 |
|
|
85 |
// System.out.println("Av specif ");
|
|
84 | 86 |
specIndex = compute(symbol, lt, null, null); |
85 | 87 |
} |
86 |
|
|
87 |
// /**
|
|
88 |
// * compute Specificites of subcorpus using the textometry package functions.
|
|
89 |
// *
|
|
90 |
// * @param lexicon the lexicon
|
|
91 |
// * @param subLexicon the sub lexicon
|
|
92 |
// * @return the double[][]
|
|
93 |
// * @throws StatException the stat exception
|
|
94 |
// * @throws REXPMismatchException
|
|
95 |
// * @throws RserveException
|
|
96 |
// */
|
|
97 |
// public SpecificitiesR(Vector lexicon, Vector subLexicon) throws StatException, RserveException, REXPMismatchException {
|
|
98 |
// super(prefixR+(specif_counter++));
|
|
99 |
// |
|
100 |
// RWorkspace rw = RWorkspace.getRWorkspaceInstance();
|
|
101 |
// rw.safeEval("library(textometry)"); //$NON-NLS-1$
|
|
102 |
// REXP r = rw.callFunction("specificities.lexicon.new", new QuantitativeDataStructure[] { lexicon, subLexicon }, symbol); //$NON-NLS-1$
|
|
103 |
// // double[] res = RWorkspace.toDouble(r);
|
|
104 |
// //System.out.println(" build double matrix");
|
|
105 |
// specIndex = r.asDoubleMatrix();
|
|
106 |
// }
|
|
107 |
|
|
88 |
|
|
89 |
// /**
|
|
90 |
// * compute Specificites of subcorpus using the textometry package functions.
|
|
91 |
// *
|
|
92 |
// * @param lexicon the lexicon
|
|
93 |
// * @param subLexicon the sub lexicon
|
|
94 |
// * @return the double[][]
|
|
95 |
// * @throws StatException the stat exception
|
|
96 |
// * @throws REXPMismatchException
|
|
97 |
// * @throws RserveException
|
|
98 |
// */
|
|
99 |
// public SpecificitiesR(Vector lexicon, Vector subLexicon) throws StatException, RserveException, REXPMismatchException {
|
|
100 |
// super(prefixR+(specif_counter++));
|
|
101 |
//
|
|
102 |
// RWorkspace rw = RWorkspace.getRWorkspaceInstance();
|
|
103 |
// rw.safeEval("library(textometry)"); //$NON-NLS-1$
|
|
104 |
// REXP r = rw.callFunction("specificities.lexicon.new", new QuantitativeDataStructure[] { lexicon, subLexicon }, symbol); //$NON-NLS-1$
|
|
105 |
// // double[] res = RWorkspace.toDouble(r);
|
|
106 |
// //System.out.println(" build double matrix");
|
|
107 |
// specIndex = r.asDoubleMatrix();
|
|
108 |
// }
|
|
109 |
|
|
108 | 110 |
/** |
109 | 111 |
* compute Specificites of lexical table using the textometry package functions. |
110 | 112 |
* |
... | ... | |
115 | 117 |
* @throws StatException the stat exception |
116 | 118 |
*/ |
117 | 119 |
protected static double[][] compute(String symbol, ILexicalTable table, String[] typeFocus, String[] partFocus) throws StatException { |
118 |
|
|
120 |
|
|
119 | 121 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
120 |
|
|
122 |
|
|
121 | 123 |
VectorImpl row = null; |
122 | 124 |
if (typeFocus != null && typeFocus.length != 0) |
123 | 125 |
row = new VectorImpl(typeFocus); |
124 |
|
|
126 |
|
|
125 | 127 |
VectorImpl column = null; |
126 | 128 |
if (partFocus != null && partFocus.length != 0) |
127 | 129 |
column = new VectorImpl(partFocus); |
128 |
|
|
130 |
|
|
129 | 131 |
try { |
130 | 132 |
rw.safeEval("library(textometry)"); //$NON-NLS-1$ |
131 |
} catch (Exception e1) { |
|
133 |
} |
|
134 |
catch (Exception e1) { |
|
132 | 135 |
// TODO Auto-generated catch block |
133 | 136 |
e1.printStackTrace(); |
134 | 137 |
} |
135 |
|
|
136 | 138 |
|
139 |
|
|
137 | 140 |
double[][] res; |
138 | 141 |
if (table.getNRows() > 1 && table.getNColumns() > 1) { |
139 | 142 |
REXP r = rw.callFunction("specificities", new QuantitativeDataStructure[] { table, row, column }, symbol); //$NON-NLS-1$ |
140 | 143 |
|
141 | 144 |
try { |
142 | 145 |
res = r.asDoubleMatrix(); |
143 |
} catch (Exception e) { |
|
146 |
} |
|
147 |
catch (Exception e) { |
|
144 | 148 |
throw new StatException(TXMCoreMessages.bind(SpecificitiesCoreMessages.failedToGetTheSpecificitesColon, e.getMessage()), e); |
145 | 149 |
} |
146 | 150 |
Log.finest(TXMCoreMessages.bind(SpecificitiesCoreMessages.specificityIndexComputed, (res.length * res[0].length))); |
147 |
} else { |
|
151 |
} |
|
152 |
else { |
|
148 | 153 |
res = new double[table.getNRows()][table.getNColumns()]; |
149 | 154 |
} |
150 | 155 |
return res; |
151 | 156 |
} |
152 |
|
|
157 |
|
|
153 | 158 |
public double[][] getScores() { |
154 | 159 |
return specIndex; |
155 | 160 |
} |
156 |
} |
|
161 |
} |
Formats disponibles : Unified diff