Revision 2225

tmp/org.txm.searchengine.cqp.rcp/plugin.xml (revision 2225)
34 34
               optional="true">
35 35
         </commandParameter>
36 36
      </command>
37
      <command
38
            defaultHandler="org.txm.searchengine.cqp.rcp.handlers.base.Substraction"
39
            id="org.txm.searchengine.cqp.rcp.handlers.base.Substraction"
40
            name="Substraction">
41
      </command>
42
      <command
43
            defaultHandler="org.txm.searchengine.cqp.rcp.handlers.base.Union"
44
            id="org.txm.searchengine.cqp.rcp.handlers.base.Union"
45
            name="Union">
46
      </command>
47
      <command
48
            defaultHandler="org.txm.searchengine.cqp.rcp.handlers.base.Intersection"
49
            id="org.txm.searchengine.cqp.rcp.handlers.base.Intersection"
50
            name="Intersection">
51
      </command>
37 52
   </extension>
38 53
   <extension
39 54
         point="org.eclipse.ui.menus">
......
191 206
               </reference>
192 207
            </visibleWhen>
193 208
         </command>
209
         <command
210
               commandId="org.txm.searchengine.cqp.rcp.handlers.base.Substraction"
211
               label="MINUS"
212
               style="push">
213
            <visibleWhen
214
                  checkEnabled="false">
215
               <reference
216
                     definitionId="OneSubCorpusSelected">
217
               </reference>
218
            </visibleWhen>
219
         </command>
220
         <command
221
               commandId="org.txm.searchengine.cqp.rcp.handlers.base.Intersection"
222
               label="INTER"
223
               style="push">
224
            <visibleWhen
225
                  checkEnabled="false">
226
               <reference
227
                     definitionId="OneSubCorpusSelected">
228
               </reference>
229
            </visibleWhen>
230
         </command>
231
         <command
232
               commandId="org.txm.searchengine.cqp.rcp.handlers.base.Union"
233
               label="UNION"
234
               style="push">
235
            <visibleWhen
236
                  checkEnabled="false">
237
               <reference
238
                     definitionId="OneSubCorpusSelected">
239
               </reference>
240
            </visibleWhen>
241
         </command>
194 242
      </menuContribution>
195 243
      <menuContribution
196 244
            allPopups="true"
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/dialogs/SetOperationsDialog.java (revision 2225)
1
package org.txm.searchengine.cqp.rcp.dialogs;
2

  
3

  
4
import java.util.Arrays;
5
import java.util.HashMap;
6
import java.util.List;
7

  
8
import org.eclipse.jface.dialogs.Dialog;
9
import org.eclipse.jface.viewers.CellLabelProvider;
10
import org.eclipse.jface.viewers.ISelectionChangedListener;
11
import org.eclipse.jface.viewers.IStructuredSelection;
12
import org.eclipse.jface.viewers.ITreeContentProvider;
13
import org.eclipse.jface.viewers.SelectionChangedEvent;
14
import org.eclipse.jface.viewers.TreeNode;
15
import org.eclipse.jface.viewers.TreeNodeContentProvider;
16
import org.eclipse.jface.viewers.TreeViewer;
17
import org.eclipse.jface.viewers.TreeViewerColumn;
18
import org.eclipse.jface.viewers.Viewer;
19
import org.eclipse.jface.viewers.ViewerCell;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.events.SelectionListener;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridLayout;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Label;
30
import org.eclipse.swt.widgets.Shell;
31
import org.eclipse.swt.widgets.Spinner;
32
import org.eclipse.swt.widgets.Text;
33
import org.eclipse.swt.widgets.ToolBar;
34
import org.txm.core.results.TXMResult;
35
import org.txm.rcp.editors.TXMEditor;
36
import org.txm.rcp.swt.GLComposite;
37
import org.txm.rcp.swt.provider.SimpleLabelProvider;
38
import org.txm.searchengine.cqp.corpus.CQPCorpus;
39
import org.txm.searchengine.cqp.corpus.Subcorpus;
40

  
41
/**
42
 * 
43
 * 
44
 *
45
 */
46
public class SetOperationsDialog extends Dialog {
47
	
48
	private Text textField;
49
	String operation;
50
	CQPCorpus corpus[] = new CQPCorpus[2];
51
	String name;
52
//	private Label corpus1Label;
53
//	private Label corpus2Label;
54
	private String previousDefaultName;
55
private TreeViewer treeViewer;
56
//	private Label questionLabel;
57
private TreeViewerColumn nameColumn;
58
	
59
	public static HashMap<String, String> operations = new HashMap<String, String>();
60
	static {
61
		operations.put("UNION", "''{0}'' subcorpus union with...");
62
		operations.put("INTER", "''{0}'' subcorpus intersection with...");
63
		operations.put("MINUS", "''{0}'' subcorpus minus");
64
		operations.put("COMPL", "''{0}'' subcorpus complement...");
65
	}
66
	
67
	public static HashMap<String, String> symbols = new HashMap<String, String>();
68
	static {
69
		symbols.put("UNION", "{0} ∪ {1}");
70
		symbols.put("INTER", "{0} ∩ {1}");
71
		symbols.put("MINUS", "{0} - {1}");
72
		symbols.put("COMPL", "-{0}");
73
	}
74
	
75
	/**
76
	 * 
77
	 * @param parentShell
78
	 * @param title
79
	 * @param question
80
	 * @param text
81
	 */
82
	public SetOperationsDialog(Shell parentShell, String operation, CQPCorpus corpus1) {
83
		super(parentShell);
84
		this.operation = operation;
85
		this.corpus[0] = corpus1;
86
		if (this.operation.equals("COMPL")) {
87
			this.corpus[1] = corpus1.getCorpusParent();
88
		}
89
	}
90

  
91
	@Override
92
	protected void configureShell(Shell newShell) {
93
		super.configureShell(newShell);
94
		newShell.setText(NLS.bind(operations.get(operation), corpus[0].getName()));
95
		newShell.setMinimumSize(400, 200);
96
	}
97

  
98
	@Override
99
	protected Control createDialogArea(Composite parent) {
100
		Composite comp = (Composite) super.createDialogArea(parent);
101

  
102
		GridLayout layout = (GridLayout) comp.getLayout();
103
		layout.numColumns = 2;
104
		
105
		Label l = new Label(comp, SWT.LEFT);
106
		l.setText("Name");
107
		l.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
108
		
109
		textField = new Text(comp, SWT.SINGLE|SWT.BORDER);
110
		textField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
111

  
112
		treeViewer = new TreeViewer (comp, SWT.SINGLE | SWT.BORDER);
113
		if (this.operation.equals("COMPL")) {
114
			treeViewer.getTree().setEnabled(false);
115
		}
116
		treeViewer.setContentProvider(new ITreeContentProvider() {
117

  
118
			@Override
119
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { }
120

  
121
			@Override
122
			public void dispose() { }
123

  
124
			@Override
125
			public boolean hasChildren(Object element) {
126
				if (element instanceof CQPCorpus) {
127
					return ((CQPCorpus)element).getSubcorpora().size() > 0;
128
				}
129
				return false;
130
			}
131

  
132
			@Override
133
			public Object getParent(Object element) {
134
				if (element instanceof CQPCorpus) {
135
					return ((CQPCorpus)element).getParent();
136
				}
137
				return null;
138
			}
139

  
140
			@SuppressWarnings("rawtypes")
141
			@Override
142
			public Object[] getElements(Object inputElement) {
143
				if (inputElement == null) return new Object[0];
144
				
145
				if (inputElement instanceof CQPCorpus) {
146
					return ((CQPCorpus)inputElement).getSubcorpora().toArray();
147
				}
148
				return null;
149
			}
150

  
151
			@Override
152
			public Object[] getChildren(Object element) {
153
				if (element instanceof CQPCorpus) {
154
					return ((CQPCorpus)element).getSubcorpora().toArray();
155
				} 
156
				return new Object[0];
157
			}
158
		});
159

  
160
		treeViewer.getTree().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2 , 1));
161
		treeViewer.getTree().setHeaderVisible(true);
162
		treeViewer.getTree().setLinesVisible(true);
163
		treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
164
			
165
			@Override
166
			public void selectionChanged(SelectionChangedEvent event) {
167
				IStructuredSelection sel = event.getStructuredSelection();
168
				Object o = sel.getFirstElement();
169
				corpus[1] = (CQPCorpus) o;
170
				initializeWidgets();
171
			}
172
		});
173

  
174
		nameColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
175
		nameColumn.getColumn().setText("Availables Subcorpus");
176
		nameColumn.getColumn().pack();
177
		nameColumn.setLabelProvider(new CellLabelProvider() {
178
			@Override
179
			public void update(ViewerCell cell) {
180
				Object element = cell.getElement();
181

  
182
				if (element instanceof CQPCorpus) {
183
					cell.setText(((CQPCorpus)element).getName());
184
				} else {
185
					cell.setText("");
186
				}
187
			}
188
		});
189
		
190
		treeViewer.setInput(corpus[0].getMainCorpus());
191
		initializeWidgets();
192
		
193
		return comp;
194
	}
195
	
196
	@Override
197
	protected boolean isResizable() {
198
	    return true;
199
	}
200
	
201
	public void initializeWidgets() {
202
//		corpus1Label.setText(corpus[0].getName());
203
//		corpus2Label.setText(corpus[1].getName());
204
//		questionLabel.setText(NLS.bind(symbols.get(operation), corpus[0], corpus[1]));
205
		//textField.getShell().setText(NLS.bind(symbols.get(operation), corpus[0], corpus[1]));
206
		String current = textField.getText();
207
		if (current.length() == 0 || current.equals(previousDefaultName)) {
208
			textField.setText(getDefaultName());
209
		}
210
	}
211

  
212
	public String getDefaultName() {
213
		String s = "[select a subcorpus in the list]";
214
		if (corpus[1] != null) {
215
			s = corpus[1].getName();
216
		}
217
		previousDefaultName = NLS.bind(symbols.get(operation), corpus[0].getName(), s);
218
		return previousDefaultName;
219
	}
220

  
221
	@Override
222
	protected void buttonPressed(int buttonId) {
223
		if (buttonId == Dialog.OK) {
224
			name = textField.getText();
225
		}
226
		super.buttonPressed(buttonId);
227
	}
228

  
229
	public String getName() {
230
		return name;
231
	}
232

  
233
	public CQPCorpus[] getCorpusOrder() {
234
		return corpus;
235
	}
236
}
0 237

  
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/Substraction.java (revision 2225)
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:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.searchengine.cqp.rcp.handlers.base;
29

  
30
import java.util.Arrays;
31
import java.util.List;
32

  
33
import org.eclipse.core.commands.AbstractHandler;
34
import org.eclipse.core.commands.ExecutionEvent;
35
import org.eclipse.core.commands.ExecutionException;
36
import org.eclipse.core.runtime.IProgressMonitor;
37
import org.eclipse.core.runtime.IStatus;
38
import org.eclipse.core.runtime.Status;
39
import org.eclipse.jface.viewers.IStructuredSelection;
40
import org.eclipse.jface.window.Window;
41
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.ui.handlers.HandlerUtil;
44
import org.txm.rcp.JobsTimer;
45
import org.txm.rcp.messages.TXMUIMessages;
46
import org.txm.rcp.swt.dialog.TextDialog;
47
import org.txm.rcp.utils.JobHandler;
48
import org.txm.rcp.views.corpora.CorporaView;
49
import org.txm.searchengine.cqp.AbstractCqiClient;
50
import org.txm.searchengine.cqp.CQPSearchEngine;
51
import org.txm.searchengine.cqp.core.messages.CQPSearchEngineCoreMessages;
52
import org.txm.searchengine.cqp.corpus.CQPCorpus;
53
import org.txm.searchengine.cqp.corpus.Subcorpus;
54
import org.txm.searchengine.cqp.rcp.dialogs.SetOperationsDialog;
55
import org.txm.utils.logger.Log;
56

  
57
// TODO: Auto-generated Javadoc
58
/**
59
 * Command which creates a subcorpus from a Corpus @ author mdecorde.
60
 */
61
public class Substraction extends AbstractHandler {
62

  
63
	/** The selection. */
64
	private IStructuredSelection selection;
65

  
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
68
	 */
69
	@Override
70
	public Object execute(ExecutionEvent event) throws ExecutionException {
71
		
72
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
73
		if (selection == null) {
74
			System.out.println(TXMUIMessages.noSelectionForColon+HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActiveEditor());
75
			return null;
76
		}
77
		List list = selection.toList();
78
		if (list.size() == 0) {
79
			Log.info("No corpus selected");
80
			return null;
81
		} else if (list.size() != 1) {
82
			Log.info("Substraction need a selection of 1 corpus");
83
			return null;
84
		}
85
		Object firstElement = list.get(0);
86
//		Object secondElement = list.get(1);
87
		
88
		if (!(firstElement instanceof CQPCorpus)) {
89
			System.out.println(TXMUIMessages.selectionIsNotACorpusColon+firstElement);
90
			return null;
91
		}
92
		
93
//		if (!(secondElement instanceof CQPCorpus)) {
94
//			System.out.println(TXMUIMessages.selectionIsNotACorpusColon+secondElement);
95
//			return null;
96
//		}
97
		
98
		final CQPCorpus corpus = (CQPCorpus) firstElement;
99
		corpus.compute(false);
100
//		final CQPCorpus corpus2 = (CQPCorpus) secondElement;
101
//		corpus2.compute(false);
102
		
103
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
104
		final SetOperationsDialog d = new SetOperationsDialog(shell, "MINUS", corpus);
105
		int code = d.open();
106
		if (code == Window.OK) {
107
			JobHandler jobhandler = new JobHandler(NLS.bind(
108
					TXMUIMessages.creatingASubcorpusOnP0, corpus.getName())) {
109
				@Override
110
				protected IStatus run(IProgressMonitor monitor) {		
111
					this.runInit(monitor);
112
					JobsTimer.start();
113
					try {
114
						monitor.beginTask(TXMUIMessages.creatingASubcorpusInTheSearchEngine, 100);
115
						Subcorpus subcorpus = null;
116
						String name = d.getName();
117
						if (name.length() == 0) {
118
							name = d.getDefaultName();
119
						}
120
							
121
						AbstractCqiClient cqi = CQPSearchEngine.getCqiClient();
122
						
123
						String cqpid = "S"+Subcorpus.getNextSubcorpusCounter();
124
						CQPCorpus[] order = d.getCorpusOrder();
125
						order[1].compute(false);
126
						String query = cqpid+"=difference "+order[0].getQualifiedCqpId()+" "+order[1].getQualifiedCqpId()+";";
127
						System.out.println("QUERY="+query);
128
						cqi.query(query);
129
						subcorpus = corpus.getCorpusParent().createSubcorpus(name, cqpid);
130
						
131
						if (subcorpus == null) {
132
							monitor.done();
133
							System.out.println(TXMUIMessages.errorColonSubcorpusWasNotCreated);
134
							return Status.CANCEL_STATUS;
135
						}
136
						
137
						System.out.println(NLS.bind(TXMUIMessages.doneColonP0Created, subcorpus.getName()));
138
						monitor.worked(50);
139

  
140
						monitor.subTask(TXMUIMessages.refreshingCorpora);
141
						final Subcorpus subcorpus2 = subcorpus; 
142
						syncExec(new Runnable() {
143
							@Override
144
							public void run() {
145
								CorporaView.refresh();
146
								CorporaView.expand(subcorpus2.getParent());
147
							}
148
						});
149

  
150
						monitor.worked(100);
151
					} catch (ThreadDeath td) {
152
						return Status.CANCEL_STATUS;
153
					} catch (Exception e) {
154
						org.txm.utils.logger.Log.printStackTrace(e);
155
						Log.severe(e.toString());
156
						
157
						try {
158
							System.out.println(NLS.bind(CQPSearchEngineCoreMessages.lastCQPErrorColon, CQPSearchEngine.getCqiClient().getLastCQPError()));
159
						} catch (Exception e1) {
160
							System.out.println(TXMUIMessages.failedToGetLastCQPErrorColon+e1);
161
							org.txm.utils.logger.Log.printStackTrace(e1);
162
						}
163
					} finally {
164
						monitor.done();
165
						JobsTimer.stopAndPrint();
166
					}				
167
					return Status.OK_STATUS;
168
				}
169
			};
170
			jobhandler.startJob();
171
		}
172
		return null;
173
	}
174
}
0 175

  
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/Intersection.java (revision 2225)
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:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.searchengine.cqp.rcp.handlers.base;
29

  
30
import java.util.Arrays;
31
import java.util.List;
32

  
33
import org.eclipse.core.commands.AbstractHandler;
34
import org.eclipse.core.commands.ExecutionEvent;
35
import org.eclipse.core.commands.ExecutionException;
36
import org.eclipse.core.runtime.IProgressMonitor;
37
import org.eclipse.core.runtime.IStatus;
38
import org.eclipse.core.runtime.Status;
39
import org.eclipse.jface.viewers.IStructuredSelection;
40
import org.eclipse.jface.window.Window;
41
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.ui.handlers.HandlerUtil;
44
import org.txm.rcp.JobsTimer;
45
import org.txm.rcp.messages.TXMUIMessages;
46
import org.txm.rcp.swt.dialog.TextDialog;
47
import org.txm.rcp.utils.JobHandler;
48
import org.txm.rcp.views.corpora.CorporaView;
49
import org.txm.searchengine.cqp.AbstractCqiClient;
50
import org.txm.searchengine.cqp.CQPSearchEngine;
51
import org.txm.searchengine.cqp.core.messages.CQPSearchEngineCoreMessages;
52
import org.txm.searchengine.cqp.corpus.CQPCorpus;
53
import org.txm.searchengine.cqp.corpus.Subcorpus;
54
import org.txm.searchengine.cqp.rcp.dialogs.SetOperationsDialog;
55
import org.txm.utils.logger.Log;
56

  
57
// TODO: Auto-generated Javadoc
58
/**
59
 * Command which creates a subcorpus from a Corpus @ author mdecorde.
60
 */
61
public class Intersection extends AbstractHandler {
62

  
63
	/** The selection. */
64
	private IStructuredSelection selection;
65

  
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
68
	 */
69
	@Override
70
	public Object execute(ExecutionEvent event) throws ExecutionException {
71
		
72
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
73
		if (selection == null) {
74
			System.out.println(TXMUIMessages.noSelectionForColon+HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActiveEditor());
75
			return null;
76
		}
77
		List list = selection.toList();
78
		if (list.size() == 0) {
79
			Log.info("No corpus selected");
80
			return null;
81
		} else if (list.size() != 1) {
82
			Log.info("Substraction need a selection of 1 corpus");
83
			return null;
84
		}
85
		Object firstElement = list.get(0);
86
//		Object secondElement = list.get(1);
87
		
88
		if (!(firstElement instanceof CQPCorpus)) {
89
			System.out.println(TXMUIMessages.selectionIsNotACorpusColon+firstElement);
90
			return null;
91
		}
92
		
93
//		if (!(secondElement instanceof CQPCorpus)) {
94
//			System.out.println(TXMUIMessages.selectionIsNotACorpusColon+secondElement);
95
//			return null;
96
//		}
97
		
98
		final CQPCorpus corpus = (CQPCorpus) firstElement;
99
		corpus.compute(false);
100
//		final CQPCorpus corpus2 = (CQPCorpus) secondElement;
101
//		corpus2.compute(false);
102
		
103
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
104
		final SetOperationsDialog d = new SetOperationsDialog(shell, "INTER", corpus);
105
		int code = d.open();
106
		if (code == Window.OK) {
107
			JobHandler jobhandler = new JobHandler(NLS.bind(
108
					TXMUIMessages.creatingASubcorpusOnP0, corpus.getName())) {
109
				@Override
110
				protected IStatus run(IProgressMonitor monitor) {		
111
					this.runInit(monitor);
112
					JobsTimer.start();
113
					try {
114
						monitor.beginTask(TXMUIMessages.creatingASubcorpusInTheSearchEngine, 100);
115
						Subcorpus subcorpus = null;
116
						String name = d.getName();
117
						if (name.length() == 0) {
118
							name = d.getDefaultName();
119
						}
120
							
121
						AbstractCqiClient cqi = CQPSearchEngine.getCqiClient();
122
						
123
						String cqpid = "S"+Subcorpus.getNextSubcorpusCounter();
124
						CQPCorpus[] order = d.getCorpusOrder();
125
						order[1].compute(false);
126
						String query = cqpid+"=intersect "+order[0].getQualifiedCqpId()+" "+order[1].getQualifiedCqpId()+";";
127
						System.out.println("QUERY="+query);
128
						cqi.query(query);
129
						subcorpus = corpus.getCorpusParent().createSubcorpus(name, cqpid);
130
						
131
						if (subcorpus == null) {
132
							monitor.done();
133
							System.out.println(TXMUIMessages.errorColonSubcorpusWasNotCreated);
134
							return Status.CANCEL_STATUS;
135
						}
136
						
137
						System.out.println(NLS.bind(TXMUIMessages.doneColonP0Created, subcorpus.getName()));
138
						monitor.worked(50);
139

  
140
						monitor.subTask(TXMUIMessages.refreshingCorpora);
141
						final Subcorpus subcorpus2 = subcorpus; 
142
						syncExec(new Runnable() {
143
							@Override
144
							public void run() {
145
								CorporaView.refresh();
146
								CorporaView.expand(subcorpus2.getParent());
147
							}
148
						});
149

  
150
						monitor.worked(100);
151
					} catch (ThreadDeath td) {
152
						return Status.CANCEL_STATUS;
153
					} catch (Exception e) {
154
						org.txm.utils.logger.Log.printStackTrace(e);
155
						Log.severe(e.toString());
156
						
157
						try {
158
							System.out.println(NLS.bind(CQPSearchEngineCoreMessages.lastCQPErrorColon, CQPSearchEngine.getCqiClient().getLastCQPError()));
159
						} catch (Exception e1) {
160
							System.out.println(TXMUIMessages.failedToGetLastCQPErrorColon+e1);
161
							org.txm.utils.logger.Log.printStackTrace(e1);
162
						}
163
					} finally {
164
						monitor.done();
165
						JobsTimer.stopAndPrint();
166
					}				
167
					return Status.OK_STATUS;
168
				}
169
			};
170
			jobhandler.startJob();
171
		}
172
		return null;
173
	}
174
}
0 175

  
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/Union.java (revision 2225)
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:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.searchengine.cqp.rcp.handlers.base;
29

  
30
import java.util.Arrays;
31
import java.util.List;
32

  
33
import org.eclipse.core.commands.AbstractHandler;
34
import org.eclipse.core.commands.ExecutionEvent;
35
import org.eclipse.core.commands.ExecutionException;
36
import org.eclipse.core.runtime.IProgressMonitor;
37
import org.eclipse.core.runtime.IStatus;
38
import org.eclipse.core.runtime.Status;
39
import org.eclipse.jface.viewers.IStructuredSelection;
40
import org.eclipse.jface.window.Window;
41
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.ui.handlers.HandlerUtil;
44
import org.txm.rcp.JobsTimer;
45
import org.txm.rcp.messages.TXMUIMessages;
46
import org.txm.rcp.swt.dialog.TextDialog;
47
import org.txm.rcp.utils.JobHandler;
48
import org.txm.rcp.views.corpora.CorporaView;
49
import org.txm.searchengine.cqp.AbstractCqiClient;
50
import org.txm.searchengine.cqp.CQPSearchEngine;
51
import org.txm.searchengine.cqp.core.messages.CQPSearchEngineCoreMessages;
52
import org.txm.searchengine.cqp.corpus.CQPCorpus;
53
import org.txm.searchengine.cqp.corpus.Subcorpus;
54
import org.txm.searchengine.cqp.rcp.dialogs.SetOperationsDialog;
55
import org.txm.utils.logger.Log;
56

  
57
// TODO: Auto-generated Javadoc
58
/**
59
 * Command which creates a subcorpus from a Corpus @ author mdecorde.
60
 */
61
public class Union extends AbstractHandler {
62

  
63
	/** The selection. */
64
	private IStructuredSelection selection;
65

  
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
68
	 */
69
	@Override
70
	public Object execute(ExecutionEvent event) throws ExecutionException {
71
		
72
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
73
		if (selection == null) {
74
			System.out.println(TXMUIMessages.noSelectionForColon+HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActiveEditor());
75
			return null;
76
		}
77
		List list = selection.toList();
78
		if (list.size() == 0) {
79
			Log.info("No corpus selected");
80
			return null;
81
		} else if (list.size() != 1) {
82
			Log.info("Substraction need a selection of 1 corpus");
83
			return null;
84
		}
85
		Object firstElement = list.get(0);
86
//		Object secondElement = list.get(1);
87
		
88
		if (!(firstElement instanceof CQPCorpus)) {
89
			System.out.println(TXMUIMessages.selectionIsNotACorpusColon+firstElement);
90
			return null;
91
		}
92
		
93
//		if (!(secondElement instanceof CQPCorpus)) {
94
//			System.out.println(TXMUIMessages.selectionIsNotACorpusColon+secondElement);
95
//			return null;
96
//		}
97
		
98
		final CQPCorpus corpus = (CQPCorpus) firstElement;
99
		corpus.compute(false);
100
//		final CQPCorpus corpus2 = (CQPCorpus) secondElement;
101
//		corpus2.compute(false);
102
		
103
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
104
		final SetOperationsDialog d = new SetOperationsDialog(shell, "UNION", corpus);
105
		int code = d.open();
106
		if (code == Window.OK) {
107
			JobHandler jobhandler = new JobHandler(NLS.bind(
108
					TXMUIMessages.creatingASubcorpusOnP0, corpus.getName())) {
109
				@Override
110
				protected IStatus run(IProgressMonitor monitor) {		
111
					this.runInit(monitor);
112
					JobsTimer.start();
113
					try {
114
						monitor.beginTask(TXMUIMessages.creatingASubcorpusInTheSearchEngine, 100);
115
						Subcorpus subcorpus = null;
116
						String name = d.getName();
117
						if (name.length() == 0) {
118
							name = d.getDefaultName();
119
						}
120
							
121
						AbstractCqiClient cqi = CQPSearchEngine.getCqiClient();
122
						
123
						String cqpid = "S"+Subcorpus.getNextSubcorpusCounter();
124
						CQPCorpus[] order = d.getCorpusOrder();
125
						order[1].compute(false);
126
						String query = cqpid+"=join "+order[0].getQualifiedCqpId()+" "+order[1].getQualifiedCqpId()+";";
127
						System.out.println("QUERY="+query);
128
						cqi.query(query);
129
						subcorpus = corpus.getCorpusParent().createSubcorpus(name, cqpid);
130
						
131
						if (subcorpus == null) {
132
							monitor.done();
133
							System.out.println(TXMUIMessages.errorColonSubcorpusWasNotCreated);
134
							return Status.CANCEL_STATUS;
135
						}
136
						
137
						System.out.println(NLS.bind(TXMUIMessages.doneColonP0Created, subcorpus.getName()));
138
						monitor.worked(50);
139

  
140
						monitor.subTask(TXMUIMessages.refreshingCorpora);
141
						final Subcorpus subcorpus2 = subcorpus; 
142
						syncExec(new Runnable() {
143
							@Override
144
							public void run() {
145
								CorporaView.refresh();
146
								CorporaView.expand(subcorpus2.getParent());
147
							}
148
						});
149

  
150
						monitor.worked(100);
151
					} catch (ThreadDeath td) {
152
						return Status.CANCEL_STATUS;
153
					} catch (Exception e) {
154
						org.txm.utils.logger.Log.printStackTrace(e);
155
						Log.severe(e.toString());
156
						
157
						try {
158
							System.out.println(NLS.bind(CQPSearchEngineCoreMessages.lastCQPErrorColon, CQPSearchEngine.getCqiClient().getLastCQPError()));
159
						} catch (Exception e1) {
160
							System.out.println(TXMUIMessages.failedToGetLastCQPErrorColon+e1);
161
							org.txm.utils.logger.Log.printStackTrace(e1);
162
						}
163
					} finally {
164
						monitor.done();
165
						JobsTimer.stopAndPrint();
166
					}				
167
					return Status.OK_STATUS;
168
				}
169
			};
170
			jobhandler.startJob();
171
		}
172
		return null;
173
	}
174
}
0 175

  
tmp/org.txm.searchengine.cqp.core/META-INF/MANIFEST.MF (revision 2225)
1 1
Manifest-Version: 1.0
2 2
Require-Bundle: org.txm.searchengine.core;bundle-version="1.0.0";visibility:=reexport,
3 3
 org.txm.libs.cqp;bundle-version="1.0.0";visibility:=reexport
4
Export-Package: org.txm.importer.cwb,org.txm.searchengine.cqp,org.txm.
5
 searchengine.cqp.clientExceptions,org.txm.searchengine.cqp.core.funct
6
 ions.preview,org.txm.searchengine.cqp.core.functions.selection,org.tx
7
 m.searchengine.cqp.core.functions.summary,org.txm.searchengine.cqp.co
8
 re.tests,org.txm.searchengine.cqp.corpus,org.txm.searchengine.cqp.cor
9
 pus.query,org.txm.searchengine.cqp.serverException
4
Export-Package: org.txm.importer.cwb,
5
 org.txm.searchengine.cqp,
6
 org.txm.searchengine.cqp.clientExceptions,
7
 org.txm.searchengine.cqp.core.functions.preview,
8
 org.txm.searchengine.cqp.core.functions.selection,
9
 org.txm.searchengine.cqp.core.functions.summary,
10
 org.txm.searchengine.cqp.core.messages,
11
 org.txm.searchengine.cqp.core.tests,
12
 org.txm.searchengine.cqp.corpus,
13
 org.txm.searchengine.cqp.corpus.query,
14
 org.txm.searchengine.cqp.serverException
10 15
Bundle-Vendor: %Bundle-Vendor
11 16
Bundle-ClassPath: res/,.
12 17
Bundle-Version: 1.1.0.qualifier
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/CQPCorpus.java (revision 2225)
27 27
//
28 28
package org.txm.searchengine.cqp.corpus;
29 29

  
30
import java.io.File;
30 31
import java.io.IOException;
31 32
import java.util.ArrayList;
32 33
import java.util.Collection;
......
36 37
import java.util.HashSet;
37 38
import java.util.List;
38 39
import java.util.Locale;
40
import java.util.UUID;
39 41

  
40 42
import org.apache.commons.lang.StringUtils;
41 43
import org.eclipse.osgi.util.NLS;
......
220 222
	/** The corpus lexical units properties. */
221 223
	protected List<WordProperty> lexicalUnitsProperties;
222 224

  
223
	/** The size. */
225
	/** The size in token */
224 226
	protected int size = -1;
225 227

  
228
	/** The number of starting text. */
229
	protected int nbtext = -1;
230

  
231
	protected int[] textEndLimits;
232

  
233
	/** The textids. */
234
	protected HashMap<String, Integer> textids = null;
235
	
226 236
	// /**
227 237
	// * Creates a new object mapping a CQP corpus. This constructor is not
228 238
	// * intended to be used directly. Use {@link CorpusManager#getCorpus(String)}
......
1267 1277
		return symbol;
1268 1278
	}
1269 1279

  
1270
	abstract public int[] getTextEndLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException;
1280
	/**
1281
	 * 
1282
	 * @return the text_id values of the CQP corpus ordered by position
1283
	 * @throws CqiClientException
1284
	 * @throws IOException
1285
	 * @throws CqiServerError
1286
	 */
1287
	abstract public String[] getCorpusTextIdsList() throws CqiClientException, IOException, CqiServerError;
1288
	
1289
	/**
1290
	 * Gets the nb texts.
1291
	 *
1292
	 * @return the nb texts
1293
	 * @throws CqiClientException the cqi client exception
1294
	 * @throws CqiServerError 
1295
	 * @throws IOException 
1296
	 */
1297
	abstract public int getNbTexts() throws CqiClientException, IOException, CqiServerError;
1271 1298

  
1272 1299
	public StructuralUnitProperty getTextIdStructuralUnitProperty() throws CqiClientException {
1273 1300
		if (textIdStructuralUnitProperty == null) {
......
1275 1302
		}
1276 1303
		return textIdStructuralUnitProperty;
1277 1304
	}
1305
	
1306
	/**
1307
	 * Return the CQP END positions of the main corpus texts
1308
	 */
1309
	abstract public int[] getTextEndLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException;
1310
	
1311
	/**
1312
	 * Gets the texts ids and order number in corpus.
1313
	 *
1314
	 * @return the texts ids
1315
	 * @throws IOException Signals that an I/O exception has occurred.
1316
	 * @throws CqiServerError the cqi server error
1317
	 * @throws CqiClientException the cqi client exception
1318
	 */
1319
	abstract public HashMap<String, Integer>  getTextsIds() throws IOException, CqiServerError, CqiClientException;
1320

  
1321
	/**
1322
	 * Return the CQP START positions of the main corpus texts
1323
	 */
1278 1324
	abstract public int[] getTextStartLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException;
1279 1325

  
1280 1326
	public StructuralUnit getTextStructuralUnit() throws CqiClientException {
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/MainCorpus.java (revision 2225)
68 68
	protected File dataDirectory;
69 69
	protected boolean modified = false;
70 70

  
71
	/** The nbtext. */
72
	protected int nbtext = -1;
73

  
74 71
	protected File registryFile;
75
	protected int[] textEndLimits;
76

  
77
	/** The textids. */
78
	protected HashMap<String, Integer> textids = null;
79

  
72
	
80 73
	/**
81 74
	 * <del>Instantiates a new sub corpus</del>
82 75
	 * 
......
304 297
			return -1;
305 298
	}
306 299

  
307
	/**
308
	 * 
309
	 * @return the text_id values of the CQP corpus ordered by position
310
	 * @throws CqiClientException
311
	 * @throws IOException
312
	 * @throws CqiServerError
313
	 */
314
	public String[] getCorpusTextIdsList() throws CqiClientException, IOException, CqiServerError {
315

  
316
		int nbtext = getNbTexts();
317
		int[] structs = new int[nbtext];
318
		for(int i = 0 ; i < nbtext ; i++)
319
			structs[i] = i;
320

  
321
		StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
322
		StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
323

  
324
		return CorpusManager.getCorpusManager().getCqiClient().struc2Str(text_id_sup.getQualifiedName(), structs);
325
	}
326

  
327 300
	@Override
328 301
	public String getDetails() {
329 302
		try {
......
380 353
		return null;
381 354
	}
382 355

  
383
	/**
384
	 * Gets the nb texts.
385
	 *
386
	 * @return the nb texts
387
	 * @throws CqiClientException the cqi client exception
388
	 */
389
	public int getNbTexts() throws CqiClientException
390
	{
391
		if (nbtext == -1) {
392
			StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
393
			StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
394

  
395
			List<String> textids = text_id_sup.getValues();
396
			nbtext = textids.size();
397
		}
398
		return nbtext;
399
	}
400

  
401 356
	public int getNMatch() {
402 357
		return 1;
403 358
	}
......
608 563

  
609 564
		return this.structuralUnits;
610 565
	}
611
	/**
612
	 * Return the CQP END positions of the main corpus texts
613
	 */
614
	@Override
615
	public int[] getTextEndLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException {
616
		if (textEndLimits == null) {
617
			String queryResultId = queryResultNamePrefix
618
					+ UUID.randomUUID().toString();
619
			CorpusManager.getCorpusManager().getCqiClient().cqpQuery(
620
					this.getQualifiedCqpId(), queryResultId, "<text>[] expand to text"); //$NON-NLS-1$
621
			QueryResult queryResult = new QueryResult(queryResultId, queryResultId, this,	new CQLQuery("<text>[] expand to text")); //$NON-NLS-1$
622
			textEndLimits = queryResult.getEnds();
623
		}
624
		return textEndLimits;
625
	}
626 566

  
627
	/**
628
	 * Gets the texts ids.
629
	 *
630
	 * @return the texts ids
631
	 * @throws IOException Signals that an I/O exception has occurred.
632
	 * @throws CqiServerError the cqi server error
633
	 * @throws CqiClientException the cqi client exception
634
	 */
635
	public HashMap<String, Integer>  getTextsIds() throws IOException, CqiServerError, CqiClientException
636
	{
637
		if (textids == null)
638
		{
639
			textids = new HashMap<String, Integer>();
640
			int nbtext = getNbTexts();
641
			int[] structs = new int[nbtext];
642
			for(int i = 0 ; i < nbtext ; i++)
643
				structs[i] = i;
644 567

  
645
			StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
646
			StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
647

  
648
			String[] ids = CorpusManager.getCorpusManager().getCqiClient().struc2Str(text_id_sup.getQualifiedName(), structs);
649
			for(int i = 0 ; i < ids.length ; i++)
650
			{
651
				textids.put(ids[i], structs[i]);
652
			}
653
		}
654
		return textids;
655
	}
656

  
657
	/**
658
	 * Return the CQP START positions of the main corpus texts
659
	 */
660
	@Override
661
	public int[] getTextStartLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException {
662
		if (textLimits == null) {
663
			textLimits = getStartLimits("<text>[]");
664
		}
665
		return textLimits;
666
	}
667

  
668 568
	public boolean isModified() { return modified; }
669 569

  
670 570
	@Override
......
710 610
	public CorpusBuild getRootCorpusBuild() {
711 611
		return this;
712 612
	}
613

  
614
	/**
615
	 * Return the CQP START positions of the main corpus texts
616
	 */
617
	public int[] getTextStartLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException {
618
		if (textLimits == null) {
619
			textLimits = getStartLimits("<text>[]");
620
		}
621
		return textLimits;
622
	}
623
	
624
	/**
625
	 * Return the CQP END positions of the main corpus texts
626
	 */
627
	public int[] getTextEndLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException {
628
		if (textEndLimits == null) {
629
			String queryResultId = queryResultNamePrefix + UUID.randomUUID().toString();
630
			CorpusManager.getCorpusManager().getCqiClient().cqpQuery(
631
					this.getQualifiedCqpId(), queryResultId, "<text>[] expand to text"); //$NON-NLS-1$
632
			QueryResult queryResult = new QueryResult(queryResultId, queryResultId, this,	new CQLQuery("<text>[] expand to text")); //$NON-NLS-1$
633
			textEndLimits = queryResult.getEnds();
634
		}
635
		return textEndLimits;
636
	}
637
	
638
	/**
639
	 * Gets the nb texts.
640
	 *
641
	 * @return the nb texts
642
	 * @throws CqiClientException the cqi client exception
643
	 * @throws CqiServerError 
644
	 * @throws IOException 
645
	 */
646
	public int getNbTexts() throws CqiClientException, IOException, CqiServerError
647
	{
648
		if (nbtext == -1) {
649
			StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
650
			StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
651
			nbtext = CorpusManager.getCorpusManager().getCqiClient().attributeSize(text_id_sup.getQualifiedName());
652
		}
653
		return nbtext;
654
	}
655
	
656
	/**
657
	 * 
658
	 * @return the text_id values of the CQP corpus ordered by position
659
	 * @throws CqiClientException
660
	 * @throws IOException
661
	 * @throws CqiServerError
662
	 */
663
	public String[] getCorpusTextIdsList() throws CqiClientException, IOException, CqiServerError {
664

  
665
		int nbtext = getNbTexts();
666
		int[] structs = new int[nbtext];
667
		for(int i = 0 ; i < nbtext ; i++)
668
			structs[i] = i;
669

  
670
		StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
671
		StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
672

  
673
		return CorpusManager.getCorpusManager().getCqiClient().struc2Str(text_id_sup.getQualifiedName(), structs);
674
	}
675
	
676
	/**
677
	 * Gets the texts ids and order number in corpus.
678
	 *
679
	 * @return the texts ids
680
	 * @throws IOException Signals that an I/O exception has occurred.
681
	 * @throws CqiServerError the cqi server error
682
	 * @throws CqiClientException the cqi client exception
683
	 */
684
	public HashMap<String, Integer>  getTextsIds() throws IOException, CqiServerError, CqiClientException
685
	{
686
		if (textids == null) {
687
			textids = new HashMap<String, Integer>();
688
			int nbtext = getNbTexts();
689
			int[] structs = new int[nbtext];
690
			for(int i = 0 ; i < nbtext ; i++)
691
				structs[i] = i;
692

  
693
			StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
694
			StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
695

  
696
			String[] ids = CorpusManager.getCorpusManager().getCqiClient().struc2Str(text_id_sup.getQualifiedName(), structs);
697
			for(int i = 0 ; i < ids.length ; i++)
698
			{
699
				textids.put(ids[i], structs[i]);
700
			}
701
		}
702
		return textids;
703
	}
713 704
}
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Subcorpus.java (revision 2225)
30 30
import java.io.File;
31 31
import java.io.IOException;
32 32
import java.util.ArrayList;
33
import java.util.HashMap;
33 34
import java.util.List;
35
import java.util.UUID;
34 36

  
35 37
import org.eclipse.osgi.util.NLS;
36 38
import org.txm.core.messages.TXMCoreMessages;
......
443 445
		return getMainCorpus().getStructuralUnits();
444 446
	}
445 447

  
446
	@Override
447
	public int[] getTextEndLimits() throws CqiClientException, IOException,
448
	CqiServerError, InvalidCqpIdException {
449
		return this.getMainCorpus().getTextEndLimits();
450
	}
451

  
452
	@Override
453
	public int[] getTextStartLimits() throws CqiClientException, IOException,
454
	CqiServerError, InvalidCqpIdException {
455
		return this.getMainCorpus().getTextStartLimits();
456
	}
457

  
458 448
	public SelectionResult initSelectionResult(Element e) {
459 449

  
460 450
		if (e != null) {
......
605 595
	public CorpusBuild getRootCorpusBuild() {
606 596
		return getMainCorpus();
607 597
	}
598
	
599
	/**
600
	 * Return the CQP START positions of the main corpus texts
601
	 */
602
	public int[] getTextStartLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException {
603
		if (textLimits == null) {
604
			textLimits = getStartLimits("[text] expand left to text");
605
		}
606
		return textLimits;
607
	}
608
	
609
	/**
610
	 * Return the CQP END positions of the main corpus texts
611
	 */
612
	public int[] getTextEndLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException {
613
		if (textEndLimits == null) {
614
			String queryResultId = queryResultNamePrefix + UUID.randomUUID().toString();
615
			CorpusManager.getCorpusManager().getCqiClient().cqpQuery(
616
					this.getQualifiedCqpId(), queryResultId, "[text] expand right to text"); //$NON-NLS-1$
617
			QueryResult queryResult = new QueryResult(queryResultId, queryResultId, this,	new CQLQuery("[text] expand right to text")); //$NON-NLS-1$
618
			textEndLimits = queryResult.getEnds();
619
		}
620
		return textEndLimits;
621
	}
622
	
623
	/**
624
	 * Gets the nb texts.
625
	 *
626
	 * @return the nb texts
627
	 * @throws CqiClientException the cqi client exception
628
	 * @throws CqiServerError 
629
	 * @throws IOException 
630
	 */
631
	public int getNbTexts() throws CqiClientException, IOException, CqiServerError
632
	{
633
		if (nbtext == -1) {
634
			
635
			List<Integer> structsIncorpus = getTextNumberInCorpus();
636
			
637
			nbtext = structsIncorpus.size();
638
		}
639
		return nbtext;
640
	}
641

  
642
	private List<Integer> getTextNumberInCorpus() throws CqiClientException, IOException, CqiServerError {
643
		
644
		StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
645
		StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
646
		nbtext = CorpusManager.getCorpusManager().getCqiClient().attributeSize(text_id_sup.getQualifiedName());
647
		
648
		int[] structs = new int[nbtext];
649
		int[][] structs_positions = new int[structs.length][2];
650
		for (int i = 0 ; i < nbtext ; i++) {
651
			structs[i] = i;
652
			structs_positions[i] = CorpusManager.getCorpusManager().getCqiClient().struc2Cpos(text_id_sup.getQualifiedName(), i);
653
		}
654
		
655
		List<Integer> structsIncorpus = new ArrayList<Integer>();
656
		//filter structs with matches
657
		List<Match> matches = this.getMatches();
658
		int iText = 0;
659
		int iMatch = 0;
660
		nbtext = 0;
661
		while (iText < structs.length && iMatch < matches.size()) {
662
			if (structs_positions[iText][1] < matches.get(iMatch).getStart()) { // match before text
663
				iText++;
664
			} else if (matches.get(iMatch).getEnd() < structs_positions[iText][0]) { // text before match
665
				iMatch++;
666
			} else { // a match in the text
667
				structsIncorpus.add(iText);
668
				iText++;
669
			}
670
		}
671
		return structsIncorpus;
672
	}
673
	
674
	/**
675
	 * 
676
	 * @return the text_id values of the CQP corpus ordered by position
677
	 * @throws CqiClientException
678
	 * @throws IOException
679
	 * @throws CqiServerError
680
	 */
681
	public String[] getCorpusTextIdsList() throws CqiClientException, IOException, CqiServerError {
682

  
683
		StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
684
		StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
685
		
686
		List<Integer> list = getTextNumberInCorpus();
687
		int[] structs = new int[list.size()];
688
		for (int i = 0 ; i < list.size() ; i++) {
689
			structs[i] = list.get(i);
690
		}
691

  
692
		return CorpusManager.getCorpusManager().getCqiClient().struc2Str(text_id_sup.getQualifiedName(), structs);
693
	}
694
	
695
	/**
696
	 * Gets the texts ids and order number in corpus.
697
	 *
698
	 * @return the texts ids
699
	 * @throws IOException Signals that an I/O exception has occurred.
700
	 * @throws CqiServerError the cqi server error
701
	 * @throws CqiClientException the cqi client exception
702
	 */
703
	public HashMap<String, Integer>  getTextsIds() throws IOException, CqiServerError, CqiClientException
704
	{
705
		if (textids == null) {
706
			textids = new HashMap<String, Integer>();
707
			List<Integer> list = getTextNumberInCorpus();
708
			int[] structs = new int[list.size()];
709
			for (int i = 0 ; i < list.size() ; i++) {
710
				structs[i] = list.get(i);
711
			}
712

  
713
			StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
714
			StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
715

  
716
			String[] ids = CorpusManager.getCorpusManager().getCqiClient().struc2Str(text_id_sup.getQualifiedName(), structs);
717
			for(int i = 0 ; i < ids.length ; i++) {
718
				textids.put(ids[i], structs[i]);
719
			}
720
		}
721
		return textids;
722
	}
608 723
}

Also available in: Unified diff