Révision 534
| tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/r/data/LexicalTableImpl.java (revision 534) | ||
|---|---|---|
| 41 | 41 |
|
| 42 | 42 |
|
| 43 | 43 |
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
import org.rosuda.REngine.REXPMismatchException; |
|
| 44 | 48 |
//import org.txm.functions.queryindex.*; |
| 45 | 49 |
import org.txm.index.core.functions.Index; |
| 46 | 50 |
import org.txm.index.core.functions.Line; |
| ... | ... | |
| 58 | 62 |
import org.txm.statsengine.r.core.exceptions.RException; |
| 59 | 63 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
| 60 | 64 |
|
| 65 |
import cern.colt.Arrays; |
|
| 61 | 66 |
import cern.colt.matrix.DoubleFactory2D; |
| 62 | 67 |
import cern.colt.matrix.DoubleMatrix2D; |
| 68 |
|
|
| 63 | 69 |
import org.txm.lexicaltable.core.statsengine.data.ILexicalTable; |
| 64 | 70 |
|
| 65 | 71 |
|
| ... | ... | |
| 145 | 151 |
Vector corpusLexiconV = corpusLexicon.asVector(); |
| 146 | 152 |
Vector subcorpusLexiconV = subcorpusLexicon.asVector(); |
| 147 | 153 |
|
| 148 |
rw.callFunction("lexicons2LexicalTable", new QuantitativeDataStructure[] { corpusLexiconV, subcorpusLexiconV }, symbol); //$NON-NLS-1$
|
|
| 154 |
//TODO: implement the R function : rw.callFunction("lexicons2LexicalTable", new QuantitativeDataStructure[] { corpusLexiconV, subcorpusLexiconV }, symbol); //$NON-NLS-1$
|
|
| 155 |
|
|
| 156 |
rw.eval(symbol+" <- matrix(0, ncol = 2, nrow=length("+corpusLexiconV.getSymbol()+"))");
|
|
| 157 |
rw.eval("colnames("+symbol+") <- c(\""+corpusLexicon.getCorpus().getName()+"-"+subcorpusLexicon.getCorpus().getName()+"\", \""+subcorpusLexicon.getCorpus().getName()+"\")");
|
|
| 158 |
System.out.println("forms: "+Arrays.toString(corpusLexicon.getForms()));
|
|
| 159 |
rw.addVectorToWorkspace("ltnames", corpusLexicon.getForms());
|
|
| 160 |
rw.eval("rownames("+symbol+") <- ltnames");
|
|
| 161 |
rw.eval(symbol+"[names("+corpusLexiconV.getSymbol()+"),1] <- "+corpusLexiconV.getSymbol());
|
|
| 162 |
rw.eval(symbol+"[names("+subcorpusLexiconV.getSymbol()+"),1] <- "+symbol+"[names("+subcorpusLexiconV.getSymbol()+"),1] - "+subcorpusLexiconV.getSymbol());
|
|
| 163 |
rw.eval(symbol+"[names("+subcorpusLexiconV.getSymbol()+"),2] <- "+subcorpusLexiconV.getSymbol());
|
|
| 164 |
try {
|
|
| 165 |
System.out.println("colnames: "+Arrays.toString(rw.eval("colnames("+symbol+")").asStrings()));
|
|
| 166 |
System.out.println("ltnames: "+Arrays.toString(rw.eval("ltnames").asStrings()));
|
|
| 167 |
System.out.println("length ltnames: "+rw.eval("length(ltnames)").asInteger());
|
|
| 168 |
System.out.println("ncol: "+rw.eval("ncol("+symbol+")").asInteger());
|
|
| 169 |
System.out.println("nrow: "+rw.eval("nrow("+symbol+")").asInteger());
|
|
| 170 |
} catch (REXPMismatchException e) {
|
|
| 171 |
// TODO Auto-generated catch block |
|
| 172 |
e.printStackTrace(); |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
|
|
| 149 | 176 |
} |
| 150 | 177 |
|
| 151 | 178 |
/** |
| ... | ... | |
| 316 | 343 |
DoubleMatrix2D mat = DoubleFactory2D.sparse.make(idx.size(), colnames.length, 0); |
| 317 | 344 |
|
| 318 | 345 |
int countline = 0; |
| 319 |
for (int j : idx) |
|
| 320 |
{
|
|
| 321 |
for (int i = 0; i < colnames.length; i++) |
|
| 322 |
{
|
|
| 346 |
for (int j : idx) {
|
|
| 347 |
for (int i = 0; i < colnames.length; i++) {
|
|
| 323 | 348 |
mat.setQuick(countline, i, freqs[j][i]); |
| 324 | 349 |
} |
| 325 | 350 |
countline++; |
| 326 | 351 |
} |
| 327 | 352 |
|
| 328 | 353 |
String[] filteredrownames = new String[idx.size()]; |
| 329 |
for(int i = 0 ; i < idx.size() ; i++) |
|
| 354 |
for (int i = 0 ; i < idx.size() ; i++)
|
|
| 330 | 355 |
filteredrownames[i] = rownames[idx.get(i)]; |
| 331 | 356 |
|
| 332 | 357 |
LexicalTableImpl table = new LexicalTableImpl(mat, filteredrownames, colnames); |
| tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTable.java (revision 534) | ||
|---|---|---|
| 6 | 6 |
import java.util.Collection; |
| 7 | 7 |
import java.util.HashMap; |
| 8 | 8 |
import java.util.List; |
| 9 |
import java.util.Map; |
|
| 9 | 10 |
|
| 10 | 11 |
import org.txm.core.results.TXMParameters; |
| 11 | 12 |
import org.txm.core.results.TXMResult; |
| 12 | 13 |
import org.txm.index.core.functions.Index; |
| 13 | 14 |
import org.txm.index.core.functions.Line; |
| 14 | 15 |
import org.txm.lexicaltable.core.messages.LexicalTableCoreMessages; |
| 16 |
import org.txm.lexicaltable.core.preferences.LexicalTablePreferences; |
|
| 15 | 17 |
import org.txm.lexicaltable.core.statsengine.data.ILexicalTable; |
| 16 | 18 |
import org.txm.lexicaltable.core.statsengine.r.data.LexicalTableImpl; |
| 17 | 19 |
import org.txm.lexicon.core.corpusengine.cqp.Lexicon; |
| ... | ... | |
| 24 | 26 |
import org.txm.statsengine.core.data.Vector; |
| 25 | 27 |
import org.txm.statsengine.r.core.RWorkspace; |
| 26 | 28 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
| 29 |
import org.txm.utils.logger.Log; |
|
| 27 | 30 |
|
| 28 | 31 |
/** |
| 29 | 32 |
* ILexicalTable logic + TXMResult management methods |
| ... | ... | |
| 32 | 35 |
* |
| 33 | 36 |
*/ |
| 34 | 37 |
public class LexicalTable extends TXMResult {
|
| 35 |
|
|
| 36 |
/** The constructor_fmin. */ |
|
| 37 |
private int pFminFilter; |
|
| 38 |
|
|
| 39 |
/** The constructor_vmax. */ |
|
| 40 |
private int pVMaxFilter; |
|
| 41 |
|
|
| 42 |
/** The corpus. */ |
|
| 43 |
private Corpus corpus; |
|
| 44 | 38 |
|
| 39 |
public static Integer LEXICALTABLE_COUNTER = new Integer(1); |
|
| 40 |
public static String SYMBOL_BASE = "LexicalTable_"; |
|
| 41 |
|
|
| 45 | 42 |
/** the statengine data object */ |
| 46 | 43 |
ILexicalTable data; |
| 47 | 44 |
|
| 48 |
/** The partition. */
|
|
| 49 |
private Partition partition;
|
|
| 45 |
/** The constructor_fmin. */
|
|
| 46 |
private Integer pFminFilter;
|
|
| 50 | 47 |
|
| 51 | 48 |
/** The property. */ |
| 52 | 49 |
private Property pProperty; |
| 53 |
|
|
| 54 |
public LexicalTable(Corpus corpus, Subcorpus subcorpus) throws Exception {
|
|
| 55 |
this(Lexicon.getLexicon(corpus, corpus.getProperty("word")), Lexicon.getLexicon(subcorpus, subcorpus.getProperty("word")));
|
|
| 50 |
|
|
| 51 |
/** The constructor_vmax. */ |
|
| 52 |
private Integer pVMaxFilter; |
|
| 53 |
|
|
| 54 |
protected Boolean pUseAllOccurrences; |
|
| 55 |
|
|
| 56 |
protected static String getNextName() {
|
|
| 57 |
return SYMBOL_BASE+(LEXICALTABLE_COUNTER++); |
|
| 56 | 58 |
} |
| 57 |
|
|
| 58 |
public LexicalTable(Corpus corpus, Subcorpus subcorpus, Property property) throws Exception {
|
|
| 59 |
this(Lexicon.getLexicon(corpus, property), Lexicon.getLexicon(subcorpus, property)); |
|
| 59 |
|
|
| 60 |
public LexicalTable(Corpus corpus, Property analysisProperty, LexicalTableImpl itable) {
|
|
| 61 |
super(corpus); |
|
| 62 |
this.pProperty = analysisProperty; |
|
| 63 |
this.data = itable; |
|
| 60 | 64 |
} |
| 61 |
|
|
| 62 |
@Override |
|
| 63 |
protected boolean _compute(boolean update) throws Exception {
|
|
| 64 |
System.out.println("LexicalTable.compute() not implemented");
|
|
| 65 |
return false; |
|
| 66 |
} |
|
| 67 | 65 |
|
| 68 | 66 |
/** |
| 69 | 67 |
* Creates the lexical table. |
| 70 | 68 |
* |
| 71 | 69 |
* @param partindex the partindex |
| 72 |
* @param symbol the symbol |
|
| 73 | 70 |
* @return the lexical table |
| 74 | 71 |
* @throws RWorkspaceException the r workspace exception |
| 75 | 72 |
*/ |
| 76 |
public LexicalTable(Index partIndex,
|
|
| 77 |
String symbol) throws RWorkspaceException {
|
|
| 78 |
this(Arrays.asList(partIndex), symbol, true);
|
|
| 73 |
public LexicalTable(Index partIndex) throws RWorkspaceException {
|
|
| 74 |
super(partIndex);
|
|
| 75 |
this.pProperty = partIndex.getProperties().get(0);
|
|
| 79 | 76 |
} |
| 80 | 77 |
|
| 81 |
public LexicalTable(Lexicon corpusLexicon, Lexicon subcorpusLexicon) throws StatException {
|
|
| 82 |
super(corpusLexicon.getCorpus()); |
|
| 83 |
|
|
| 84 |
data = new LexicalTableImpl(corpusLexicon.getName()+ "minus" + subcorpusLexicon.getName(), corpusLexicon, subcorpusLexicon); |
|
| 85 |
|
|
| 86 |
this.pProperty = corpusLexicon.getProperty(); |
|
| 87 |
this.corpus = corpusLexicon.getCorpus(); |
|
| 88 |
this.corpus.addResult(this); |
|
| 89 |
} |
|
| 90 |
|
|
| 91 | 78 |
/** |
| 92 | 79 |
* Creates the lexical table. |
| 93 | 80 |
* |
| ... | ... | |
| 97 | 84 |
* @return the lexical table |
| 98 | 85 |
* @throws RWorkspaceException the r workspace exception |
| 99 | 86 |
*/ |
| 100 |
public LexicalTable(List<Index> vocabularies, String symbol, boolean useAllOccurrences) |
|
| 101 |
throws RWorkspaceException {
|
|
| 102 |
super(vocabularies.get(0)); |
|
| 87 |
protected void _computeForIndex(List<Index> vocabularies) |
|
| 88 |
throws RWorkspaceException {
|
|
| 103 | 89 |
System.out.println(LexicalTableCoreMessages.LexicalTableImpl_1 + vocabularies); |
| 104 | 90 |
Index partindex = vocabularies.get(0);// FRIGO |
| 91 |
Partition partition = partindex.getPartition(); // the Index is computed on a partition |
|
| 92 |
|
|
| 105 | 93 |
if (!partindex.isComputedWithPartition()) |
| 106 | 94 |
throw new IllegalArgumentException("Vocabularies are not computed with a partition. Aborting.");
|
| 107 | 95 |
|
| 108 |
this.partition = partindex.getPartition(); |
|
| 109 | 96 |
this.pProperty = partindex.getProperties().get(0); |
| 110 |
this.corpus = partindex.getPartition().getCorpus(); |
|
| 111 | 97 |
|
| 112 | 98 |
HashMap<String, Line> alllines = new HashMap<String, Line>(); |
| 113 | 99 |
// merge lines of all indexes |
| ... | ... | |
| 133 | 119 |
rownames.add(l.toString()); |
| 134 | 120 |
} |
| 135 | 121 |
int extra = 0; |
| 136 |
if(useAllOccurrences)
|
|
| 122 |
if (pUseAllOccurrences)
|
|
| 137 | 123 |
extra = 1; |
| 138 | 124 |
|
| 139 | 125 |
String[] entries = new String[alllines.size() + extra]; |
| ... | ... | |
| 149 | 135 |
entries[i++] = l.toString(); |
| 150 | 136 |
} |
| 151 | 137 |
|
| 152 |
if (useAllOccurrences) {
|
|
| 138 |
if (pUseAllOccurrences) {
|
|
| 153 | 139 |
try {
|
| 154 | 140 |
int[] partitionSizes = partition.getPartSizes(); |
| 155 | 141 |
int[] reste = new int[partitionSizes.length]; |
| ... | ... | |
| 157 | 143 |
//System.out.println("margins : "+Arrays.toString(margins));
|
| 158 | 144 |
//System.out.println("partsizes : "+Arrays.toString(partitionSizes));
|
| 159 | 145 |
|
| 160 |
for(i = 0 ; i < reste.length ; i++) {
|
|
| 146 |
for (i = 0 ; i < reste.length ; i++) {
|
|
| 161 | 147 |
reste[i] = partitionSizes[i] - margins[i]; |
| 162 |
if(reste[i] < 0) |
|
| 163 |
{
|
|
| 148 |
if (reste[i] < 0) {
|
|
| 164 | 149 |
System.out.println(LexicalTableCoreMessages.LexicalTableImpl_12+i+LexicalTableCoreMessages.LexicalTableImpl_13); |
| 165 | 150 |
throw new IllegalArgumentException(LexicalTableCoreMessages.LexicalTableImpl_12+i+LexicalTableCoreMessages.LexicalTableImpl_13); |
| 166 | 151 |
} |
| ... | ... | |
| 174 | 159 |
// TODO Auto-generated catch block |
| 175 | 160 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 176 | 161 |
} |
| 177 |
|
|
| 178 | 162 |
} |
| 179 | 163 |
//System.out.println("mat size : ["+(rownames.size() + extra)+"]["+colnames.size()+"]");
|
| 180 | 164 |
//System.out.println("rownames size : "+rownames.size());
|
| ... | ... | |
| 193 | 177 |
public LexicalTable(Partition partition, Property analysisProperty, int fmin, LexicalTableImpl itable) {
|
| 194 | 178 |
super(partition); |
| 195 | 179 |
this.pProperty = analysisProperty; |
| 196 |
this.partition = partition; |
|
| 197 |
this.corpus = partition.getCorpus(); |
|
| 198 | 180 |
this.data = itable; |
| 199 | 181 |
} |
| 200 | 182 |
|
| 201 |
public LexicalTable(Corpus corpus, Property analysisProperty, LexicalTableImpl itable) {
|
|
| 202 |
super(corpus); |
|
| 203 |
this.corpus = corpus; |
|
| 204 |
this.pProperty = analysisProperty; |
|
| 205 |
this.data = itable; |
|
| 183 |
public LexicalTable(Subcorpus subcorpus) throws Exception {
|
|
| 184 |
this(subcorpus, subcorpus.getProperty("word"));
|
|
| 206 | 185 |
} |
| 207 | 186 |
|
| 187 |
public LexicalTable(Subcorpus subcorpus, Property property) throws Exception {
|
|
| 188 |
super(subcorpus); |
|
| 189 |
this.pProperty = property; |
|
| 190 |
} |
|
| 191 |
|
|
| 208 | 192 |
@Override |
| 193 |
protected boolean _compute(boolean update) throws Exception {
|
|
| 194 |
|
|
| 195 |
if (parent instanceof Subcorpus) {
|
|
| 196 |
Subcorpus subcorpus = (Subcorpus) parent; |
|
| 197 |
Corpus parentCorpus = subcorpus.getMotherCorpus(); |
|
| 198 |
data = new LexicalTableImpl(getNextName(), new Lexicon(parentCorpus), new Lexicon(subcorpus)); |
|
| 199 |
} else if (parent instanceof Partition) {
|
|
| 200 |
_computeForPartition((Partition)parent); |
|
| 201 |
} else if (parent instanceof Index) {
|
|
| 202 |
_computeForIndex(Arrays.asList((Index)parent)); |
|
| 203 |
} |
|
| 204 |
return false; |
|
| 205 |
} |
|
| 206 |
|
|
| 207 |
protected void _computeForPartition(Partition partition) throws Exception {
|
|
| 208 |
//long time = System.currentTimeMillis(); |
|
| 209 |
List<Lexicon> lexicons = new ArrayList<Lexicon>(); |
|
| 210 |
// Set<String> allLexiconEntry = new HashSet<String>(); |
|
| 211 |
for (int i = 0; i < partition.getNPart(); i++) {
|
|
| 212 |
Lexicon l = Lexicon.getLexicon(partition.getParts().get(i), pProperty); |
|
| 213 |
lexicons.add(l); |
|
| 214 |
} |
|
| 215 |
//System.out.println("time lexicon build "+(System.currentTimeMillis()-time));
|
|
| 216 |
//time = System.currentTimeMillis(); |
|
| 217 |
// String[] entries = allLexiconEntry.toArray(new String[]{});
|
|
| 218 |
Corpus c = partition.getCorpus(); |
|
| 219 |
Lexicon ll = Lexicon.getLexicon(c, pProperty); |
|
| 220 |
|
|
| 221 |
ArrayList<String> filteredForms = new ArrayList<String>(); |
|
| 222 |
//create a copy and filter line with Fmin; |
|
| 223 |
for (int i = 0 ; i < ll.getFreq().length ; i++) {
|
|
| 224 |
if (ll.getFreq()[i] >= pFminFilter) {
|
|
| 225 |
filteredForms.add(ll.getForms()[i]); |
|
| 226 |
} |
|
| 227 |
} |
|
| 228 |
//System.out.println("remove freq too low "+(System.currentTimeMillis()-time));
|
|
| 229 |
//time = System.currentTimeMillis(); |
|
| 230 |
Map<String, Integer> entries2index = new HashMap<String, Integer>(); |
|
| 231 |
for (int i = 0; i < filteredForms.size(); i++) {
|
|
| 232 |
entries2index.put(filteredForms.get(i), i); |
|
| 233 |
} |
|
| 234 |
|
|
| 235 |
//System.out.println("entries2index "+(System.currentTimeMillis()-time));
|
|
| 236 |
//time = System.currentTimeMillis(); |
|
| 237 |
int[][] mat = new int[filteredForms.size()][lexicons.size()];//DoubleFactory2D.sparse.make(filteredForms.size(), lexicons.size(), 0); |
|
| 238 |
|
|
| 239 |
|
|
| 240 |
Integer id= null; |
|
| 241 |
for (int i = 0; i < lexicons.size(); i++) {
|
|
| 242 |
Lexicon l = lexicons.get(i); |
|
| 243 |
String[] ents = l.getForms(); |
|
| 244 |
int[] freqs = l.getFreq(); |
|
| 245 |
for (int j = 0; j < freqs.length; j++) {
|
|
| 246 |
id = entries2index.get(ents[j]); |
|
| 247 |
// if (entriesFreqs[id] >= 2) |
|
| 248 |
if (id != null) |
|
| 249 |
mat[id][i] = freqs[j]; //mat.setQuick(id, i, freqs[j]); |
|
| 250 |
} |
|
| 251 |
} |
|
| 252 |
//System.out.println("time build matrix "+(System.currentTimeMillis()-time));
|
|
| 253 |
//time = System.currentTimeMillis(); |
|
| 254 |
//System.out.println("Entries size " + filteredForms.size());
|
|
| 255 |
//System.out.println("mat size " + mat.rows());
|
|
| 256 |
//System.out.println("mat columns " + mat.columns());
|
|
| 257 |
|
|
| 258 |
data = new LexicalTableImpl(mat, filteredForms.toArray(new String[]{}), partition.getPartShortNames()
|
|
| 259 |
.toArray(new String[] {}));
|
|
| 260 |
|
|
| 261 |
} |
|
| 262 |
|
|
| 263 |
@Override |
|
| 264 |
public boolean canCompute() {
|
|
| 265 |
return true; // can be computed on partition or corpus |
|
| 266 |
} |
|
| 267 |
|
|
| 268 |
@Override |
|
| 209 | 269 |
public void clean() {
|
| 210 | 270 |
try {
|
| 211 | 271 |
RWorkspace.getRWorkspaceInstance().removeVariableFromWorkspace(data.getSymbol()); |
| ... | ... | |
| 214 | 274 |
e.printStackTrace(); |
| 215 | 275 |
} |
| 216 | 276 |
} |
| 217 |
|
|
| 277 |
|
|
| 218 | 278 |
public Vector getColMarginsVector() throws StatException {
|
| 219 | 279 |
return data.getColMarginsVector(); |
| 220 | 280 |
} |
| 221 |
|
|
| 281 |
|
|
| 222 | 282 |
public Vector getColNames() {
|
| 223 | 283 |
return data.getColNames(); |
| 224 | 284 |
} |
| 225 |
|
|
| 285 |
|
|
| 226 | 286 |
/** |
| 227 | 287 |
* Get the corpus this lexical table is bound to. |
| 228 | 288 |
* |
| 229 | 289 |
* @return the corpus or null if the LexicalTable was build without a Corpus or thiout a Partition (built with a Corpus) |
| 230 | 290 |
*/ |
| 231 | 291 |
public Corpus getCorpus() {
|
| 232 |
if (corpus != null) return corpus; |
|
| 233 |
else if (partition != null) return partition.getCorpus(); |
|
| 292 |
if (parent instanceof Corpus) return (Corpus)parent; |
|
| 293 |
if (parent instanceof Partition) return ((Partition)parent).getCorpus(); |
|
| 294 |
if (parent instanceof Index) return ((Index)parent).getCorpus(); |
|
| 234 | 295 |
else return null; |
| 235 | 296 |
} |
| 236 | 297 |
|
| ... | ... | |
| 238 | 299 |
return data; |
| 239 | 300 |
} |
| 240 | 301 |
|
| 302 |
@Override |
|
| 303 |
public String getDetails() {
|
|
| 304 |
return ""; |
|
| 305 |
} |
|
| 241 | 306 |
|
| 307 |
public int getFmin() {
|
|
| 308 |
return pFminFilter; |
|
| 309 |
} |
|
| 242 | 310 |
|
| 311 |
@Override |
|
| 312 |
public String getName() {
|
|
| 313 |
return this.getPartition().getSimpleName() + ":" + this.getSimpleName(); //$NON-NLS-1$ |
|
| 314 |
} |
|
| 315 |
|
|
| 243 | 316 |
public int getNColumns() {
|
| 244 | 317 |
return data.getNColumns(); |
| 245 | 318 |
} |
| ... | ... | |
| 247 | 320 |
public int getNRows() {
|
| 248 | 321 |
return data.getNRows(); |
| 249 | 322 |
} |
| 250 |
|
|
| 323 |
|
|
| 251 | 324 |
/** |
| 252 | 325 |
* Get the partition this lexical table is bound to. |
| 253 | 326 |
* |
| 254 | 327 |
* @return the partition |
| 255 | 328 |
*/ |
| 256 | 329 |
public Partition getPartition() {
|
| 257 |
return partition; |
|
| 330 |
if (parent instanceof Partition) return ((Partition)parent); |
|
| 331 |
if (parent instanceof Index) return ((Index)parent).getPartition(); |
|
| 332 |
else return null; |
|
| 258 | 333 |
} |
| 259 | 334 |
|
| 260 | 335 |
/** |
| ... | ... | |
| 278 | 353 |
return data.getRowNames(); |
| 279 | 354 |
} |
| 280 | 355 |
|
| 281 |
|
|
| 282 |
|
|
| 283 | 356 |
@Override |
| 284 |
public String getName() {
|
|
| 285 |
return this.getPartition().getSimpleName() + ":" + this.getSimpleName(); //$NON-NLS-1$ |
|
| 357 |
public String getSimpleName() {
|
|
| 358 |
StringBuilder strb = new StringBuilder(); |
|
| 359 |
if (pProperty != null) strb.append(pProperty.getName()+" "); |
|
| 360 |
if (data != null) strb.append(data.getFmin() + " / " + this.getNRows()); |
|
| 361 |
return strb.toString(); |
|
| 286 | 362 |
} |
| 287 | 363 |
|
| 288 |
@Override |
|
| 289 |
public String getSimpleName() {
|
|
| 290 |
return pProperty.getName() + " (" + data.getFmin() + " / " + this.getNRows() + ")";
|
|
| 364 |
public int getVmax() {
|
|
| 365 |
return pVMaxFilter; |
|
| 291 | 366 |
} |
| 292 | 367 |
|
| 293 | 368 |
@Override |
| 294 |
public String getDetails() {
|
|
| 369 |
public boolean saveParameters() {
|
|
| 295 | 370 |
// TODO Auto-generated method stub |
| 296 |
return null;
|
|
| 371 |
return false;
|
|
| 297 | 372 |
} |
| 298 |
|
|
| 299 | 373 |
|
| 300 |
public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) {
|
|
| 301 |
return data.toTxt(outfile, encoding, colseparator, txtseparator); |
|
| 302 |
} |
|
| 374 |
/** |
|
| 375 |
* see LexicalTablePreferences.PROPERTY, LexicalTablePreferences.F_MIN, LexicalTablePreferences.V_MAX and LexicalTablePreferences.USEALLOCCURENCES |
|
| 376 |
*/ |
|
| 377 |
@Override |
|
| 378 |
public boolean setParameters(TXMParameters parameters) {
|
|
| 379 |
try {
|
|
| 380 |
if (parameters.get(LexicalTablePreferences.PROPERTY) != null) {
|
|
| 381 |
Object o = parameters.get(LexicalTablePreferences.PROPERTY); |
|
| 382 |
if (o instanceof Property) this.pProperty = (Property) o; |
|
| 383 |
else if (o instanceof String) this.pProperty = this.getCorpus().getProperty(o.toString()); |
|
| 384 |
} |
|
| 385 |
if (parameters.get(LexicalTablePreferences.F_MIN) != null) {
|
|
| 386 |
Object o = parameters.get(LexicalTablePreferences.F_MIN); |
|
| 387 |
if (o instanceof Integer) this.pFminFilter = (Integer)o; |
|
| 388 |
else if (o instanceof String) this.pFminFilter = Integer.parseInt(o.toString()); |
|
| 389 |
} |
|
| 390 |
if (parameters.get(LexicalTablePreferences.V_MAX) != null) {
|
|
| 391 |
Object o = parameters.get(LexicalTablePreferences.V_MAX); |
|
| 392 |
if (o instanceof Integer) this.pVMaxFilter = (Integer)o; |
|
| 393 |
else if (o instanceof String) this.pVMaxFilter = Integer.parseInt(o.toString()); |
|
| 394 |
} |
|
| 395 |
if (parameters.get(LexicalTablePreferences.USEALLOCCURENCES) != null) {
|
|
| 396 |
Object o = parameters.get(LexicalTablePreferences.USEALLOCCURENCES); |
|
| 397 |
if (o instanceof Boolean) this.pUseAllOccurrences = (Boolean)o; |
|
| 398 |
else if (o instanceof Integer) this.pUseAllOccurrences = (Integer)o > 0; |
|
| 399 |
else if (o instanceof String) this.pUseAllOccurrences = Boolean.parseBoolean(o.toString()); |
|
| 400 |
} |
|
| 303 | 401 |
|
| 304 |
public int getFmin() {
|
|
| 305 |
return pFminFilter; |
|
| 402 |
dirty = true; |
|
| 403 |
} catch (Exception e) {
|
|
| 404 |
System.out.println("Error while setting LexicalTable parameters: "+e.getLocalizedMessage());
|
|
| 405 |
Log.printStackTrace(e); |
|
| 406 |
return false; |
|
| 407 |
} |
|
| 408 |
return true; |
|
| 306 | 409 |
} |
| 307 | 410 |
|
| 308 |
public int getVmax() {
|
|
| 309 |
return pVMaxFilter;
|
|
| 411 |
public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) {
|
|
| 412 |
return data.toTxt(outfile, encoding, colseparator, txtseparator);
|
|
| 310 | 413 |
} |
| 311 |
|
|
| 312 |
@Override |
|
| 313 |
public boolean canCompute() {
|
|
| 314 |
return corpus != null || partition != null; // can be computed on partition or corpus |
|
| 315 |
} |
|
| 316 | 414 |
|
| 317 |
@Override |
|
| 318 |
public boolean setParameters(TXMParameters parameters) {
|
|
| 319 |
return false; |
|
| 320 |
} |
|
| 415 |
public void setParameters(Property prop, Integer fmin, Integer vmax, Boolean useAllOccurrences) {
|
|
| 416 |
if (prop != null) this.pProperty = prop; |
|
| 417 |
if (fmin != null) this.pFminFilter = fmin; |
|
| 418 |
if (vmax != null) this.pVMaxFilter = vmax; |
|
| 419 |
if (useAllOccurrences != null) this.pUseAllOccurrences = useAllOccurrences; |
|
| 321 | 420 |
|
| 322 |
@Override |
|
| 323 |
public boolean saveParameters() {
|
|
| 324 |
// TODO Auto-generated method stub |
|
| 325 |
return false; |
|
| 421 |
this.dirty = true; |
|
| 326 | 422 |
} |
| 327 | 423 |
} |
| tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTableFactory.java (revision 534) | ||
|---|---|---|
| 13 | 13 |
import org.txm.searchengine.cqp.corpus.Corpus; |
| 14 | 14 |
import org.txm.searchengine.cqp.corpus.Partition; |
| 15 | 15 |
import org.txm.searchengine.cqp.corpus.Property; |
| 16 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
|
| 16 | 17 |
import org.txm.statsengine.core.StatException; |
| 18 |
import org.txm.statsengine.core.data.Vector; |
|
| 17 | 19 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
| 18 | 20 |
|
| 19 | 21 |
public class LexicalTableFactory {
|
| ... | ... | |
| 89 | 91 |
//System.out.println("time build table lexical "+(System.currentTimeMillis()-time));
|
| 90 | 92 |
return table; |
| 91 | 93 |
} |
| 94 |
|
|
| 95 |
public static LexicalTable getLexicalTable(Subcorpus subcorpus, Property property) throws Exception {
|
|
| 96 |
LexicalTable table = new LexicalTable(subcorpus, property); |
|
| 97 |
return table; |
|
| 98 |
} |
|
| 92 | 99 |
} |
| tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/preferences/LexicalTablePreferences.java (revision 534) | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
public static final String PREFERENCES_PREFIX = "lexical_table_"; //$NON-NLS-1$ |
| 23 | 23 |
|
| 24 |
/** |
|
| 25 |
* The minimal occurrence frequency to show in the table |
|
| 26 |
*/ |
|
| 24 | 27 |
public static final String F_MIN = PREFERENCES_PREFIX + "fmin"; //$NON-NLS-1$ |
| 28 |
/** |
|
| 29 |
* The maximum number of lines to show in the table |
|
| 30 |
*/ |
|
| 25 | 31 |
public static final String V_MAX = PREFERENCES_PREFIX + "vmax"; //$NON-NLS-1$ |
| 32 |
/** |
|
| 33 |
* The property to count |
|
| 34 |
*/ |
|
| 35 |
public static final String PROPERTY = PREFERENCES_PREFIX + "property"; //$NON-NLS-1$ |
|
| 36 |
/** |
|
| 37 |
* if true the table computed from an Index will use all the occurrences from the corpus to add the #RESTE# line composed of the others words |
|
| 38 |
*/ |
|
| 39 |
public static final String USEALLOCCURENCES = PREFERENCES_PREFIX + "usealloccurrences"; //$NON-NLS-1$ |
|
| 26 | 40 |
|
| 27 |
|
|
| 28 | 41 |
@Override |
| 29 | 42 |
public void initializeDefaultPreferences() {
|
| 30 | 43 |
Preferences preferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE); |
| 31 | 44 |
preferences.putInt(F_MIN, 2); |
| 32 | 45 |
preferences.putInt(V_MAX, 200); |
| 46 |
preferences.put(PROPERTY, "word"); |
|
| 47 |
preferences.putBoolean(USEALLOCCURENCES, true); |
|
| 33 | 48 |
} |
| 34 | 49 |
|
| 35 | 50 |
} |
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/AdapterFactory.java (revision 534) | ||
|---|---|---|
| 121 | 121 |
for (int i = 0; i < results.size(); i++) {
|
| 122 | 122 |
Object element = results.get(i); |
| 123 | 123 |
|
| 124 |
// remove Text and SavedQuery from the corpora view |
|
| 124 | 125 |
if (element instanceof Text || element instanceof SavedQuery) {
|
| 125 | 126 |
results.remove(i); |
| 126 | 127 |
i--; |
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/messages_fr.properties (revision 534) | ||
|---|---|---|
| 1045 | 1045 |
SpecificitiesTableEditor_11 = T |
| 1046 | 1046 |
SpecificitiesTableEditor_16 = Graphique : |
| 1047 | 1047 |
SpecificitiesTableEditor_17 = Chargement de la table des spécificités |
| 1048 |
SpecificitiesTableEditor_5 = Erreur inattendue dans le moteur statistique R |
|
| 1048 |
SpecificitiesTableEditor_5 = Erreur inattendue dans le moteur statistique R : {0}
|
|
| 1049 | 1049 |
SpecificitiesTableEditor_8 = Calculer le diagramme en bâtons des lignes sélectionnées |
| 1050 | 1050 |
|
| 1051 | 1051 |
Structure_field_not_empty = Le champ structure ne doit pas être vide. |
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditorPart.java (revision 534) | ||
|---|---|---|
| 173 | 173 |
} |
| 174 | 174 |
|
| 175 | 175 |
/** |
| 176 |
* @return the commandParametersComposite |
|
| 176 |
* @return the commandParametersComposite. Put here you main parameter widgets
|
|
| 177 | 177 |
*/ |
| 178 | 178 |
public Composite getCommandParametersGroup() {
|
| 179 | 179 |
return computingParametersGroup; |
| tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/messages_fr.properties (revision 534) | ||
|---|---|---|
| 1045 | 1045 |
SpecificitiesTableEditor_11 = T |
| 1046 | 1046 |
SpecificitiesTableEditor_16 = Graphique : |
| 1047 | 1047 |
SpecificitiesTableEditor_17 = Chargement de la table des spécificités |
| 1048 |
SpecificitiesTableEditor_5 = Erreur inattendue dans le moteur statistique R |
|
| 1048 |
SpecificitiesTableEditor_5 = Erreur inattendue dans le moteur statistique R : {0}
|
|
| 1049 | 1049 |
SpecificitiesTableEditor_8 = Calculer le diagramme en bâtons des lignes sélectionnées |
| 1050 | 1050 |
|
| 1051 | 1051 |
Structure_field_not_empty = Le champ structure ne doit pas être vide. |
| tmp/org.txm.searchengine.cqp.rcp/.settings/org.eclipse.core.resources.prefs (revision 534) | ||
|---|---|---|
| 1 |
eclipse.preferences.version=1 |
|
| 2 |
encoding//src/org/txm/searchengine/cqp/rcp/messages_fr.properties=UTF-8 |
|
| 0 | 3 | |
| tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/handlers/ComputeLexicalTable.java (revision 534) | ||
|---|---|---|
| 467 | 467 |
try {
|
| 468 | 468 |
monitor.beginTask("Computing Lexical table with Index: "+firstIndex+" property: "+property, 100);
|
| 469 | 469 |
this.acquireSemaphore(); |
| 470 |
table = new LexicalTable(vocabularies, QuantitativeDataStructureImpl.createSymbole(LexicalTableImpl.class), useAllOccurrences); |
|
| 470 |
table = new LexicalTable(firstIndex); |
|
| 471 |
table.setParameters(null, null, null, useAllOccurrences); |
|
| 472 |
table.compute(true, monitor); |
|
| 471 | 473 |
monitor.worked(45); |
| 472 | 474 |
this.releaseSemaphore(); |
| 473 | 475 |
if (monitor.isCanceled() || table == null) |
| tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifities.java (revision 534) | ||
|---|---|---|
| 42 | 42 |
import org.eclipse.ui.handlers.HandlerUtil; |
| 43 | 43 |
import org.txm.core.preferences.TXMPreferences; |
| 44 | 44 |
import org.txm.lexicaltable.core.functions.LexicalTable; |
| 45 |
import org.txm.lexicaltable.core.functions.LexicalTableFactory; |
|
| 45 | 46 |
import org.txm.lexicaltable.core.preferences.LexicalTablePreferences; |
| 46 | 47 |
import org.txm.rcp.editors.TXMEditorPart; |
| 47 | 48 |
import org.txm.rcp.editors.TXMResultEditorInput; |
| ... | ... | |
| 57 | 58 |
import org.txm.searchengine.cqp.corpus.Partition; |
| 58 | 59 |
import org.txm.searchengine.cqp.corpus.Property; |
| 59 | 60 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
| 60 |
import org.txm.specificities.core.functions.SpecificitesResult;
|
|
| 61 |
import org.txm.specificities.core.functions.Specificities;
|
|
| 61 | 62 |
import org.txm.specificities.core.preferences.SpecificitiesPreferences; |
| 62 | 63 |
import org.txm.specificities.rcp.dialogs.ComputeSpecificitiesDialog; |
| 63 | 64 |
import org.txm.specificities.rcp.dialogs.ComputeSpecificitiesForSubcorpusDialog; |
| ... | ... | |
| 76 | 77 |
* @author mdecorde |
| 77 | 78 |
*/ |
| 78 | 79 |
public class ComputeSpecifities extends BaseAbstractHandler {
|
| 79 |
|
|
| 80 |
|
|
| 80 |
|
|
| 81 |
|
|
| 81 | 82 |
// adds a double click listener to the Corpus View |
| 82 | 83 |
static {
|
| 83 |
CorporaView.addDoubleClickListener(SpecificitesResult.class, ComputeSpecifities.class);
|
|
| 84 |
CorporaView.addDoubleClickListener(Specificities.class, ComputeSpecifities.class);
|
|
| 84 | 85 |
} |
| 85 |
|
|
| 86 |
/** The window. */ |
|
| 87 |
private IWorkbenchWindow window; |
|
| 88 | 86 |
|
| 89 |
/** The selection. */ |
|
| 90 |
private IStructuredSelection selection; |
|
| 91 |
|
|
| 92 |
/** The specificities result. */ |
|
| 93 |
private SpecificitesResult specificitiesResult; |
|
| 94 |
|
|
| 95 | 87 |
/* |
| 96 | 88 |
* (non-Javadoc) |
| 97 | 89 |
* |
| ... | ... | |
| 102 | 94 |
@Override |
| 103 | 95 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
| 104 | 96 |
|
| 105 |
if(!this.checkStatsEngine()) {
|
|
| 97 |
if (!this.checkStatsEngine()) {
|
|
| 106 | 98 |
return null; |
| 107 | 99 |
} |
| 108 | 100 |
|
| 109 |
|
|
| 110 |
window = HandlerUtil.getActiveWorkbenchWindow(event); |
|
| 111 |
selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
| 112 |
if(selection == null) {
|
|
| 101 |
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); |
|
| 102 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
| 103 |
if (selection == null) {
|
|
| 113 | 104 |
Log.info(RCPMessages.ComputeSpecifities_1); |
| 114 | 105 |
return null; |
| 115 | 106 |
} |
| 116 |
Object s = selection.getFirstElement(); |
|
| 117 |
final int maxScore = TXMPreferences.getInt(SpecificitiesPreferences.MAX_SCORE, SpecificitiesPreferences.PREFERENCES_NODE); |
|
| 118 |
if(s instanceof Partition) {
|
|
| 119 |
final Partition partition = (Partition) selection.getFirstElement(); |
|
| 120 |
final int Fmin = TXMPreferences.getInt(LexicalTablePreferences.F_MIN, LexicalTablePreferences.PREFERENCES_NODE); |
|
| 107 |
final Object s = selection.getFirstElement(); |
|
| 108 |
final Integer maxScore = TXMPreferences.getInt(SpecificitiesPreferences.MAX_SCORE, SpecificitiesPreferences.PREFERENCES_NODE); |
|
| 109 |
final Integer Fmin = TXMPreferences.getInt(LexicalTablePreferences.F_MIN, LexicalTablePreferences.PREFERENCES_NODE); |
|
| 110 |
Property propertyChoice = null; |
|
| 121 | 111 |
|
| 122 |
final ComputeSpecificitiesDialog d = new ComputeSpecificitiesDialog(window.getShell(), partition, false); |
|
| 112 |
// depending on the selection, ask different parameters |
|
| 113 |
if (s instanceof Partition) {
|
|
| 114 |
|
|
| 115 |
Partition partition = (Partition) s; |
|
| 116 |
ComputeSpecificitiesDialog d = new ComputeSpecificitiesDialog(window.getShell(), partition, false); |
|
| 123 | 117 |
int code = d.open(); |
| 124 |
if(code == Window.OK) {
|
|
| 125 |
final Property property = d.getAnalysisProperty(); |
|
| 118 |
if (code == Window.OK) {
|
|
| 119 |
propertyChoice = d.getAnalysisProperty(); |
|
| 120 |
} else {
|
|
| 121 |
return null; |
|
| 122 |
} |
|
| 123 |
} else if (s instanceof Subcorpus) {
|
|
| 126 | 124 |
|
| 127 |
// final CorporaView corporaView = (CorporaView) |
|
| 128 |
// PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(CorporaView.ID); |
|
| 129 |
JobHandler jobhandler = new JobHandler(RCPMessages.ComputeSpecificities_0) {
|
|
| 130 |
@Override |
|
| 131 |
protected IStatus run(IProgressMonitor monitor) {
|
|
| 132 |
this.runInit(monitor); |
|
| 133 |
try {
|
|
| 134 |
JobsTimer.start(); |
|
| 135 |
String str = NLS.bind(RCPMessages.ComputeSpecificities_2, new Object[] { partition.getName(), property });
|
|
| 136 |
monitor.beginTask(str, 100); |
|
| 137 |
try {
|
|
| 138 |
System.out.println(str); |
|
| 139 |
this.acquireSemaphore(); |
|
| 140 |
specificitiesResult = new SpecificitesResult(partition, property, Fmin, maxScore); |
|
| 141 |
this.releaseSemaphore(); |
|
| 125 |
Subcorpus subcorpus = (Subcorpus) s; |
|
| 126 |
ComputeSpecificitiesForSubcorpusDialog d = new ComputeSpecificitiesForSubcorpusDialog(window.getShell(), subcorpus); |
|
| 127 |
int code = d.open(); |
|
| 128 |
if (code == Window.OK) {
|
|
| 129 |
propertyChoice = d.getProperty(); |
|
| 130 |
} else {
|
|
| 131 |
return null; |
|
| 132 |
} |
|
| 133 |
} |
|
| 142 | 134 |
|
| 143 |
System.out.println(NLS.bind(RCPMessages.DONE, specificitiesResult.getName())); |
|
| 144 |
} catch(Exception e) {
|
|
| 145 |
System.out.println(RCPMessages.ComputeSpecifities_4 + e); |
|
| 146 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
| 147 |
return Status.CANCEL_STATUS; |
|
| 148 |
} |
|
| 149 |
monitor.worked(45); |
|
| 135 |
final Property property = propertyChoice; |
|
| 150 | 136 |
|
| 151 |
specificitiesResult.getLexicalTable().addResult(specificitiesResult); |
|
| 152 |
// partition.storeResult(specificitiesResult); |
|
| 153 |
monitor.worked(5); |
|
| 137 |
JobHandler jobhandler = new JobHandler(RCPMessages.ComputeSpecificities_0) {
|
|
| 138 |
@Override |
|
| 139 |
protected IStatus run(IProgressMonitor monitor) {
|
|
| 140 |
this.runInit(monitor); |
|
| 141 |
try {
|
|
| 142 |
Specificities specifRes = null; |
|
| 154 | 143 |
|
| 155 |
monitor.subTask(RCPMessages.ComputeSpecifities_10); |
|
| 156 |
syncExec(new Runnable() {
|
|
| 157 |
@Override |
|
| 158 |
public void run() {
|
|
| 159 |
IWorkbenchPage page = window.getActivePage(); |
|
| 160 |
SpecificitiesResultEditorInput editorInput = new SpecificitiesResultEditorInput(specificitiesResult, partition); |
|
| 161 |
try {
|
|
| 162 |
StatusLine.setMessage(RCPMessages.ComputeSpecifities_10); |
|
| 163 |
page.openEditor(editorInput, SpecificitiesTableEditor.ID); //$NON-NLS-1$ |
|
| 164 |
} |
|
| 165 |
catch(PartInitException e) {
|
|
| 166 |
System.err.println(NLS.bind(RCPMessages.Error_computing_specificities, e)); |
|
| 167 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
| 168 |
} |
|
| 169 |
} |
|
| 170 |
}); |
|
| 144 |
if (s instanceof Partition) {
|
|
| 145 |
Partition partition = (Partition) s; |
|
| 171 | 146 |
|
| 172 |
monitor.worked(50); |
|
| 173 |
if(monitor.isCanceled()) |
|
| 174 |
return Status.CANCEL_STATUS; |
|
| 147 |
JobsTimer.start(); |
|
| 148 |
String str = NLS.bind(RCPMessages.ComputeSpecificities_2, new Object[] { partition.getName(), property });
|
|
| 149 |
monitor.beginTask(str, 100); |
|
| 150 |
System.out.println(str); |
|
| 175 | 151 |
|
| 176 |
monitor.subTask(RCPMessages.ComputeSpecifities_2); |
|
| 177 |
syncExec(new Runnable() {
|
|
| 178 |
@Override |
|
| 179 |
public void run() {
|
|
| 180 |
CorporaView.refresh(); |
|
| 181 |
CorporaView.expand(specificitiesResult.getParent()); |
|
| 182 |
QueriesView.refresh(); |
|
| 183 |
RVariablesView.refresh(); |
|
| 184 |
} |
|
| 185 |
}); |
|
| 152 |
this.acquireSemaphore(); |
|
| 153 |
LexicalTable table = LexicalTableFactory.getLexicalTable(partition, property, Fmin); |
|
| 154 |
this.releaseSemaphore(); |
|
| 186 | 155 |
|
| 187 |
monitor.worked(100); |
|
| 188 |
} catch(ThreadDeath td) {
|
|
| 189 |
return Status.CANCEL_STATUS; |
|
| 190 |
} catch(Exception e) {
|
|
| 191 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
| 192 |
} finally {
|
|
| 193 |
monitor.done(); |
|
| 194 |
JobsTimer.stopAndPrint(); |
|
| 195 |
} |
|
| 196 |
return Status.OK_STATUS; |
|
| 197 |
} |
|
| 198 |
}; |
|
| 199 |
jobhandler.startJob(); |
|
| 200 |
} |
|
| 201 |
} |
|
| 202 |
else if(s instanceof Subcorpus) {
|
|
| 203 |
final Subcorpus subcorpus = (Subcorpus) s; |
|
| 204 |
ComputeSpecificitiesForSubcorpusDialog d = new ComputeSpecificitiesForSubcorpusDialog(window.getShell(), subcorpus); |
|
| 205 |
int code = d.open(); |
|
| 206 |
if(code == Window.OK) {
|
|
| 207 |
final Property property = d.getProperty(); |
|
| 208 |
try {
|
|
| 209 |
JobHandler jobhandler = new JobHandler(RCPMessages.ComputeSpecificities_0) {
|
|
| 210 |
@Override |
|
| 211 |
protected IStatus run(IProgressMonitor monitor) {
|
|
| 212 |
this.runInit(monitor); |
|
| 156 |
if (monitor.isCanceled()) return Status.CANCEL_STATUS; |
|
| 213 | 157 |
|
| 214 |
try {
|
|
| 215 |
Corpus parentCorpus = subcorpus.getMotherSubcorpus(); |
|
| 216 |
if(parentCorpus == null) |
|
| 217 |
parentCorpus = subcorpus.getMainCorpus(); |
|
| 158 |
this.acquireSemaphore(); |
|
| 159 |
specifRes = new Specificities(table, maxScore); |
|
| 160 |
this.releaseSemaphore(); |
|
| 218 | 161 |
|
| 219 |
System.out.println(NLS.bind(RCPMessages.ComputeSpecifities_3, new Object[] { subcorpus.getName(), parentCorpus.getName(), property }));
|
|
| 220 |
specificitiesResult = new SpecificitesResult(parentCorpus, subcorpus, property, maxScore); |
|
| 221 |
System.out.println(NLS.bind(RCPMessages.DONE, specificitiesResult.getName())); |
|
| 222 |
subcorpus.addResult(specificitiesResult); |
|
| 223 |
} |
|
| 224 |
catch(Exception e) {
|
|
| 225 |
System.err.println(NLS.bind(RCPMessages.Error_computing_specificities, e)); |
|
| 226 |
System.err.println(e); |
|
| 227 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
| 228 |
} |
|
| 162 |
System.out.println(NLS.bind(RCPMessages.DONE, specifRes.getName())); |
|
| 163 |
} |
|
| 164 |
else if (s instanceof Subcorpus) {
|
|
| 165 |
Subcorpus subcorpus = (Subcorpus) s; |
|
| 166 |
|
|
| 167 |
this.acquireSemaphore(); |
|
| 168 |
LexicalTable table = LexicalTableFactory.getLexicalTable(subcorpus, property); |
|
| 169 |
this.releaseSemaphore(); |
|
| 229 | 170 |
|
| 230 |
monitor.subTask(RCPMessages.ComputeSpecifities_2); |
|
| 231 |
syncExec(new Runnable() {
|
|
| 232 |
@Override |
|
| 233 |
public void run() {
|
|
| 234 |
IWorkbenchPage page = window.getActivePage(); |
|
| 235 |
SpecificitiesResultEditorInput editorInput = new SpecificitiesResultEditorInput(specificitiesResult, subcorpus); |
|
| 171 |
if (monitor.isCanceled()) return Status.CANCEL_STATUS; |
|
| 236 | 172 |
|
| 237 |
try {
|
|
| 238 |
page.openEditor(editorInput, SpecificitiesTableEditor.ID); |
|
| 239 |
} |
|
| 240 |
catch(PartInitException e) {
|
|
| 241 |
e.printStackTrace(); |
|
| 242 |
} |
|
| 173 |
System.out.println(NLS.bind(RCPMessages.ComputeSpecifities_3, new Object[] { subcorpus.getName(), subcorpus.getMotherCorpus().getName(), property }));
|
|
| 174 |
specifRes = new Specificities(table, maxScore); |
|
| 175 |
} |
|
| 176 |
else if (s instanceof LexicalTable) {
|
|
| 177 |
LexicalTable table = (LexicalTable) s; |
|
| 243 | 178 |
|
| 244 |
CorporaView.refresh(); |
|
| 245 |
CorporaView.expand(specificitiesResult.getParent()); |
|
| 246 |
QueriesView.refresh(); |
|
| 247 |
RVariablesView.refresh(); |
|
| 248 |
} |
|
| 249 |
}); |
|
| 250 |
|
|
| 251 |
return Status.OK_STATUS; |
|
| 252 |
} |
|
| 253 |
}; |
|
| 254 |
jobhandler.startJob(); |
|
| 255 |
} |
|
| 256 |
catch(Exception e) {
|
|
| 257 |
System.err.println(NLS.bind(RCPMessages.Error_computing_specificities, e)); |
|
| 258 |
} |
|
| 259 |
} |
|
| 260 |
} |
|
| 261 |
else if(s instanceof LexicalTable) {
|
|
| 262 |
final LexicalTable table = (LexicalTable) s; |
|
| 263 |
JobHandler jobhandler = new JobHandler(RCPMessages.ComputeSpecificities_0) {
|
|
| 264 |
@Override |
|
| 265 |
protected IStatus run(IProgressMonitor monitor) {
|
|
| 266 |
this.runInit(monitor); |
|
| 267 |
try {
|
|
| 268 | 179 |
JobsTimer.start(); |
| 269 | 180 |
monitor.beginTask(NLS.bind(RCPMessages.ComputeSpecifities_11, table.getPartition().getName()), 100); |
| 270 |
try {
|
|
| 271 |
System.out.println(RCPMessages.ComputeSpecificities_0 + ": " + table.getPartition().getName()); //$NON-NLS-1$ |
|
| 272 |
this.acquireSemaphore(); |
|
| 273 |
specificitiesResult = new SpecificitesResult(table, maxScore); |
|
| 274 |
this.releaseSemaphore(); |
|
| 275 |
System.out.println(NLS.bind(RCPMessages.DONE, specificitiesResult.getName())); |
|
| 276 |
} |
|
| 277 |
catch(StatException e) {
|
|
| 278 |
System.err.println(NLS.bind(RCPMessages.Error_computing_specificities, e)); |
|
| 279 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
| 280 |
return Status.CANCEL_STATUS; |
|
| 281 |
} |
|
| 282 |
monitor.worked(45); |
|
| 283 |
if(monitor.isCanceled()) |
|
| 284 |
return Status.CANCEL_STATUS; |
|
| 285 |
|
|
| 181 |
System.out.println(RCPMessages.ComputeSpecificities_0 + ": " + table.getPartition().getName()); //$NON-NLS-1$ |
|
| 182 |
|
|
| 286 | 183 |
this.acquireSemaphore(); |
| 287 |
table.addResult(specificitiesResult);
|
|
| 184 |
specifRes = new Specificities(table, maxScore);
|
|
| 288 | 185 |
this.releaseSemaphore(); |
| 289 |
monitor.worked(5); |
|
| 186 |
|
|
| 187 |
System.out.println(NLS.bind(RCPMessages.DONE, specifRes.getName())); |
|
| 188 |
monitor.worked(45); |
|
| 290 | 189 |
|
| 291 |
monitor.subTask(RCPMessages.ComputeSpecifities_10); |
|
| 292 |
syncExec(new Runnable() {
|
|
| 293 |
@Override |
|
| 294 |
public void run() {
|
|
| 295 |
IWorkbenchPage page = window.getActivePage(); |
|
| 296 |
SpecificitiesResultEditorInput editorInput = null; |
|
| 297 |
if(table.getPartition() == null) {
|
|
| 298 |
editorInput = new SpecificitiesResultEditorInput(specificitiesResult, table.getCorpus()); |
|
| 299 |
} |
|
| 300 |
else {
|
|
| 301 |
editorInput = new SpecificitiesResultEditorInput(specificitiesResult, table.getPartition()); |
|
| 302 |
} |
|
| 303 |
try {
|
|
| 304 |
StatusLine.setMessage(RCPMessages.ComputeSpecifities_10); |
|
| 305 |
page.openEditor(editorInput, SpecificitiesTableEditor.ID); //$NON-NLS-1$ |
|
| 190 |
if (monitor.isCanceled()) return Status.CANCEL_STATUS; |
|
| 191 |
} else if (s instanceof Specificities) { // re-openning a Speicificties result
|
|
| 192 |
specifRes = (Specificities) s; |
|
| 193 |
} |
|
| 306 | 194 |
|
| 307 |
}
|
|
| 308 |
catch(PartInitException e) {
|
|
| 309 |
org.txm.rcp.utils.Logger.printStackTrace(e);
|
|
| 310 |
}
|
|
| 311 |
} |
|
| 312 |
});
|
|
| 195 |
if (specifRes == null) {
|
|
| 196 |
System.out.println("Cannot compute Specificities with "+s);
|
|
| 197 |
return Status.CANCEL_STATUS;
|
|
| 198 |
} |
|
| 199 |
|
|
| 200 |
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
|
| 313 | 201 |
|
| 314 |
monitor.worked(50); |
|
| 315 |
if(monitor.isCanceled()) {
|
|
| 316 |
return Status.CANCEL_STATUS; |
|
| 317 |
} |
|
| 202 |
final Specificities specifResFinal = specifRes; |
|
| 203 |
this.syncExec(new Runnable() {
|
|
| 204 |
@Override |
|
| 205 |
public void run() {
|
|
| 206 |
CorporaView.refresh(); |
|
| 207 |
CorporaView.expand(specifResFinal.getParent()); |
|
| 318 | 208 |
|
| 319 |
monitor.subTask(RCPMessages.ComputeSpecifities_2); |
|
| 320 |
syncExec(new Runnable() {
|
|
| 321 |
@Override |
|
| 322 |
public void run() {
|
|
| 323 |
CorporaView.refresh(); |
|
| 324 |
CorporaView.expand(specificitiesResult.getParent()); |
|
| 325 |
QueriesView.refresh(); |
|
| 326 |
RVariablesView.refresh(); |
|
| 327 |
} |
|
| 328 |
}); |
|
| 209 |
TXMResultEditorInput editorInput = null; |
|
| 329 | 210 |
|
| 330 |
monitor.worked(100); |
|
| 331 |
} |
|
| 332 |
catch(ThreadDeath td) {
|
|
| 333 |
return Status.CANCEL_STATUS; |
|
| 334 |
} |
|
| 335 |
catch(CqiClientException e) {
|
|
| 336 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
| 337 |
} |
|
| 338 |
finally {
|
|
| 339 |
monitor.done(); |
|
| 340 |
JobsTimer.stopAndPrint(); |
|
| 341 |
} |
|
| 342 |
return Status.OK_STATUS; |
|
| 343 |
} |
|
| 344 |
}; |
|
| 345 |
jobhandler.startJob(); |
|
| 346 |
} |
|
| 347 |
// reopens an existing result |
|
| 348 |
else if(s instanceof SpecificitesResult) {
|
|
| 349 |
SpecificitesResult specifRes = (SpecificitesResult) s; |
|
| 350 |
Partition partition = null; |
|
| 351 |
TXMResultEditorInput editorInput = null; |
|
| 211 |
editorInput = new SpecificitiesResultEditorInput(specifResFinal); |
|
| 352 | 212 |
|
| 353 |
if(specifRes.getLexicalTable() != null) {
|
|
| 354 |
if(specifRes.getLexicalTable().getPartition() != null) {
|
|
| 355 |
partition = specifRes.getLexicalTable().getPartition(); |
|
| 356 |
editorInput = new SpecificitiesResultEditorInput(specifRes, partition); |
|
| 213 |
TXMEditorPart.openEditor(editorInput, SpecificitiesTableEditor.ID); |
|
| 214 |
} |
|
| 215 |
}); |
|
| 216 |
|
|
| 217 |
} catch(Exception e) {
|
|
| 218 |
System.out.println(RCPMessages.Error_computing_specificities); |
|
| 219 |
Log.printStackTrace(e); |
|
| 220 |
return Status.CANCEL_STATUS; |
|
| 357 | 221 |
} |
| 358 |
else {
|
|
| 359 |
editorInput = new SpecificitiesResultEditorInput(specifRes, specifRes.getLexicalTable().getCorpus()); |
|
| 360 |
} |
|
| 361 |
} |
|
| 362 |
else {
|
|
| 363 |
editorInput = new SpecificitiesResultEditorInput(specifRes, specifRes.getCorpus()); |
|
| 364 |
} |
|
| 365 | 222 |
|
| 366 |
TXMEditorPart.openEditor(editorInput, SpecificitiesTableEditor.ID); |
|
| 367 |
} |
|
| 368 |
|
|
| 223 |
return Status.OK_STATUS; |
|
| 224 |
} |
|
| 225 |
}; |
|
| 226 |
jobhandler.startJob(); |
|
| 369 | 227 |
return null; |
| 370 | 228 |
} |
| 371 | 229 |
} |
| tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifictiesBarChart.java (revision 534) | ||
|---|---|---|
| 17 | 17 |
import org.txm.chartsengine.rcp.swt.ChartEditorToolBar; |
| 18 | 18 |
import org.txm.core.preferences.TXMPreferences; |
| 19 | 19 |
import org.txm.rcp.IImageKeys; |
| 20 |
import org.txm.specificities.core.functions.SpecificitesResult;
|
|
| 20 |
import org.txm.specificities.core.functions.Specificities;
|
|
| 21 | 21 |
import org.txm.specificities.core.preferences.SpecificitiesPreferences; |
| 22 | 22 |
import org.txm.specificities.rcp.editors.SpecificitiesTableEditor; |
| 23 | 23 |
import org.txm.specificities.rcp.editors.SpecificitiesTableLines; |
| ... | ... | |
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 | 43 |
SpecificitiesTableEditor editor = (SpecificitiesTableEditor)ieditor; |
| 44 |
SpecificitesResult specificitiesResult = editor.getSpecificitiesResult();
|
|
| 44 |
Specificities specificitiesResult = editor.getSpecificitiesResult();
|
|
| 45 | 45 |
Table specificitesTable = editor.getSpecificitesTable(); |
| 46 | 46 |
SpecificitiesTableLines tableLines = editor.getTableLines(); |
| 47 | 47 |
double[][] specIndex = specificitiesResult.getSpecificitesIndex(); |
| ... | ... | |
| 78 | 78 |
* @param typeNames |
| 79 | 79 |
* @param specificteIndices |
| 80 | 80 |
*/ |
| 81 |
public void openEditor(SpecificitesResult specificitiesResult, String[] partNames, String[] typeNames, double[][] specificteIndices) {
|
|
| 81 |
public void openEditor(Specificities specificitiesResult, String[] partNames, String[] typeNames, double[][] specificteIndices) {
|
|
| 82 | 82 |
try {
|
| 83 | 83 |
|
| 84 | 84 |
// Set the data to focus on |
| tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/adapters/SpecificitiesAdapterFactory.java (revision 534) | ||
|---|---|---|
| 7 | 7 |
import org.osgi.framework.FrameworkUtil; |
| 8 | 8 |
import org.txm.rcp.adapters.TXMResultAdapter; |
| 9 | 9 |
import org.txm.rcp.adapters.TXMResultAdapterFactory; |
| 10 |
import org.txm.specificities.core.functions.SpecificitesResult;
|
|
| 10 |
import org.txm.specificities.core.functions.Specificities;
|
|
| 11 | 11 |
|
| 12 | 12 |
|
| 13 | 13 |
/** |
| ... | ... | |
| 26 | 26 |
|
| 27 | 27 |
@Override |
| 28 | 28 |
public Object getAdapter(Object adaptableObject, Class adapterType) {
|
| 29 |
if(adapterType == IWorkbenchAdapter.class && adaptableObject instanceof SpecificitesResult) {
|
|
| 29 |
if(adapterType == IWorkbenchAdapter.class && adaptableObject instanceof Specificities) {
|
|
| 30 | 30 |
return new TXMResultAdapter() {
|
| 31 | 31 |
@Override |
| 32 | 32 |
public ImageDescriptor getImageDescriptor(Object object) {
|
| tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/messages/messages_ru.properties (revision 534) | ||
|---|---|---|
| 18 | 18 |
SpecificitiesTableEditor_11= T |
| 19 | 19 |
SpecificitiesTableEditor_16=График: |
| 20 | 20 |
SpecificitiesTableEditor_17=Загрузка таблицы специфичности |
| 21 |
SpecificitiesTableEditor_5=Неожиданная ошибка в статистической машине R |
|
| 21 |
SpecificitiesTableEditor_5=Неожиданная ошибка в статистической машине R : {0}
|
|
| 22 | 22 |
SpecificitiesTableEditor_8=Построить гистограмму выделенных строк |
| tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/messages/messages_fr.properties (revision 534) | ||
|---|---|---|
| 19 | 19 |
SpecificitiesTableEditor_11=T |
| 20 | 20 |
SpecificitiesTableEditor_16=Graphique : |
| 21 | 21 |
SpecificitiesTableEditor_17=Chargement de la table des spécificités |
| 22 |
SpecificitiesTableEditor_5=Erreur inattendue dans le moteur statistique R |
|
| 22 |
SpecificitiesTableEditor_5=Erreur inattendue dans le moteur statistique R : {0}
|
|
| 23 | 23 |
SpecificitiesTableEditor_8=Calculer le diagramme en bâtons des lignes sélectionnées |
| tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/SpecificitiesTableEditor.java (revision 534) | ||
|---|---|---|
| 35 | 35 |
import java.util.Locale; |
| 36 | 36 |
|
| 37 | 37 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 38 |
import org.eclipse.core.runtime.IStatus; |
|
| 39 |
import org.eclipse.core.runtime.Status; |
|
| 38 | 40 |
import org.eclipse.jface.action.MenuManager; |
| 39 | 41 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
| 40 | 42 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
| ... | ... | |
| 50 | 52 |
import org.eclipse.swt.widgets.Label; |
| 51 | 53 |
import org.eclipse.swt.widgets.Menu; |
| 52 | 54 |
import org.eclipse.swt.widgets.ScrollBar; |
| 55 |
import org.eclipse.swt.widgets.Spinner; |
|
| 53 | 56 |
import org.eclipse.swt.widgets.Table; |
| 54 | 57 |
import org.eclipse.swt.widgets.TableColumn; |
| 55 | 58 |
import org.eclipse.ui.IEditorInput; |
| 56 | 59 |
import org.eclipse.ui.IEditorSite; |
| 57 | 60 |
import org.eclipse.ui.PartInitException; |
| 58 | 61 |
import org.eclipse.ui.PlatformUI; |
| 62 |
import org.eclipse.ui.part.EditorPart; |
|
| 59 | 63 |
import org.txm.core.results.TXMResult; |
| 60 | 64 |
import org.txm.objects.TxmObject; |
| 61 | 65 |
import org.txm.rcp.RCPMessages; |
| 62 | 66 |
import org.txm.rcp.StatusLine; |
| 63 | 67 |
import org.txm.rcp.editors.TXMEditorPart; |
| 64 | 68 |
import org.txm.rcp.editors.TableKeyListener; |
| 65 |
import org.txm.specificities.core.functions.SpecificitesResult; |
|
| 69 |
import org.txm.rcp.utils.JobHandler; |
|
| 70 |
import org.txm.specificities.core.functions.Specificities; |
|
| 71 |
import org.txm.specificities.core.preferences.SpecificitiesPreferences; |
|
| 66 | 72 |
import org.txm.specificities.rcp.messages.SpecificitiesUIMessages; |
| 67 | 73 |
import org.txm.statsengine.core.StatException; |
| 74 |
import org.txm.utils.logger.Log; |
|
| 68 | 75 |
/** |
| 69 | 76 |
* Display a table editor with specificites index. |
| 70 | 77 |
* |
| ... | ... | |
| 74 | 81 |
public class SpecificitiesTableEditor extends TXMEditorPart {
|
| 75 | 82 |
|
| 76 | 83 |
public static String ID = SpecificitiesTableEditor.class.getName(); |
| 77 |
|
|
| 84 |
|
|
| 78 | 85 |
/** The specificities table. */ |
| 79 | 86 |
private Table specificitesTable; |
| 80 | 87 |
private TableViewer viewer; |
| 81 |
|
|
| 88 |
|
|
| 82 | 89 |
/** Column for table typeNameTable. */ |
| 83 | 90 |
private TableColumn typeNameColumn; |
| 84 | 91 |
|
| ... | ... | |
| 92 | 99 |
private List<TableColumn> specificitesTableColumn = new ArrayList<TableColumn>(); |
| 93 | 100 |
|
| 94 | 101 |
/** The result of specificities*/ |
| 95 |
private SpecificitesResult specificitiesResult;
|
|
| 102 |
private Specificities specificitiesResult;
|
|
| 96 | 103 |
|
| 97 | 104 |
/** The table lines : table input */ |
| 98 | 105 |
private SpecificitiesTableLines tableLines; |
| ... | ... | |
| 108 | 115 |
super.init(site, input); |
| 109 | 116 |
|
| 110 | 117 |
SpecificitiesResultEditorInput spinput = (SpecificitiesResultEditorInput) getEditorInput(); |
| 111 |
this.specificitiesResult = (SpecificitesResult) ((SpecificitiesResultEditorInput) getEditorInput()).getResult();
|
|
| 118 |
this.specificitiesResult = (Specificities) ((SpecificitiesResultEditorInput) getEditorInput()).getResult();
|
|
| 112 | 119 |
if (this.specificitiesResult.getLexicalTable()!= null && this.specificitiesResult.getLexicalTable().getPartition() != null) {
|
| 113 | 120 |
setPartName(this.specificitiesResult.getLexicalTable().getPartition().getName()+": "+specificitiesResult.getName()); //$NON-NLS-1$ |
| 114 | 121 |
} else if (spinput.getSubcorpus() != null) {
|
| ... | ... | |
| 123 | 130 |
*/ |
| 124 | 131 |
@Override |
| 125 | 132 |
public void createPartControl(Composite parent) {
|
| 126 |
Composite displayArea = new Composite(parent, SWT.BORDER); |
|
| 127 |
displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
| 133 |
super.createPartControl(parent); |
|
| 134 |
|
|
| 135 |
Composite parametersArea = getCommandParametersGroup(); |
|
| 136 |
|
|
| 137 |
new Label(parametersArea, SWT.NONE).setText("Maximum score");
|
|
| 138 |
|
|
| 139 |
Spinner maxScore = new Spinner(parametersArea, SWT.BORDER); |
|
| 140 |
maxScore.setToolTipText("The maximum score to show");
|
|
| 141 |
maxScore.setMinimum(0); |
|
| 142 |
maxScore.setSelection(SpecificitiesPreferences.getInt(SpecificitiesPreferences.MAX_SCORE, SpecificitiesPreferences.PREFERENCES_NODE)); |
|
| 143 |
|
|
| 144 |
Composite displayArea = getDisplayArea(); |
|
| 145 |
//displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
| 128 | 146 |
try {
|
| 129 | 147 |
composeDisplayArea(displayArea); |
| 130 | 148 |
} catch (StatException e) {
|
| ... | ... | |
| 140 | 158 |
new IRunnableWithProgress() {
|
| 141 | 159 |
@Override |
| 142 | 160 |
public void run(IProgressMonitor monitor) |
| 143 |
throws InvocationTargetException, |
|
| 144 |
InterruptedException {
|
|
| 161 |
throws InvocationTargetException,
|
|
| 162 |
InterruptedException {
|
|
| 145 | 163 |
tableLines.sort(currentComparator); |
| 146 | 164 |
} |
| 147 | 165 |
}); |
| ... | ... | |
| 165 | 183 |
layout.marginWidth = layout.marginHeight = layout.horizontalSpacing = 0; |
| 166 | 184 |
parent.setLayout(layout); |
| 167 | 185 |
|
| 168 |
final SpecificitesResult specificitiesResult = this.specificitiesResult; |
|
| 169 |
// units |
|
| 170 |
final String[] typeNames = specificitiesResult.getTypeNames(); |
|
| 171 |
// units' total freq |
|
| 172 |
final int[] typeFreq = specificitiesResult.getFormFrequencies(); |
|
| 173 |
// units' index fr each part |
|
| 174 |
final double[][] specIndex = specificitiesResult.getSpecificitesIndex(); |
|
| 175 |
final int[][] specFreqs = specificitiesResult.getFrequency(); |
|
| 176 |
// units' total in parts |
|
| 177 |
//final int[] sortedPartIndexes = specificitesResult.getSortedPartIndexes(); |
|
| 178 |
|
|
| 179 |
// Create an array of lines to fill the tables |
|
| 180 |
// System.out.println("len types: "+typeNames.length);
|
|
| 181 |
// System.out.println("len freq: "+typeFreq.length);
|
|
| 182 |
// System.out.println("len spec: "+specFreqs.length);
|
|
| 183 |
// System.out.println("len specidx: "+specIndex.length);
|
|
| 184 |
Object[] lines = new Object[typeNames.length]; |
|
| 185 |
for (int j = 0; j < lines.length; j++) |
|
| 186 |
lines[j] = new Object[] { typeNames[j], new Integer(typeFreq[j]), specFreqs[j], specIndex[j] };
|
|
| 187 |
|
|
| 188 |
// final SpecificitesTableLines |
|
| 189 |
tableLines = new SpecificitiesTableLines(lines); |
|
| 190 |
|
|
| 191 | 186 |
// create table viewer |
| 192 | 187 |
viewer = new TableViewer(parent, SWT.VIRTUAL | SWT.MULTI | SWT.FULL_SELECTION); |
| 193 | 188 |
viewer.getTable().addKeyListener(new TableKeyListener(viewer)); |
| 194 | 189 |
viewer.getTable().setLinesVisible(true); |
| 195 | 190 |
viewer.getTable().setHeaderVisible(true); |
| 196 | 191 |
viewer.setLabelProvider(new SpecificitiesTableLabelProvider()); |
| 197 |
viewer.setContentProvider(new IStructuredContentProvider() {
|
|
| 198 |
@Override |
|
| 199 |
public Object[] getElements(Object inputElement) {
|
|
| 200 |
return ((SpecificitiesTableLines) inputElement).getLines(); |
|
| 201 |
} |
|
| 202 | 192 |
|
| 203 |
@Override |
|
| 204 |
public void dispose() { }
|
|
| 205 |
|
|
| 206 |
@Override |
|
| 207 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
|
| 208 |
} |
|
| 209 |
}); |
|
| 210 |
|
|
| 211 | 193 |
specificitesTable = viewer.getTable(); |
| 212 | 194 |
GridData table2Data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2); |
| 213 | 195 |
specificitesTable.setLayoutData(table2Data); |
| ... | ... | |
| 319 | 301 |
partSize = specificitiesResult.getPartSizes(); |
| 320 | 302 |
} catch (StatException e) {
|
| 321 | 303 |
System.err.println(NLS.bind(SpecificitiesUIMessages.SpecificitiesTableEditor_5, e)); |
| 304 |
Log.printStackTrace(e); |
|
| 322 | 305 |
return; |
| 323 | 306 |
} |
| 324 | 307 |
// System.out.println("partnames: "+Arrays.toString(partNames));
|
| ... | ... | |
| 351 | 334 |
((int[]) line2[2])[columnIndex])); |
| 352 | 335 |
} |
| 353 | 336 |
}; |
| 354 |
|
|
| 337 |
|
|
| 355 | 338 |
if (specificitesTable.getSortColumn() != freqpartTableColumn) {
|
| 356 | 339 |
specificitesTable.setSortColumn(freqpartTableColumn); |
| 357 | 340 |
specificitesTable.setSortDirection(SWT.DOWN); |
| ... | ... | |
| 442 | 425 |
specificitesTable.setMenu(menu); |
| 443 | 426 |
getSite().setSelectionProvider(viewer); |
| 444 | 427 |
getSite().registerContextMenu(menuManager, viewer); |
| 445 |
|
|
| 446 |
// Draw lines |
|
| 447 |
fillDisplay(); |
|
| 448 | 428 |
|
| 429 |
|
|
| 430 |
|
|
| 449 | 431 |
// and first sort |
| 450 | 432 |
specificitesTable.setSortColumn(typeNameColumn); |
| 451 | 433 |
specificitesTable.setSortDirection(SWT.UP); |
| ... | ... | |
| 457 | 439 |
return collator.compare(line1[0], line2[0]); |
| 458 | 440 |
} |
| 459 | 441 |
}; |
| 460 |
|
|
| 461 |
sort();
|
|
| 462 |
|
|
| 463 |
specificitesTable.setFocus(); |
|
| 442 |
|
|
| 443 |
// compute the specif scores
|
|
| 444 |
computeResult(); |
|
| 445 |
|
|
| 464 | 446 |
} |
| 465 |
|
|
| 447 |
|
|
| 466 | 448 |
public Table getSpecificitesTable() {
|
| 467 | 449 |
return specificitesTable; |
| 468 | 450 |
} |
| ... | ... | |
| 471 | 453 |
* Fills display. |
| 472 | 454 |
*/ |
| 473 | 455 |
private void fillDisplay() {
|
| 474 |
|
|
| 456 |
|
|
| 475 | 457 |
viewer.setInput(tableLines); |
| 476 | 458 |
|
| 477 | 459 |
// Pack the columns so the label of the sort column is not truncated due of the sorting order arrow display |
| ... | ... | |
| 534 | 516 |
* |
| 535 | 517 |
* @return the specificities result |
| 536 | 518 |
*/ |
| 537 |
public SpecificitesResult getSpecificitiesResult() {
|
|
| 519 |
public Specificities getSpecificitiesResult() {
|
|
| 538 | 520 |
return this.specificitiesResult; |
| 539 | 521 |
} |
| 540 |
|
|
| 522 |
|
|
| 541 | 523 |
public SpecificitiesTableLines getTableLines() {
|
| 542 | 524 |
return tableLines; |
| 543 | 525 |
} |
| ... | ... | |
| 551 | 533 |
|
| 552 | 534 |
@Override |
| 553 | 535 |
public void computeResult() {
|
| 554 |
// FIXME! not yet implemented |
|
| 555 |
System.err.println("SpecificitiesTableEditor.computeResult(): not yet implemented.");
|
|
| 536 |
JobHandler job = new JobHandler("Computing specificities...") {
|
|
| 537 |
|
|
| 538 |
@Override |
|
| 539 |
protected IStatus run(IProgressMonitor monitor) {
|
|
| 540 |
this.runInit(monitor); |
|
| 541 |
try {
|
|
| 542 |
if (!specificitiesResult.compute(true, monitor)) {
|
|
| 543 |
System.out.println("Error: Specificities not computed.");
|
|
| 544 |
return Status.CANCEL_STATUS; |
|
| 545 |
} |
|
| 546 |
|
|
| 547 |
// units |
|
| 548 |
String[] typeNames = specificitiesResult.getTypeNames(); |
|
| 549 |
// units' total freq |
|
| 550 |
int[] typeFreq = specificitiesResult.getFormFrequencies(); |
|
| 551 |
// units' index fr each part |
|
| 552 |
double[][] specIndex = specificitiesResult.getSpecificitesIndex(); |
|
| 553 |
int[][] specFreqs = specificitiesResult.getFrequency(); |
|
| 554 |
|
|
| 555 |
// units' total in parts |
|
| 556 |
//final int[] sortedPartIndexes = specificitesResult.getSortedPartIndexes(); |
|
| 557 |
|
|
| 558 |
// Create an array of lines to fill the tables |
|
| 559 |
// System.out.println("len types: "+typeNames.length);
|
|
| 560 |
// System.out.println("len freq: "+typeFreq.length);
|
|
| 561 |
// System.out.println("len spec: "+specFreqs.length);
|
|
| 562 |
// System.out.println("len specidx: "+specIndex.length);
|
|
| 563 |
Object[] lines = new Object[typeNames.length]; |
|
| 564 |
for (int j = 0; j < lines.length; j++) |
|
| 565 |
lines[j] = new Object[] { typeNames[j], new Integer(typeFreq[j]), specFreqs[j], specIndex[j] };
|
|
| 566 |
|
|
| 567 |
// final SpecificitesTableLines |
|
| 568 |
tableLines = new SpecificitiesTableLines(lines); |
|
| 569 |
|
|
| 570 |
// set the TableViewer input |
|
| 571 |
viewer.setContentProvider(new IStructuredContentProvider() {
|
|
| 572 |
@Override |
|
| 573 |
public Object[] getElements(Object inputElement) {
|
|
| 574 |
return ((SpecificitiesTableLines) inputElement).getLines(); |
|
| 575 |
} |
|
| 576 |
|
|
| 577 |
@Override |
|
| 578 |
public void dispose() { }
|
|
| 579 |
|
|
| 580 |
@Override |
|
| 581 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
|
| 582 |
} |
|
| 583 |
}); |
|
| 584 |
|
|
| 585 |
this.syncExec(new Runnable() {
|
|
| 586 |
@Override |
|
| 587 |
public void run() {
|
|
| 588 |
viewer.refresh(); |
|
| 589 |
SpecificitiesTableEditor.this.firePropertyChange(EditorPart.PROP_DIRTY); |
|
| 590 |
// Draw lines |
|
| 591 |
fillDisplay(); |
|
| 592 |
sort(); |
|
| 593 |
specificitesTable.setFocus(); |
|
| 594 |
} |
|
| 595 |
}); |
|
| 596 |
|
|
| 597 |
} catch (Exception e) {
|
|
| 598 |
System.out.println("Error while computing specificities: "+e.getLocalizedMessage());
|
|
| 599 |
Log.printStackTrace(e); |
|
| 600 |
} |
|
| 601 |
return Status.OK_STATUS; |
|
| 602 |
} |
|
| 603 |
}; |
|
| 604 |
job.schedule(); |
|
| 556 | 605 |
} |
| 557 | 606 |
|
| 558 | 607 |
@Override |
| 559 | 608 |
protected void initializeFields() {
|
| 560 | 609 |
// TODO Auto-generated method stub |
| 561 |
|
|
| 610 |
|
|
| 562 | 611 |
} |
| 563 | 612 |
} |
| tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/SpecificitiesResultEditorInput.java (revision 534) | ||
|---|---|---|
| 51 | 51 |
import org.txm.rcp.editors.input.IProvidingMultiPageEditorInput; |
| 52 | 52 |
import org.txm.searchengine.cqp.corpus.Corpus; |
| 53 | 53 |
import org.txm.searchengine.cqp.corpus.Partition; |
| 54 |
import org.txm.specificities.core.functions.SpecificitesResult;
|
|
| 54 |
import org.txm.specificities.core.functions.Specificities;
|
|
| 55 | 55 |
import org.txm.specificities.rcp.messages.SpecificitiesUIMessages; |
| 56 | 56 |
import org.txm.statsengine.core.StatException; |
| 57 | 57 |
// TODO: Auto-generated Javadoc |
| ... | ... | |
| 91 | 91 |
* @param specificitiesResult the specificities result |
| 92 | 92 |
* @param subcorpus the subcorpus |
| 93 | 93 |
*/ |
| 94 |
public SpecificitiesResultEditorInput(SpecificitesResult specificitiesResult, Corpus subcorpus) {
|
|
| 94 |
public SpecificitiesResultEditorInput(Specificities specificitiesResult, Corpus subcorpus) {
|
|
| 95 | 95 |
this(specificitiesResult); |
| 96 | 96 |
this.subcorpus = subcorpus; |
| 97 | 97 |
init(); |
| ... | ... | |
| 103 | 103 |
* @param specificitiesResult the specificities result |
| 104 | 104 |
* @param partition the partition |
| 105 | 105 |
*/ |
| 106 |
public SpecificitiesResultEditorInput(SpecificitesResult specificitiesResult, Partition partition) {
|
|
| 106 |
public SpecificitiesResultEditorInput(Specificities specificitiesResult, Partition partition) {
|
|
| 107 | 107 |
this(specificitiesResult); |
| 108 | 108 |
this.partition = partition; |
| 109 | 109 |
specificitiesResult.getLexicalTable().getPartition(); |
| ... | ... | |
| 114 | 114 |
} |
| 115 | 115 |
|
| 116 | 116 |
|
| 117 |
public SpecificitiesResultEditorInput(SpecificitesResult specificitiesResult) {
|
|
Formats disponibles : Unified diff