Révision 2494

tmp/org.txm.index.rcp/src/org/txm/index/rcp/handlers/SendIndexTo.java (revision 2494)
29 29

  
30 30
import org.eclipse.core.commands.ExecutionEvent;
31 31
import org.eclipse.jface.viewers.ISelection;
32
import org.eclipse.jface.viewers.IStructuredSelection;
33 32
import org.eclipse.jface.viewers.StructuredSelection;
34 33
import org.eclipse.ui.handlers.HandlerUtil;
35 34
import org.txm.core.results.TXMResult;
36 35
import org.txm.index.core.functions.Index;
37 36
import org.txm.links.rcp.handlers.SendSelectionToQueryable;
38 37
import org.txm.rcp.editors.TXMEditor;
38
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
39 39
import org.txm.searchengine.cqp.corpus.CQPCorpus;
40 40
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
41 41

  
......
47 47
 */
48 48
public class SendIndexTo extends SendSelectionToQueryable {
49 49
	
50
	
51 50
	@Override
52 51
	public String createQuery(ExecutionEvent event, ISelection selection) {
53 52
		if (selection instanceof StructuredSelection) {
......
66 65
		return null;
67 66
	}
68 67
	
69
	
70
	
71 68
	@Override
72 69
	public TXMResult getResultParent(ExecutionEvent event) {
73
		TXMEditor editor = (TXMEditor) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
74
		return CQPCorpus.getFirstParentCorpus(editor.getResult());
70
		@SuppressWarnings("unchecked")
71
		TXMEditor<Index> editor = (TXMEditor<Index>) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
72
		
73
		TXMResult result = editor.getResult();
74
		Index index = (Index) result;
75
		CQPCorpus corpus = CQPCorpus.getFirstParentCorpus(index);
76
		if (index.getQuery() instanceof CQLQuery) {
77
			CQLQuery cqlQuery = (CQLQuery) index.getQuery();
78
			CQPCorpus subcorpus;
79
			try {
80
				subcorpus = corpus.createSubcorpus(cqlQuery, cqlQuery.getQueryString());
81
			}
82
			catch (CqiClientException e) {
83
				// TODO Auto-generated catch block
84
				e.printStackTrace();
85
				return null;
86
			}
87
			
88
			return subcorpus;
89
		}
90
		else {
91
			return null;
92
		}
75 93
	}
76
	
77
	
78
	
79 94
}
tmp/org.txm.links.rcp/src/org/txm/links/rcp/handlers/SendSelectionToQueryable.java (revision 2494)
45 45
 * 
46 46
 */
47 47
public abstract class SendSelectionToQueryable extends BaseAbstractHandler {
48

  
48
	
49 49
	/**
50 50
	 * Creates the query.
51
	 * 
51 52
	 * @param isel
52 53
	 * @return
53 54
	 */
54 55
	public abstract String createQuery(ExecutionEvent event, ISelection isel);
55
	 
56
	
56 57
	/**
57 58
	 * Creates the queries.
58 59
	 * This method is essentially dedicated to be overridden, if needed.
60
	 * 
59 61
	 * @param selection
60 62
	 * @return
61 63
	 */
......
73 75
			String query = this.createQuery(event, selection);
74 76
			String queries = this.createQueries(event, selection);
75 77
			
76
			if(query.isEmpty() && queries.isEmpty()) {
78
			if (query.isEmpty() && queries.isEmpty()) {
77 79
				Log.severe(Messages.noQueryWasSetCommandCanceled);
78 80
				return null;
79 81
			}
80 82
			
81 83
			// create a local result node in the project node, store in some parameters and call the linked command
82
			String resultParametersNodePath = this.getResultParent(event).getProject().getParametersNodeRootPath() + TXMResult.createUUID() + "_link"; // FIXME: we can't put the class name here since we does not know the target class
83
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.PARENT_PARAMETERS_NODE_PATH, this.getResultParent(event).getParametersNodePath());
84
			TXMResult result = this.getResultParent(event);
85
			String resultParametersNodePath = result.getProject().getParametersNodeRootPath() + TXMResult.createUUID() + "_link"; // FIXME: we can't put the class name here since
86
																																	 // we does not know the target class
87
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.PARENT_PARAMETERS_NODE_PATH, result.getParametersNodePath());
84 88
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.QUERY, query);
85 89
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.QUERIES, queries);
86 90
			
87 91
			BaseAbstractHandler.executeSendToCommand(event.getCommand().getId(), resultParametersNodePath);
88 92
			
89 93
		}
90
		else	{
94
		else {
91 95
			this.logCanNotExecuteCommand(selection);
92 96
		}
93 97
		return null;
94 98
	}
95
}
99
}
tmp/org.txm.links.rcp/src/org/txm/links/rcp/handlers/SendSelectionToMatchable.java (revision 2494)
48 48
 * 
49 49
 */
50 50
public abstract class SendSelectionToMatchable extends BaseAbstractHandler {
51

  
51
	
52 52
	/**
53 53
	 * Creates the queries.
54 54
	 * This method is essentially dedicated to be overridden, if needed.
55
	 * 
55 56
	 * @param selection
56 57
	 * @return
57 58
	 */
58 59
	public abstract List<Match> createMatches(ExecutionEvent event, IStructuredSelection selection);
59

  
60
	
60 61
	@Override
61 62
	public Object execute(ExecutionEvent event) throws ExecutionException {
62 63
		
......
65 66
			
66 67
			List<Match> matches = this.createMatches(event, selection);
67 68
			
68
			if(matches.isEmpty()) {
69
			if (matches.isEmpty()) {
69 70
				Log.severe(Messages.noMatchesWasSetCommandCanceled);
70 71
				return null;
71 72
			}
72 73
			
73 74
			// create a local result node in the project node, store in some parameters and call the linked command
74
			String resultParametersNodePath = this.getResultParent(event).getProject().getParametersNodeRootPath() + TXMResult.createUUID() + "_link"; // FIXME: we can't put the class name here since we does not know the target class
75
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.PARENT_PARAMETERS_NODE_PATH, this.getResultParent(event).getParametersNodePath());
75
			TXMResult result = this.getResultParent(event);
76
			if (result == null) {
77
				System.out.println("No result found with " + event);
78
				return null;
79
			}
80
			String resultParametersNodePath = result.getProject().getParametersNodeRootPath() + TXMResult.createUUID() + "_link"; // FIXME: we can't put the class name here since we does not know the
81
																																	 // target class
82
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.PARENT_PARAMETERS_NODE_PATH, result.getParametersNodePath());
76 83
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.MATCHES, matches.toString());
77 84
			
78 85
			BaseAbstractHandler.executeSendToCommand(event.getCommand().getId(), resultParametersNodePath);
79 86
		}
80
		else	{
87
		else {
81 88
			this.logCanNotExecuteCommand(selection);
82 89
		}
83 90
		return null;
84 91
	}
85

  
86
}
92
	
93
}
tmp/org.txm.index.core/src/org/txm/index/core/functions/LineComparator.java (revision 2494)
62 62
	/** The reverse. */
63 63
	boolean reverse;
64 64
	
65
	int focusedSubcorpus = 0;
66
	
65 67
	/**
66 68
	 * Instantiates a new line comparator.
67 69
	 *
68 70
	 * @param mode the mode
69 71
	 * @param reverse the reverse
70 72
	 */
71
	public LineComparator(SortMode mode, boolean reverse) {
73
	public LineComparator(SortMode mode, int focusedSubcorpus, boolean reverse) {
72 74
		setSortByFrequence(mode);
73 75
		setReverse(reverse);
76
		this.focusedSubcorpus = focusedSubcorpus;
74 77
	}
75 78
	
76 79
	/**
......
91 94
		int sort = 0;
92 95
		switch (currentsortmode) {
93 96
			case FREQUNIT:
94
				sort = arg0.getFrequency() - arg1.getFrequency();
97
				sort = arg0.getFrequency(focusedSubcorpus) - arg1.getFrequency(focusedSubcorpus);
95 98
				
96 99
				if (sort == 0)
97 100
					sort = -collator.compare(arg0.toString(), arg1.toString());
......
101 104
			case UNITFREQ:
102 105
				sort = collator.compare(arg0.toString(), arg1.toString());
103 106
				if (sort == 0)
104
					sort = arg0.getFrequency() - arg1.getFrequency();
107
					sort = arg0.getFrequency(focusedSubcorpus) - arg1.getFrequency(focusedSubcorpus);
105 108
				break;
106 109
			
107 110
			case FREQ:
108
				sort = arg0.getFrequency() - arg1.getFrequency();
111
				sort = arg0.getFrequency(focusedSubcorpus) - arg1.getFrequency(focusedSubcorpus);
109 112
				break;
110 113
			
111 114
			case UNIT:
112 115
				sort = collator.compare(arg0.toString(), arg1.toString());
113 116
				break;
114 117
		}
115
		if (reverse)
118
		
119
		if (reverse) {
116 120
			sort = -sort;
121
		}
117 122
		return sort;
118 123
	}
119 124
	
tmp/org.txm.index.core/src/org/txm/index/core/functions/PartitionIndex.java (revision 2494)
32 32
import java.io.FileOutputStream;
33 33
import java.io.IOException;
34 34
import java.io.OutputStreamWriter;
35
import java.util.ArrayList;
36
import java.util.Arrays;
37
import java.util.Collections;
38 35
import java.util.HashMap;
39
import java.util.LinkedHashMap;
40 36
import java.util.List;
41 37

  
42 38
import org.eclipse.osgi.util.NLS;
43 39
import org.rosuda.REngine.REXPMismatchException;
44 40
import org.txm.core.messages.TXMCoreMessages;
45 41
import org.txm.core.preferences.TXMPreferences;
46
import org.txm.core.results.Parameter;
47
import org.txm.core.results.TXMParameters;
48
import org.txm.core.results.TXMResult;
49 42
import org.txm.index.core.functions.LineComparator.SortMode;
50 43
import org.txm.index.core.messages.IndexCoreMessages;
51
import org.txm.index.core.preferences.IndexPreferences;
52
import org.txm.objects.Match;
53
import org.txm.searchengine.core.IQuery;
54
import org.txm.searchengine.core.Selection;
55 44
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
56 45
import org.txm.searchengine.cqp.corpus.CQPCorpus;
57 46
import org.txm.searchengine.cqp.corpus.CQPLexicon;
58
import org.txm.searchengine.cqp.corpus.CorpusManager;
59 47
import org.txm.searchengine.cqp.corpus.Part;
60 48
import org.txm.searchengine.cqp.corpus.Partition;
61 49
import org.txm.searchengine.cqp.corpus.Property;
62
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
63 50
import org.txm.searchengine.cqp.corpus.WordProperty;
64 51
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
65
import org.txm.searchengine.cqp.serverException.CqiServerError;
66 52
import org.txm.statsengine.r.core.RWorkspace;
67 53
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
68 54
import org.txm.utils.logger.Log;
......
73 59
 * @author mdecorde
74 60
 * @author sjacquot
75 61
 */
76
// FIXME: SJ: chzeck that all works well then remove the partnamtes usage
62
// FIXME: SJ: check that all works well then remove the partnames usage
77 63
public class PartitionIndex extends Index {
78 64
	
79
	
80 65
	/** The lexicon used to compute the index (if query = null || query == [] && properties.size() == 1 */
81 66
	@Deprecated
82 67
	protected CQPLexicon lexicon;
83 68
	
84
	@Deprecated
85
	protected boolean lexiconMode = false;
86
	
87
	// /**
88
	// * Partition part names.
89
	// */
90
	// protected List<String> partNames = new ArrayList<>();
91
	
92
	
93
	
94 69
	/**
95 70
	 * 
96 71
	 * @param parent
......
113 88
	 */
114 89
	public PartitionIndex(String parametersNodePath, Partition parent) {
115 90
		super(parametersNodePath, parent);
116
		//
117
		// Partition partition = getParent();
118
		// partNames.clear();
119
		// for (Part part : partition.getParts()) {
120
		// partNames.add(part.getName());
121
		// }
122 91
	}
123 92
	
124 93
	@Override
......
126 95
		return (Partition) parent;
127 96
	}
128 97
	
129
	
130
	
131 98
	@Override
132 99
	public String getComputingStartMessage() {
133 100
		return TXMCoreMessages.bind(IndexCoreMessages.indexOfP0PropertiesP1OnP2Partition, this.pQuery, WordProperty.propertiesToString(this.pProperties).replaceAll(TXMPreferences.LIST_SEPARATOR,
134 101
				", "), this.getPartition().getSimpleName()); //$NON-NLS-1$
135 102
	}
136 103
	
137
	
138
	
139
	
140 104
	@Override
141 105
	protected boolean _compute() throws Exception {
142 106
		lines.clear();
......
146 110
		nTotalTokens = 0;
147 111
		
148 112
		Partition partition = getParent();
149
		// partNames.clear();
150 113
		for (Part part : partition.getParts()) {
151 114
			scanCorpus(part);
152 115
			currentpartid++;
153
			// partNames.add(part.getName());
154 116
		}
155 117
		
156 118
		setLineCounts();
......
286 248
		return lexicon;
287 249
	}
288 250
	
289
	public boolean getLexiconMode() {
290
		return this.lexiconMode;
291
	}
292
	
293
	
294
	
295 251
	/**
296 252
	 * update the lines counts.
297 253
	 */
tmp/org.txm.index.core/src/org/txm/index/core/functions/Index.java (revision 2494)
171 171
	@Override
172 172
	protected boolean _compute() throws Exception {
173 173
		
174
		
175
		
176 174
		// reset all stored data
177 175
		if (lines != null) {
178 176
			lines.clear();
......
978 976
	 * @param reverse the reverse
979 977
	 */
980 978
	public void sortLines(LineComparator.SortMode mode, boolean reverse) {
981
		LineComparator lc = new LineComparator(mode, reverse);
979
		LineComparator lc = new LineComparator(mode, 0, reverse);
982 980
		lc.initialize(this.getCorpus());
981
		
983 982
		Collections.sort(lines, lc);
983
		
984 984
		this.pTopIndex = 0; // return to the first page
985 985
	}
986 986
	

Formats disponibles : Unified diff