Révision 466
| tmp/org.txm.queryindex.rcp/TODO.txt (revision 466) | ||
|---|---|---|
| 1 |
- link to LexicalTable |
|
| 2 |
- link to Matrice MotsxMots |
|
| 3 |
- link to WordCloud |
|
| 4 |
- Adapter : |
|
| 5 |
getAdapter |
|
| 6 |
create Adapter |
|
| 7 |
declare Adapter in plugin.xml |
|
| 8 |
- CorporaView : |
|
| 9 |
status line |
|
| 10 |
open result |
|
| 11 |
- Delete Object |
|
| 12 |
implémenter Function devrait suffire |
|
| 13 |
- LexicalTableImpl : createLexicalImpl |
|
| 14 |
- Command : ComputeQueryIndex |
|
| 15 |
- Editor |
|
| 16 |
- Editor input |
|
| 17 |
- WordCloud : constructeur |
|
| 18 |
- WordCloud editor : init |
|
| 0 | 19 | |
| tmp/org.txm.queryindex.rcp/.project (revision 466) | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
| 2 |
<projectDescription> |
|
| 3 |
<name>QueryIndexRCP</name> |
|
| 4 |
<comment></comment> |
|
| 5 |
<projects> |
|
| 6 |
</projects> |
|
| 7 |
<buildSpec> |
|
| 8 |
<buildCommand> |
|
| 9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
| 10 |
<arguments> |
|
| 11 |
</arguments> |
|
| 12 |
</buildCommand> |
|
| 13 |
<buildCommand> |
|
| 14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
| 15 |
<arguments> |
|
| 16 |
</arguments> |
|
| 17 |
</buildCommand> |
|
| 18 |
<buildCommand> |
|
| 19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
| 20 |
<arguments> |
|
| 21 |
</arguments> |
|
| 22 |
</buildCommand> |
|
| 23 |
</buildSpec> |
|
| 24 |
<natures> |
|
| 25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
| 26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
| 27 |
</natures> |
|
| 28 |
</projectDescription> |
|
| 0 | 29 | |
| tmp/org.txm.queryindex.rcp/src/queryindexrcp/Activator.java (revision 466) | ||
|---|---|---|
| 1 |
package queryindexrcp; |
|
| 2 |
|
|
| 3 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
| 4 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
| 5 |
import org.osgi.framework.BundleContext; |
|
| 6 |
|
|
| 7 |
/** |
|
| 8 |
* The activator class controls the plug-in life cycle |
|
| 9 |
*/ |
|
| 10 |
public class Activator extends AbstractUIPlugin {
|
|
| 11 |
|
|
| 12 |
// The plug-in ID |
|
| 13 |
public static final String PLUGIN_ID = "QueryIndexRCP"; //$NON-NLS-1$ |
|
| 14 |
|
|
| 15 |
// The shared instance |
|
| 16 |
private static Activator plugin; |
|
| 17 |
|
|
| 18 |
/** |
|
| 19 |
* The constructor |
|
| 20 |
*/ |
|
| 21 |
public Activator() {
|
|
| 22 |
} |
|
| 23 |
|
|
| 24 |
/* |
|
| 25 |
* (non-Javadoc) |
|
| 26 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
|
| 27 |
*/ |
|
| 28 |
public void start(BundleContext context) throws Exception {
|
|
| 29 |
super.start(context); |
|
| 30 |
plugin = this; |
|
| 31 |
} |
|
| 32 |
|
|
| 33 |
/* |
|
| 34 |
* (non-Javadoc) |
|
| 35 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
|
| 36 |
*/ |
|
| 37 |
public void stop(BundleContext context) throws Exception {
|
|
| 38 |
plugin = null; |
|
| 39 |
super.stop(context); |
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
/** |
|
| 43 |
* Returns the shared instance |
|
| 44 |
* |
|
| 45 |
* @return the shared instance |
|
| 46 |
*/ |
|
| 47 |
public static Activator getDefault() {
|
|
| 48 |
return plugin; |
|
| 49 |
} |
|
| 50 |
|
|
| 51 |
/** |
|
| 52 |
* Returns an image descriptor for the image file at the given |
|
| 53 |
* plug-in relative path |
|
| 54 |
* |
|
| 55 |
* @param path the path |
|
| 56 |
* @return the image descriptor |
|
| 57 |
*/ |
|
| 58 |
public static ImageDescriptor getImageDescriptor(String path) {
|
|
| 59 |
return imageDescriptorFromPlugin(PLUGIN_ID, path); |
|
| 60 |
} |
|
| 61 |
} |
|
| 0 | 62 | |
| tmp/org.txm.queryindex.rcp/src/queryindexrcp/actions/SampleAction.java (revision 466) | ||
|---|---|---|
| 1 |
package queryindexrcp.actions; |
|
| 2 |
|
|
| 3 |
import org.eclipse.jface.action.IAction; |
|
| 4 |
import org.eclipse.jface.viewers.ISelection; |
|
| 5 |
import org.eclipse.ui.IWorkbenchWindow; |
|
| 6 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
|
| 7 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
| 8 |
|
|
| 9 |
/** |
|
| 10 |
* Our sample action implements workbench action delegate. |
|
| 11 |
* The action proxy will be created by the workbench and |
|
| 12 |
* shown in the UI. When the user tries to use the action, |
|
| 13 |
* this delegate will be created and execution will be |
|
| 14 |
* delegated to it. |
|
| 15 |
* @see IWorkbenchWindowActionDelegate |
|
| 16 |
*/ |
|
| 17 |
public class SampleAction implements IWorkbenchWindowActionDelegate {
|
|
| 18 |
private IWorkbenchWindow window; |
|
| 19 |
/** |
|
| 20 |
* The constructor. |
|
| 21 |
*/ |
|
| 22 |
public SampleAction() {
|
|
| 23 |
} |
|
| 24 |
|
|
| 25 |
/** |
|
| 26 |
* The action has been activated. The argument of the |
|
| 27 |
* method represents the 'real' action sitting |
|
| 28 |
* in the workbench UI. |
|
| 29 |
* @see IWorkbenchWindowActionDelegate#run |
|
| 30 |
*/ |
|
| 31 |
public void run(IAction action) {
|
|
| 32 |
MessageDialog.openInformation( |
|
| 33 |
window.getShell(), |
|
| 34 |
"QueryIndexRCP", |
|
| 35 |
"Hello, Eclipse world"); |
|
| 36 |
} |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* Selection in the workbench has been changed. We |
|
| 40 |
* can change the state of the 'real' action here |
|
| 41 |
* if we want, but this can only happen after |
|
| 42 |
* the delegate has been created. |
|
| 43 |
* @see IWorkbenchWindowActionDelegate#selectionChanged |
|
| 44 |
*/ |
|
| 45 |
public void selectionChanged(IAction action, ISelection selection) {
|
|
| 46 |
} |
|
| 47 |
|
|
| 48 |
/** |
|
| 49 |
* We can use this method to dispose of any system |
|
| 50 |
* resources we previously allocated. |
|
| 51 |
* @see IWorkbenchWindowActionDelegate#dispose |
|
| 52 |
*/ |
|
| 53 |
public void dispose() {
|
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/** |
|
| 57 |
* We will cache window object in order to |
|
| 58 |
* be able to provide parent shell for the message dialog. |
|
| 59 |
* @see IWorkbenchWindowActionDelegate#init |
|
| 60 |
*/ |
|
| 61 |
public void init(IWorkbenchWindow window) {
|
|
| 62 |
this.window = window; |
|
| 63 |
} |
|
| 64 |
} |
|
| 0 | 65 | |
| tmp/org.txm.queryindex.rcp/src/queryindexrcp/adapters/AdapterFactory.java (revision 466) | ||
|---|---|---|
| 1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
| 2 |
package queryindexrcp.adapters; |
|
| 3 |
|
|
| 4 |
import org.eclipse.core.runtime.IAdapterFactory; |
|
| 5 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
| 6 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
|
| 7 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
| 8 |
import org.txm.functions.queryindex.QueryIndex; |
|
| 9 |
import org.txm.rcp.Application; |
|
| 10 |
import org.txm.rcp.IImageKeys; |
|
| 11 |
|
|
| 12 |
/** |
|
| 13 |
* A factory for creating Adapter objects. |
|
| 14 |
* |
|
| 15 |
* @author mdecorde |
|
| 16 |
*/ |
|
| 17 |
public class AdapterFactory implements IAdapterFactory {
|
|
| 18 |
|
|
| 19 |
/** The Index adapter. */ |
|
| 20 |
private IWorkbenchAdapter QueryIndexAdapter = new IWorkbenchAdapter() {
|
|
| 21 |
|
|
| 22 |
@Override |
|
| 23 |
public Object[] getChildren(Object o) {
|
|
| 24 |
return new Object[0]; |
|
| 25 |
} |
|
| 26 |
|
|
| 27 |
@Override |
|
| 28 |
public ImageDescriptor getImageDescriptor(Object object) {
|
|
| 29 |
return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
| 30 |
Application.PLUGIN_ID, IImageKeys.QUERYINDEX); |
|
| 31 |
} |
|
| 32 |
|
|
| 33 |
@Override |
|
| 34 |
public String getLabel(Object o) {
|
|
| 35 |
return ((QueryIndex) o).getName(); |
|
| 36 |
} |
|
| 37 |
|
|
| 38 |
@Override |
|
| 39 |
public Object getParent(Object o) {
|
|
| 40 |
return ((QueryIndex) o).getCorpus(); |
|
| 41 |
} |
|
| 42 |
}; |
|
| 43 |
|
|
| 44 |
/** |
|
| 45 |
* Gets the adapter. |
|
| 46 |
* |
|
| 47 |
* @param adaptableObject the adaptable object |
|
| 48 |
* @param adapterType the adapter type |
|
| 49 |
* @return the adapter |
|
| 50 |
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, |
|
| 51 |
* java.lang.Class) |
|
| 52 |
*/ |
|
| 53 |
@Override |
|
| 54 |
public Object getAdapter(Object adaptableObject, Class adapterType) {
|
|
| 55 |
if (adapterType == IWorkbenchAdapter.class |
|
| 56 |
&& adaptableObject instanceof QueryIndex) |
|
| 57 |
return QueryIndexAdapter; |
|
| 58 |
return null; |
|
| 59 |
} |
|
| 60 |
|
|
| 61 |
/** |
|
| 62 |
* Gets the adapter list. |
|
| 63 |
* |
|
| 64 |
* @return the adapter list |
|
| 65 |
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() |
|
| 66 |
*/ |
|
| 67 |
@Override |
|
| 68 |
@SuppressWarnings("unchecked") //$NON-NLS-1$
|
|
| 69 |
public Class[] getAdapterList() {
|
|
| 70 |
return new Class[] { IWorkbenchAdapter.class };
|
|
| 71 |
} |
|
| 72 |
|
|
| 73 |
} |
|
| 0 | 74 | |
| tmp/org.txm.queryindex.rcp/src/org/txm/functions/queryindex/QueryIndex.java (revision 466) | ||
|---|---|---|
| 1 |
package org.txm.functions.queryindex; |
|
| 2 |
|
|
| 3 |
import java.io.BufferedReader; |
|
| 4 |
import java.io.File; |
|
| 5 |
import java.io.FileInputStream; |
|
| 6 |
import java.io.FileOutputStream; |
|
| 7 |
import java.io.IOException; |
|
| 8 |
import java.io.InputStreamReader; |
|
| 9 |
import java.io.OutputStreamWriter; |
|
| 10 |
import java.util.ArrayList; |
|
| 11 |
import java.util.Arrays; |
|
| 12 |
import java.util.Collection; |
|
| 13 |
import java.util.Collections; |
|
| 14 |
import java.util.Comparator; |
|
| 15 |
import java.util.LinkedHashMap; |
|
| 16 |
import java.util.List; |
|
| 17 |
import java.util.Map; |
|
| 18 |
|
|
| 19 |
import org.eclipse.core.runtime.IAdaptable; |
|
| 20 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
| 21 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
|
| 22 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
| 23 |
import org.txm.core.messages.TXMCoreMessages; |
|
| 24 |
import org.txm.core.results.TXMResult; |
|
| 25 |
import org.txm.index.core.functions.LineComparator.SortMode; |
|
| 26 |
import org.txm.index.core.messages.IndexCoreMessages; |
|
| 27 |
import org.txm.lexicaltable.core.functions.LexicalTable; |
|
| 28 |
import org.txm.lexicaltable.core.statsengine.r.data.LexicalTableImpl; |
|
| 29 |
import org.txm.rcp.IImageKeys; |
|
| 30 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
| 31 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
| 32 |
import org.txm.searchengine.cqp.corpus.Part; |
|
| 33 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
| 34 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
| 35 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
| 36 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
|
| 37 |
import org.txm.utils.logger.Log; |
|
| 38 |
|
|
| 39 |
public class QueryIndex extends TXMResult implements IAdaptable {
|
|
| 40 |
Corpus corpus; |
|
| 41 |
Partition partition; |
|
| 42 |
|
|
| 43 |
LinkedHashMap<String, QueryIndexLine> lines = new LinkedHashMap<String, QueryIndexLine>(); |
|
| 44 |
List<String> partnames; |
|
| 45 |
// private int FilterFmin; |
|
| 46 |
// private int FilterFmax; |
|
| 47 |
// private int FilterVmax; |
|
| 48 |
|
|
| 49 |
// public int getFilterFmin() {
|
|
| 50 |
// return FilterFmin; |
|
| 51 |
// } |
|
| 52 |
// |
|
| 53 |
// public int getFilterFmax() {
|
|
| 54 |
// return FilterFmax; |
|
| 55 |
// } |
|
| 56 |
// |
|
| 57 |
// public int getFilterVmax() {
|
|
| 58 |
// return FilterVmax; |
|
| 59 |
// } |
|
| 60 |
|
|
| 61 |
/** The writer. */ |
|
| 62 |
private OutputStreamWriter writer; |
|
| 63 |
|
|
| 64 |
public int getT() {
|
|
| 65 |
int t = 0; |
|
| 66 |
for (QueryIndexLine line : lines.values()) {
|
|
| 67 |
t += line.getFrequency(); |
|
| 68 |
} |
|
| 69 |
return t; |
|
| 70 |
} |
|
| 71 |
|
|
| 72 |
public int getFmin() {
|
|
| 73 |
int t = 999999999; |
|
| 74 |
for (QueryIndexLine line : lines.values()) {
|
|
| 75 |
int f = line.getFrequency(); |
|
| 76 |
if (f < t) t = f; |
|
| 77 |
} |
|
| 78 |
return t; |
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
public int getFmax() {
|
|
| 82 |
int t = 0; |
|
| 83 |
for (QueryIndexLine line : lines.values()) {
|
|
| 84 |
int f = line.getFrequency(); |
|
| 85 |
if (f > t) t = f; |
|
| 86 |
} |
|
| 87 |
return t; |
|
| 88 |
} |
|
| 89 |
|
|
| 90 |
public int getV() {
|
|
| 91 |
return lines.values().size(); |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
public QueryIndex(Corpus corpus) {
|
|
| 95 |
this.corpus = corpus; |
|
| 96 |
partnames = Arrays.asList(corpus.getName()); |
|
| 97 |
} |
|
| 98 |
|
|
| 99 |
public String getName() {
|
|
| 100 |
if (partition != null) |
|
| 101 |
return partition.getName(); |
|
| 102 |
return corpus.getName(); |
|
| 103 |
} |
|
| 104 |
|
|
| 105 |
public TXMResult getParent() {
|
|
| 106 |
if (partition != null) return partition; |
|
| 107 |
return corpus; |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
public QueryIndex(Partition partition) {
|
|
| 111 |
this.corpus = partition.getCorpus(); |
|
| 112 |
this.partition = partition; |
|
| 113 |
partnames = partition.getPartNames(); |
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
public Corpus getCorpus() {
|
|
| 117 |
return corpus; |
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
public Partition getPartition() {
|
|
| 121 |
return partition; |
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
public Collection<QueryIndexLine> getLines() {
|
|
| 125 |
return lines.values(); |
|
| 126 |
} |
|
| 127 |
|
|
| 128 |
public LinkedHashMap<String, QueryIndexLine> getLinesHash() {
|
|
| 129 |
return lines; |
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
// public void filterLines(int fmin, int fmax) {
|
|
| 133 |
// System.out.println("filter lines fmin="+fmin +" fmax="+fmax );
|
|
| 134 |
// this.FilterFmin = fmin; |
|
| 135 |
// this.FilterFmax = fmax; |
|
| 136 |
// } |
|
| 137 |
int multi = 1; |
|
| 138 |
public void sortLines(SortMode mode, boolean revert) {
|
|
| 139 |
|
|
| 140 |
multi = 1; |
|
| 141 |
if (revert) multi = -1; |
|
| 142 |
List<Map.Entry<String, QueryIndexLine>> entries = |
|
| 143 |
new ArrayList<Map.Entry<String, QueryIndexLine>>(lines.entrySet()); |
|
| 144 |
|
|
| 145 |
if (mode == SortMode.FREQUNIT) {
|
|
| 146 |
Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() {
|
|
| 147 |
public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b){
|
|
| 148 |
int ret = multi * (a.getValue().getFrequency() - b.getValue().getFrequency()); |
|
| 149 |
if (ret == 0) {
|
|
| 150 |
return multi * a.getValue().getName().compareTo(b.getValue().getName()); |
|
| 151 |
} |
|
| 152 |
return ret; |
|
| 153 |
} |
|
| 154 |
}); |
|
| 155 |
} else if (mode == SortMode.FREQ) {
|
|
| 156 |
Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() {
|
|
| 157 |
public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b){
|
|
| 158 |
return multi * (a.getValue().getFrequency() - b.getValue().getFrequency()); |
|
| 159 |
} |
|
| 160 |
}); |
|
| 161 |
} else if (mode == SortMode.UNIT) {
|
|
| 162 |
Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() {
|
|
| 163 |
public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b){
|
|
| 164 |
return multi * a.getValue().getName().compareTo(b.getValue().getName()); |
|
| 165 |
} |
|
| 166 |
}); |
|
| 167 |
} else if (mode == SortMode.UNITFREQ) {
|
|
| 168 |
Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() {
|
|
| 169 |
public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b){
|
|
| 170 |
int ret = multi * a.getValue().getName().compareTo(b.getValue().getName()); |
|
| 171 |
if (ret == 0) {
|
|
| 172 |
return multi * (a.getValue().getFrequency() - b.getValue().getFrequency()); |
|
| 173 |
} |
|
| 174 |
return ret; |
|
| 175 |
} |
|
| 176 |
}); |
|
| 177 |
} |
|
| 178 |
|
|
| 179 |
LinkedHashMap<String, QueryIndexLine> sortedMap = new LinkedHashMap<String, QueryIndexLine>(); |
|
| 180 |
for (Map.Entry<String, QueryIndexLine> entry : entries) {
|
|
| 181 |
sortedMap.put(entry.getKey(), entry.getValue()); |
|
| 182 |
} |
|
| 183 |
|
|
| 184 |
lines = sortedMap; |
|
| 185 |
} |
|
| 186 |
|
|
| 187 |
// public void cut(int vmax) {
|
|
| 188 |
// System.out.println("TODO cut tmax="+vmax );
|
|
| 189 |
// this.FilterVmax = vmax; |
|
| 190 |
// } |
|
| 191 |
|
|
| 192 |
public boolean isComputedWithPartition() {
|
|
| 193 |
return partition != null; |
|
| 194 |
} |
|
| 195 |
|
|
| 196 |
public void addLinesFromFile(File propFile) throws CqiClientException, IOException {
|
|
| 197 |
BufferedReader reader = new BufferedReader(new InputStreamReader( |
|
| 198 |
new FileInputStream(propFile), "UTF-8")); //$NON-NLS-1$ |
|
| 199 |
|
|
| 200 |
String line = reader.readLine(); |
|
| 201 |
while (line != null) {
|
|
| 202 |
String[] split = line.split("=", 2); //$NON-NLS-1$
|
|
| 203 |
if (split.length == 2) {
|
|
| 204 |
if (hasLine(split[0])) {
|
|
| 205 |
System.out.println(TXMCoreMessages.QueryIndex_2+line); |
|
| 206 |
} else {
|
|
| 207 |
if (addLine(split[0], new Query(split[1])) == null) {
|
|
| 208 |
System.out.println(TXMCoreMessages.QueryIndex_3+line); |
|
| 209 |
} |
|
| 210 |
} |
|
| 211 |
} |
|
| 212 |
line = reader.readLine(); |
|
| 213 |
} |
|
| 214 |
reader.close(); |
|
| 215 |
} |
|
| 216 |
|
|
| 217 |
/** |
|
| 218 |
* Write all the lines on a writer. |
|
| 219 |
* |
|
| 220 |
* @param outfile the outfile |
|
| 221 |
* @param encoding the encoding |
|
| 222 |
* @param colseparator the colseparator |
|
| 223 |
* @param txtseparator the txtseparator |
|
| 224 |
* @return true, if successful |
|
| 225 |
*/ |
|
| 226 |
public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) {
|
|
| 227 |
try {
|
|
| 228 |
toTxt(outfile, 0, lines.size(), encoding, colseparator, txtseparator); |
|
| 229 |
} catch (Exception e) {
|
|
| 230 |
System.err.println(IndexCoreMessages.Index_7 + Log.toString(e)); |
|
| 231 |
return false; |
|
| 232 |
} |
|
| 233 |
return true; |
|
| 234 |
} |
|
| 235 |
|
|
| 236 |
/** |
|
| 237 |
* Write the lines between from and to on a writer. |
|
| 238 |
* |
|
| 239 |
* @param outfile the outfile |
|
| 240 |
* @param from The first line to be written |
|
| 241 |
* @param to The last line to be writen |
|
| 242 |
* @param encoding the encoding |
|
| 243 |
* @param colseparator the colseparator |
|
| 244 |
* @param txtseparator the txtseparator |
|
| 245 |
* @throws CqiClientException the cqi client exception |
|
| 246 |
* @throws IOException Signals that an I/O exception has occurred. |
|
| 247 |
*/ |
|
| 248 |
public void toTxt(File outfile, int from, int to, String encoding, String colseparator, String txtseparator) |
|
| 249 |
throws CqiClientException, IOException {
|
|
| 250 |
// NK: writer declared as class attribute to perform a clean if the operation is interrupted |
|
| 251 |
this.writer = new OutputStreamWriter(new FileOutputStream(outfile), |
|
| 252 |
encoding); |
|
| 253 |
String header = "Queries"; //$NON-NLS-1$ |
|
| 254 |
header = txtseparator+ header.substring(0, header.length() - 1) +txtseparator; |
|
| 255 |
header += colseparator+ txtseparator+ "F" + txtseparator; //$NON-NLS-1$ |
|
| 256 |
|
|
| 257 |
if (partnames.size() > 1) |
|
| 258 |
for (int j = 0; j < partnames.size(); j++) |
|
| 259 |
header += colseparator + txtseparator+ partnames.get(j).replace(txtseparator, txtseparator+txtseparator)+txtseparator; |
|
| 260 |
header += "\n"; //$NON-NLS-1$ |
|
| 261 |
writer.write(header); |
|
| 262 |
|
|
| 263 |
// for(Line ligne: lines) |
|
| 264 |
for (String name : lines.keySet()) {
|
|
| 265 |
QueryIndexLine ligne = lines.get(name); |
|
| 266 |
writer.write(txtseparator+ ligne.getName().replace(txtseparator, txtseparator+txtseparator)+ txtseparator + colseparator + ligne.getFrequency()); |
|
| 267 |
if (partnames.size() > 1) |
|
| 268 |
for (int j = 0; j < partnames.size(); j++) |
|
| 269 |
writer.write(colseparator + ligne.getFrequency(j)); |
|
| 270 |
writer.write("\n"); //$NON-NLS-1$
|
|
| 271 |
} |
|
| 272 |
writer.flush(); |
|
| 273 |
writer.close(); |
|
| 274 |
} |
|
| 275 |
|
|
| 276 |
public List<String> getPartnames() {
|
|
| 277 |
return partnames; |
|
| 278 |
} |
|
| 279 |
|
|
| 280 |
public QueryIndexLine addLine(String name, Query query) throws CqiClientException {
|
|
| 281 |
if (lines.containsKey(name)) return null; |
|
| 282 |
QueryResult[] qresults; |
|
| 283 |
if (partition != null) {
|
|
| 284 |
qresults = new QueryResult[partition.getNPart()]; |
|
| 285 |
List<Part> parts = partition.getParts(); |
|
| 286 |
for (int i = 0 ; i < parts.size() ; i++) {
|
|
| 287 |
qresults[i] = parts.get(i).query(query, "tmp", true); //$NON-NLS-1$ |
|
| 288 |
//qresults[i].drop(); // free mem done later |
|
| 289 |
} |
|
| 290 |
} else {
|
|
| 291 |
qresults = new QueryResult[1]; |
|
| 292 |
qresults[0] = corpus.query(query, "tmp", true); //$NON-NLS-1$ |
|
| 293 |
//qresults[0].drop(); // free mem done later |
|
| 294 |
} |
|
| 295 |
|
|
| 296 |
QueryIndexLine line = new QueryIndexLine(name, query, qresults); |
|
| 297 |
lines.put(name, line); |
|
| 298 |
return line; |
|
| 299 |
} |
|
| 300 |
|
|
| 301 |
public LexicalTable toLexicalTable() {
|
|
| 302 |
if (partition == null) return null; |
|
| 303 |
|
|
| 304 |
int npart = partition.getNPart(); |
|
| 305 |
int[][] freqs = new int[lines.size()][npart]; |
|
| 306 |
String[] rownames = new String[lines.size()]; |
|
| 307 |
String[] colnames = new String[npart]; |
|
| 308 |
|
|
| 309 |
int i = 0; |
|
| 310 |
for (String key : lines.keySet()) {
|
|
| 311 |
|
|
| 312 |
QueryIndexLine line = lines.get(key); |
|
| 313 |
int[] linefreqs = line.getFreqs(); |
|
| 314 |
rownames[i] = line.getName(); |
|
| 315 |
for (int j = 0 ; j < npart ; j++) {
|
|
| 316 |
freqs[i][j] = linefreqs[j]; |
|
| 317 |
} |
|
| 318 |
i++; |
|
| 319 |
} |
|
| 320 |
List<Part> parts = partition.getParts(); |
|
| 321 |
for (int j = 0 ; j < npart ; j++) {
|
|
| 322 |
colnames[j] = parts.get(j).getName(); |
|
| 323 |
} |
|
| 324 |
|
|
| 325 |
try {
|
|
| 326 |
LexicalTableImpl lt = new LexicalTableImpl(freqs, rownames, colnames); |
|
| 327 |
LexicalTable table = new LexicalTable(partition, partition.getProperty(), 1, lt); |
|
| 328 |
return table; |
|
| 329 |
} catch (Exception e) {
|
|
| 330 |
Log.printStackTrace(e); |
|
| 331 |
} |
|
| 332 |
return null; |
|
| 333 |
} |
|
| 334 |
|
|
| 335 |
public boolean removeLine(String name) {
|
|
| 336 |
if (lines.containsKey(name)) {
|
|
| 337 |
lines.remove(name); |
|
| 338 |
return true; |
|
| 339 |
} else {
|
|
| 340 |
return false; |
|
| 341 |
} |
|
| 342 |
} |
|
| 343 |
|
|
| 344 |
public boolean hasLine(String name) {
|
|
| 345 |
return lines.containsKey(name); |
|
| 346 |
} |
|
| 347 |
|
|
| 348 |
public ArrayList<QueryIndexLine> getLines(int from, int to) {
|
|
| 349 |
if (lines.size() == 0) return new ArrayList<QueryIndexLine>(); |
|
| 350 |
|
|
| 351 |
if (from < 0) from = 0; |
|
| 352 |
if (to < 0) to = 0; |
|
| 353 |
if (to > lines.size()) to = lines.size(); |
|
| 354 |
if (from > to) from = to - 1; |
|
| 355 |
ArrayList<QueryIndexLine> tmp = new ArrayList<QueryIndexLine>(); |
|
| 356 |
int i = 0; |
|
| 357 |
for (QueryIndexLine line : lines.values()) {
|
|
| 358 |
if (i >= from && i < to) {
|
|
| 359 |
tmp.add(line); |
|
| 360 |
} |
|
| 361 |
i++; |
|
| 362 |
} |
|
| 363 |
|
|
| 364 |
return tmp; |
|
| 365 |
} |
|
| 366 |
|
|
| 367 |
@Override |
|
| 368 |
public void clean() {
|
|
| 369 |
try {
|
|
| 370 |
this.writer.flush(); |
|
| 371 |
this.writer.close(); |
|
| 372 |
} catch (IOException e) {
|
|
| 373 |
Log.printStackTrace(e); |
|
| 374 |
} |
|
| 375 |
} |
|
| 376 |
|
|
| 377 |
@Override |
|
| 378 |
public Object getAdapter(Class adapterType) {
|
|
| 379 |
if (adapterType == IWorkbenchAdapter.class) |
|
| 380 |
return queryindexAdapter; |
|
| 381 |
return null; |
|
| 382 |
} |
|
| 383 |
|
|
| 384 |
/** The QueryIndex adapter. */ |
|
| 385 |
private static IWorkbenchAdapter queryindexAdapter = new IWorkbenchAdapter() {
|
|
| 386 |
|
|
| 387 |
@Override |
|
| 388 |
public Object[] getChildren(Object o) {
|
|
| 389 |
return new Object[0]; |
|
| 390 |
} |
|
| 391 |
|
|
| 392 |
@Override |
|
| 393 |
public ImageDescriptor getImageDescriptor(Object object) {
|
|
| 394 |
return IImageKeys.getImageDescriptor(IImageKeys.QUERYINDEX); |
|
| 395 |
//return AbstractUIPlugin.imageDescriptorFromPlugin("QueryIndexRCP", "icons/functions/WordCloud.png"); //$NON-NLS //$NON-NLS-1$
|
|
| 396 |
//return null; |
|
| 397 |
} |
|
| 398 |
|
|
| 399 |
@Override |
|
| 400 |
public String getLabel(Object o) {
|
|
| 401 |
return ((QueryIndex) o).getName(); |
|
| 402 |
} |
|
| 403 |
|
|
| 404 |
@Override |
|
| 405 |
public Object getParent(Object o) {
|
|
| 406 |
if (((QueryIndex) o).getPartition() != null) {
|
|
| 407 |
return ((QueryIndex) o).getPartition(); |
|
| 408 |
} else {
|
|
| 409 |
return ((QueryIndex) o).getCorpus(); |
|
| 410 |
} |
|
| 411 |
} |
|
| 412 |
}; |
|
| 413 |
|
|
| 414 |
@Override |
|
| 415 |
public boolean delete() {
|
|
| 416 |
if (partition != null) return partition.removeResult(this); |
|
| 417 |
else if (corpus != null) return corpus.removeResult(this); |
|
| 418 |
return false; |
|
| 419 |
} |
|
| 420 |
|
|
| 421 |
@Override |
|
| 422 |
public String getSimpleName() {
|
|
| 423 |
return ""; |
|
| 424 |
} |
|
| 425 |
|
|
| 426 |
@Override |
|
| 427 |
public String getDetails() {
|
|
| 428 |
return ""; |
|
| 429 |
} |
|
| 430 |
} |
|
| 0 | 431 | |
| tmp/org.txm.queryindex.rcp/src/org/txm/functions/queryindex/package.html (revision 466) | ||
|---|---|---|
| 1 |
<html> |
|
| 2 |
<body> |
|
| 3 |
<p>Prototype of Query index.</p> |
|
| 4 |
</body> |
|
| 5 |
</html> |
|
| 0 | 6 | |
| tmp/org.txm.queryindex.rcp/src/org/txm/functions/queryindex/QueryIndexLine.java (revision 466) | ||
|---|---|---|
| 1 |
package org.txm.functions.queryindex; |
|
| 2 |
|
|
| 3 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
| 4 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
| 5 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
| 6 |
|
|
| 7 |
public class QueryIndexLine {
|
|
| 8 |
String name; |
|
| 9 |
private Query query; |
|
| 10 |
QueryResult[] qresults; |
|
| 11 |
int[] freqs; |
|
| 12 |
int total; |
|
| 13 |
|
|
| 14 |
|
|
| 15 |
public QueryIndexLine(String name, Query query, QueryResult[] qresults) {
|
|
| 16 |
this.qresults = qresults; |
|
| 17 |
this.query = query; |
|
| 18 |
this.name = name; |
|
| 19 |
} |
|
| 20 |
|
|
| 21 |
public String getName() {
|
|
| 22 |
return name; |
|
| 23 |
} |
|
| 24 |
|
|
| 25 |
public Query getQuery() {
|
|
| 26 |
return query; |
|
| 27 |
} |
|
| 28 |
|
|
| 29 |
public int[] getFreqs() {
|
|
| 30 |
computeFreqsAndTotal(); |
|
| 31 |
return freqs; |
|
| 32 |
} |
|
| 33 |
|
|
| 34 |
private void computeFreqsAndTotal() {
|
|
| 35 |
if (freqs == null) {
|
|
| 36 |
//System.out.println("compute freqs");
|
|
| 37 |
total = 0; |
|
| 38 |
try {
|
|
| 39 |
freqs = new int[qresults.length]; |
|
| 40 |
for (int i = 0 ; i < freqs.length ; i++) {
|
|
| 41 |
//System.out.println("add "+qresults[i].getNMatch());
|
|
| 42 |
freqs[i] = qresults[i].getNMatch(); |
|
| 43 |
total += freqs[i]; |
|
| 44 |
qresults[i].drop(); |
|
| 45 |
} |
|
| 46 |
qresults = null; |
|
| 47 |
} catch (CqiClientException e) {
|
|
| 48 |
// TODO Auto-generated catch block |
|
| 49 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
| 50 |
freqs = new int[0]; |
|
| 51 |
} |
|
| 52 |
} else {
|
|
| 53 |
total = 0; |
|
| 54 |
for (int i = 0 ; i < freqs.length ; i++) {
|
|
| 55 |
total += freqs[i]; |
|
| 56 |
} |
|
| 57 |
} |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
public int getFrequency() {
|
|
| 61 |
computeFreqsAndTotal(); |
|
| 62 |
return total; |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
public int getFrequency(int i) {
|
|
| 66 |
computeFreqsAndTotal(); |
|
| 67 |
return freqs[i]; |
|
| 68 |
} |
|
| 69 |
|
|
| 70 |
public void setFrequencies(int[] freqs) {
|
|
| 71 |
this.freqs = freqs; |
|
| 72 |
// total = 0 ; |
|
| 73 |
// for (int f : freqs) total+=f; |
|
| 74 |
// System.out.println("total : "+total);
|
|
| 75 |
} |
|
| 76 |
|
|
| 77 |
/*private static void mergeMatches(int from, List<Match> matches, List<Match> tmp) {
|
|
| 78 |
int im1 = 0; |
|
| 79 |
for (int im2 = 0 ; im2 < tmp.size() && im1 < matches.size() ;) {
|
|
| 80 |
Match m1 = matches.get(im1); |
|
| 81 |
Match m2 = tmp.get(im2); |
|
| 82 |
|
|
| 83 |
if (m1.getStart() < m2.getStart()) {
|
|
| 84 |
im1++; |
|
| 85 |
} else if (m1.getStart() > m2.getStart()) {
|
|
| 86 |
im2++; |
|
| 87 |
matches.add(im1,m2); |
|
| 88 |
} else {
|
|
| 89 |
if (m1.getEnd() < m2.getEnd()) {
|
|
| 90 |
im1++; |
|
| 91 |
} else if (m1.getEnd() > m2.getEnd()) {
|
|
| 92 |
im2++; |
|
| 93 |
matches.add(im1,m2); |
|
| 94 |
} else {
|
|
| 95 |
System.out.println("ERROR while merging : m1 == m2");
|
|
| 96 |
} |
|
| 97 |
} |
|
| 98 |
} // end of match merge |
|
| 99 |
} |
|
| 100 |
|
|
| 101 |
public void union(List<QueryIndexLine> lines) throws CqiClientException {
|
|
| 102 |
for (QueryIndexLine line : lines) { // process lines
|
|
| 103 |
for (QueryResult qresult : line.getQResult()) {
|
|
| 104 |
|
|
| 105 |
List<Match> matches = qresult.getMatches(); |
|
| 106 |
|
|
| 107 |
int nmatches = matches.size(); |
|
| 108 |
int im1 = 0; |
|
| 109 |
List<Match> matches2 = qresult.getMatches(); |
|
| 110 |
int nmatches2 = matches2.size(); |
|
| 111 |
ArrayList<Match> tmp = new ArrayList<Match>(); // receive the match to add |
|
| 112 |
|
|
| 113 |
// 1-5 2-5 3-6 7-9 |
|
| 114 |
// 1.4 1-5 2-5 3-5 7-8 7-9 |
|
| 115 |
// select all without doublons |
|
| 116 |
int im2; |
|
| 117 |
for (im2 = 0 ; im2 < nmatches2 && im1 < nmatches ;) {
|
|
| 118 |
Match m1 = matches.get(im1); |
|
| 119 |
Match m2 = matches2.get(im2); |
|
| 120 |
|
|
| 121 |
if (m1.getStart() == m2.getStart() && m1.getEnd() == m2.getEnd()) {
|
|
| 122 |
// don't add |
|
| 123 |
im2++; // test next match2 |
|
| 124 |
} else {
|
|
| 125 |
tmp.add(m2); |
|
| 126 |
if (m1.getStart() < m2.getStart()) {
|
|
| 127 |
im1++; |
|
| 128 |
} else if (m1.getStart() > m2.getStart()){
|
|
| 129 |
im2++; |
|
| 130 |
} else {
|
|
| 131 |
if (m1.getEnd() < m2.getEnd()) {
|
|
| 132 |
im1++; |
|
| 133 |
} else {
|
|
| 134 |
im2++; |
|
| 135 |
} |
|
| 136 |
} |
|
| 137 |
} |
|
| 138 |
} // almost end of match selection |
|
| 139 |
for (int i = im2 ; i < nmatches2 ; i++) |
|
| 140 |
tmp.add(matches2.get(im2)); // get the last ones if any |
|
| 141 |
|
|
| 142 |
// merge |
|
| 143 |
mergeMatches(0, matches, tmp); |
|
| 144 |
} // end of union |
|
| 145 |
freqs = null; // will be recomputed next time |
|
| 146 |
} |
|
| 147 |
}*/ |
|
| 148 |
|
|
| 149 |
/*public void inter(List<QueryIndexLine> lines) throws CqiClientException {
|
|
| 150 |
List<Match> matches = qresult.getMatches(); |
|
| 151 |
for (QueryIndexLine line : lines) {
|
|
| 152 |
List<Match> matches2 = line.getQResult().getMatches(); |
|
| 153 |
} |
|
| 154 |
freq = -1; |
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
public void minus(List<QueryIndexLine> lines)throws CqiClientException {
|
|
| 158 |
List<Match> matches = qresult.getMatches(); |
|
| 159 |
for (QueryIndexLine line : lines) {
|
|
| 160 |
List<Match> matches2 = line.getQResult().getMatches(); |
|
| 161 |
} |
|
| 162 |
freq = -1; |
|
| 163 |
} |
|
| 164 |
*/ |
|
| 165 |
} |
|
| 0 | 166 | |
| tmp/org.txm.queryindex.rcp/src/org/txm/rcpapplication/commands/function/ComputeQueryIndex.java (revision 466) | ||
|---|---|---|
| 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.rcpapplication.commands.function; |
|
| 29 |
|
|
| 30 |
import org.eclipse.core.commands.AbstractHandler; |
|
| 31 |
import org.eclipse.core.commands.ExecutionEvent; |
|
| 32 |
import org.eclipse.core.commands.ExecutionException; |
|
| 33 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
| 34 |
import org.eclipse.ui.IWorkbenchPage; |
|
| 35 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
| 36 |
import org.txm.index.rcp.messages.IndexUIMessages; |
|
| 37 |
import org.txm.rcp.StatusLine; |
|
| 38 |
import org.txm.rcp.TXMWindows; |
|
| 39 |
import org.txm.rcpapplication.editors.input.QueryIndexEditorInput; |
|
| 40 |
import org.txm.rcpapplication.editors.queryindex.QueryIndexEditor; |
|
| 41 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
| 42 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
| 43 |
import org.txm.utils.logger.Log; |
|
| 44 |
// TODO: Auto-generated Javadoc |
|
| 45 |
/** |
|
| 46 |
* open the Index Editor |
|
| 47 |
* @author mdecorde. |
|
| 48 |
*/ |
|
| 49 |
public class ComputeQueryIndex extends AbstractHandler {
|
|
| 50 |
|
|
| 51 |
/** The ID. */ |
|
| 52 |
public static String ID = "org.txm.rcpapplication.commands.function.ComputeQueryIndex"; //$NON-NLS-1$ |
|
| 53 |
|
|
| 54 |
/** The selection. */ |
|
| 55 |
private IStructuredSelection selection; |
|
| 56 |
|
|
| 57 |
/* (non-Javadoc) |
|
| 58 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
| 59 |
*/ |
|
| 60 |
@Override |
|
| 61 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
|
| 62 |
Log.info("Compute QueryIndex: start");
|
|
| 63 |
selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
| 64 |
|
|
| 65 |
Object s = selection.getFirstElement(); |
|
| 66 |
if (s instanceof Corpus) {
|
|
| 67 |
final Corpus corpus = (Corpus) s; |
|
| 68 |
openEditor(corpus); |
|
| 69 |
} else if (s instanceof Partition) {
|
|
| 70 |
final Partition partition = (Partition) s; |
|
| 71 |
openEditor(partition); |
|
| 72 |
} else {
|
|
| 73 |
Log.severe("Can not compute QueryIndex with: "+s);
|
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
return null; |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
public static void openEditor(Corpus corpus) {
|
|
| 80 |
IWorkbenchPage page = TXMWindows.getActiveWindow().getActivePage(); |
|
| 81 |
QueryIndexEditorInput editorInput = new QueryIndexEditorInput(corpus); |
|
| 82 |
try {
|
|
| 83 |
StatusLine.setMessage(IndexUIMessages.ComputeIndex_0); |
|
| 84 |
QueryIndexEditor voceditor = (QueryIndexEditor) page |
|
| 85 |
.openEditor(editorInput,QueryIndexEditor.ID); |
|
| 86 |
voceditor.initializeFields(); |
|
| 87 |
} catch (Exception e) {
|
|
| 88 |
Log.printStackTrace(e); |
|
| 89 |
} |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
public static void openEditor(Partition partition) {
|
|
| 93 |
IWorkbenchPage page = TXMWindows.getActiveWindow().getActivePage(); |
|
| 94 |
QueryIndexEditorInput editorInput = new QueryIndexEditorInput(partition); |
|
| 95 |
try {
|
|
| 96 |
StatusLine.setMessage(IndexUIMessages.ComputeIndex_0); |
|
| 97 |
QueryIndexEditor voceditor = (QueryIndexEditor) page |
|
| 98 |
.openEditor(editorInput, QueryIndexEditor.ID); |
|
| 99 |
voceditor.initializeFields(); |
|
| 100 |
} catch (Exception e) {
|
|
| 101 |
Log.printStackTrace(e); |
|
| 102 |
} |
|
| 103 |
} |
|
| 104 |
} |
|
| 0 | 105 | |
| tmp/org.txm.queryindex.rcp/src/org/txm/rcpapplication/commands/link/QueryIndexToLexicalTable.java (revision 466) | ||
|---|---|---|
| 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.rcpapplication.commands.link; |
|
| 29 |
|
|
| 30 |
import java.util.ArrayList; |
|
| 31 |
|
|
| 32 |
import org.apache.batik.util.gui.CSSMediaPanel.Dialog; |
|
| 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.jface.viewers.ArrayContentProvider; |
|
| 37 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
| 38 |
import org.eclipse.jface.viewers.LabelProvider; |
|
| 39 |
import org.eclipse.swt.widgets.Shell; |
|
| 40 |
import org.eclipse.ui.IWorkbenchWindow; |
|
| 41 |
import org.eclipse.ui.dialogs.ListSelectionDialog; |
|
| 42 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
| 43 |
import org.txm.functions.queryindex.QueryIndex; |
|
| 44 |
import org.txm.lexicaltable.core.functions.LexicalTable; |
|
| 45 |
import org.txm.rcp.Messages; |
|
| 46 |
import org.txm.rcp.StatusLine; |
|
| 47 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
| 48 |
import org.txm.searchengine.cqp.corpus.Property; |
|
| 49 |
// TODO: Auto-generated Javadoc |
|
| 50 |
/** |
|
| 51 |
* The Class IndexToLexicalTable. |
|
| 52 |
*/ |
|
| 53 |
public class QueryIndexToLexicalTable extends AbstractHandler {
|
|
| 54 |
|
|
| 55 |
/** The window. */ |
|
| 56 |
private IWorkbenchWindow window; |
|
| 57 |
|
|
| 58 |
/** The selection. */ |
|
| 59 |
private IStructuredSelection selection; |
|
| 60 |
private static Shell shell; |
|
| 61 |
/* (non-Javadoc) |
|
| 62 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
| 63 |
*/ |
|
| 64 |
@Override |
|
| 65 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
|
| 66 |
// TODO Auto-generated method stub |
|
| 67 |
window = HandlerUtil.getActiveWorkbenchWindow(event); |
|
| 68 |
selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
| 69 |
shell = HandlerUtil.getActiveWorkbenchWindowChecked(event) |
|
| 70 |
.getShell(); |
|
| 71 |
return null; |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/** |
|
| 75 |
* Builds the lexical table. |
|
| 76 |
* |
|
| 77 |
* @param qindex the voc |
|
| 78 |
* @param from the from |
|
| 79 |
* @param to the to |
|
| 80 |
* @return true, if successful |
|
| 81 |
*/ |
|
| 82 |
public boolean buildLexicalTable(QueryIndex qindex, int from, int to) {
|
|
| 83 |
LexicalTable table; |
|
| 84 |
Partition partition; |
|
| 85 |
Property property; |
|
| 86 |
|
|
| 87 |
if (!qindex.isComputedWithPartition()) {
|
|
| 88 |
|
|
| 89 |
System.out.println(Messages.IndexToLexicalTable_0); |
|
| 90 |
StatusLine.setMessage(Messages.IndexToLexicalTable_0); |
|
| 91 |
return false; |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
System.out.println(Messages.ComputeLexicalTable_3); |
|
| 95 |
ArrayList<String> choices = new ArrayList<String>(); |
|
| 96 |
choices.add(Messages.ComputeLexicalTable_16); |
|
| 97 |
choices.add(Messages.ComputeLexicalTable_12); |
|
| 98 |
ListSelectionDialog dialog = new ListSelectionDialog(shell, |
|
| 99 |
choices, new ArrayContentProvider(), new LabelProvider(), |
|
| 100 |
Messages.ComputeLexicalTable_13); |
|
| 101 |
|
|
| 102 |
int ret = dialog.open(); |
|
| 103 |
//System.out.println("ret= "+ret);
|
|
| 104 |
if (ret == Dialog.OK_OPTION) {
|
|
| 105 |
|
|
| 106 |
} else {
|
|
| 107 |
return false; |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
// TODO: fix line 119 |
|
| 111 |
// try {
|
|
| 112 |
// table = LexicalTableImpl.createLexicalTableImpl(voc, QuantitativeDataStructureImpl |
|
| 113 |
// .createSymbole(LexicalTableImpl.class)); |
|
| 114 |
// partition = voc.getPartition(); |
|
| 115 |
// property = voc.getCorpus().getProperties().get(0); |
|
| 116 |
// } catch (Exception e) {
|
|
| 117 |
// org.txm.rcpapplication.utils.Logger.printStackTrace(e); |
|
| 118 |
// return false; |
|
| 119 |
// } |
|
| 120 |
// |
|
| 121 |
// try {
|
|
| 122 |
// IWorkbenchWindow window = PlatformUI.getWorkbench() |
|
| 123 |
// .getActiveWorkbenchWindow(); |
|
| 124 |
// IWorkbenchPage page = window.getActivePage(); |
|
| 125 |
// LexicalTableEditorInput editorInput = new LexicalTableEditorInput( |
|
| 126 |
// table, partition, property); |
|
| 127 |
// StatusLine.setMessage(Messages.ComputeLexicalTable_10); |
|
| 128 |
// page |
|
| 129 |
// .openEditor(editorInput, |
|
| 130 |
// "org.txm.rcpapplication.editors.lexicaltable.LexicalTableEditor"); //$NON-NLS-1$ |
|
| 131 |
// } catch (PartInitException e) {
|
|
| 132 |
// org.txm.rcpapplication.utils.Logger.printStackTrace(e); |
|
| 133 |
// } |
|
| 134 |
|
|
| 135 |
return false; |
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
} |
|
| 0 | 139 | |
| tmp/org.txm.queryindex.rcp/src/org/txm/rcpapplication/commands/link/package.html (revision 466) | ||
|---|---|---|
| 1 |
<html> |
|
| 2 |
<body> |
|
| 3 |
<p>Commands which create link between 2 textometry function</p> |
|
| 4 |
</body> |
|
| 5 |
</html> |
|
| 0 | 6 | |
| tmp/org.txm.queryindex.rcp/src/org/txm/rcpapplication/editors/queryindex/LineContentProvider.java (revision 466) | ||
|---|---|---|
| 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.rcpapplication.editors.queryindex; |
|
| 29 |
|
|
| 30 |
import java.util.List; |
|
| 31 |
|
|
| 32 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
| 33 |
import org.eclipse.jface.viewers.Viewer; |
|
| 34 |
import org.txm.functions.queryindex.QueryIndexLine; |
|
| 35 |
|
|
| 36 |
// TODO: Auto-generated Javadoc |
|
| 37 |
/** |
|
| 38 |
* The IStructuredContentProvider used by the reference and line tables. |
|
| 39 |
* |
|
| 40 |
* @author jmague |
|
| 41 |
*/ |
|
| 42 |
public class LineContentProvider implements IStructuredContentProvider {
|
|
| 43 |
|
|
| 44 |
/* |
|
| 45 |
* (non-Javadoc) |
|
| 46 |
* |
|
| 47 |
* @see |
|
| 48 |
* org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java |
|
| 49 |
* .lang.Object) |
|
| 50 |
*/ |
|
| 51 |
@Override |
|
| 52 |
public Object[] getElements(Object inputElement) {
|
|
| 53 |
@SuppressWarnings("unchecked")
|
|
| 54 |
List<QueryIndexLine> lines = (List<QueryIndexLine>) inputElement; |
|
| 55 |
return lines.toArray(); |
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
/* |
|
| 59 |
* (non-Javadoc) |
|
| 60 |
* |
|
| 61 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
| 62 |
*/ |
|
| 63 |
@Override |
|
| 64 |
public void dispose() {
|
|
| 65 |
// TODO Auto-generated method stub |
|
| 66 |
|
|
| 67 |
} |
|
| 68 |
|
|
| 69 |
/* |
|
| 70 |
* (non-Javadoc) |
|
| 71 |
* |
|
| 72 |
* @see |
|
| 73 |
* org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface |
|
| 74 |
* .viewers.Viewer, java.lang.Object, java.lang.Object) |
|
| 75 |
*/ |
|
| 76 |
@Override |
|
| 77 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
|
| 78 |
// TODO Auto-generated method stub |
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
} |
|
| 0 | 82 | |
| tmp/org.txm.queryindex.rcp/src/org/txm/rcpapplication/editors/queryindex/LineLabelProvider.java (revision 466) | ||
|---|---|---|
| 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.rcpapplication.editors.queryindex; |
|
| 29 |
|
|
| 30 |
import org.eclipse.jface.viewers.ILabelProviderListener; |
|
| 31 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
|
| 32 |
import org.eclipse.swt.graphics.Image; |
|
| 33 |
import org.txm.functions.queryindex.QueryIndexLine; |
|
| 34 |
|
|
| 35 |
// TODO: Auto-generated Javadoc |
|
| 36 |
/** |
|
| 37 |
* The Class LineLabelProvider. |
|
| 38 |
*/ |
|
| 39 |
public class LineLabelProvider implements ITableLabelProvider {
|
|
| 40 |
|
|
| 41 |
/* (non-Javadoc) |
|
| 42 |
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) |
|
| 43 |
*/ |
|
| 44 |
@Override |
|
| 45 |
public Image getColumnImage(Object element, int columnIndex) {
|
|
| 46 |
return null; |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/* (non-Javadoc) |
|
| 50 |
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) |
|
| 51 |
*/ |
|
| 52 |
@Override |
|
| 53 |
public String getColumnText(Object element, int columnIndex) {
|
|
| 54 |
QueryIndexLine line = (QueryIndexLine) element; |
|
| 55 |
switch (columnIndex) {
|
|
| 56 |
case 0: |
|
| 57 |
return ""; //$NON-NLS-1$ |
|
| 58 |
case 1: |
|
| 59 |
return line.getName(); |
|
| 60 |
case 2: |
|
| 61 |
return "" + line.getFrequency(); //$NON-NLS-1$ |
|
| 62 |
default: |
|
| 63 |
if (line.getFreqs().length > 1 |
|
| 64 |
&& columnIndex - 3 < line.getFreqs().length) |
|
| 65 |
return "" + line.getFrequency(columnIndex - 3); //$NON-NLS-1$ |
|
| 66 |
else |
|
| 67 |
return "";//$NON-NLS-1$ |
|
| 68 |
} |
|
| 69 |
} |
|
| 70 |
|
|
| 71 |
/* (non-Javadoc) |
|
| 72 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) |
|
| 73 |
*/ |
|
| 74 |
@Override |
|
| 75 |
public void addListener(ILabelProviderListener listener) {
|
|
| 76 |
// TODO Auto-generated method stub |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
/* (non-Javadoc) |
|
| 80 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() |
|
| 81 |
*/ |
|
| 82 |
@Override |
|
| 83 |
public void dispose() {
|
|
| 84 |
// TODO Auto-generated method stub |
|
| 85 |
} |
|
| 86 |
|
|
| 87 |
/* (non-Javadoc) |
|
| 88 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) |
|
| 89 |
*/ |
|
| 90 |
@Override |
|
| 91 |
public boolean isLabelProperty(Object element, String property) {
|
|
| 92 |
// TODO Auto-generated method stub |
|
| 93 |
return false; |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
/* (non-Javadoc) |
|
| 97 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) |
|
| 98 |
*/ |
|
| 99 |
@Override |
|
| 100 |
public void removeListener(ILabelProviderListener listener) {
|
|
| 101 |
// TODO Auto-generated method stub |
|
| 102 |
} |
|
| 103 |
} |
|
| 0 | 104 | |
| tmp/org.txm.queryindex.rcp/src/org/txm/rcpapplication/editors/queryindex/QueryIndexEditor.java (revision 466) | ||
|---|---|---|
| 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.rcpapplication.editors.queryindex; |
|
| 29 |
|
|
| 30 |
import java.io.File; |
|
| 31 |
import java.io.IOException; |
|
| 32 |
import java.util.ArrayList; |
|
| 33 |
import java.util.List; |
|
| 34 |
|
|
| 35 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
| 36 |
import org.eclipse.core.runtime.IStatus; |
|
| 37 |
import org.eclipse.core.runtime.Status; |
|
| 38 |
import org.eclipse.jface.action.MenuManager; |
|
| 39 |
import org.eclipse.jface.viewers.ISelection; |
|
| 40 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
| 41 |
import org.eclipse.jface.viewers.TableViewer; |
|
| 42 |
import org.eclipse.swt.SWT; |
|
| 43 |
import org.eclipse.swt.custom.ScrolledComposite; |
|
| 44 |
import org.eclipse.swt.events.ControlAdapter; |
|
| 45 |
import org.eclipse.swt.events.ControlEvent; |
|
| 46 |
import org.eclipse.swt.events.KeyEvent; |
|
| 47 |
import org.eclipse.swt.events.KeyListener; |
|
| 48 |
import org.eclipse.swt.events.MouseAdapter; |
|
| 49 |
import org.eclipse.swt.events.MouseEvent; |
|
| 50 |
import org.eclipse.swt.events.SelectionEvent; |
|
| 51 |
import org.eclipse.swt.events.SelectionListener; |
|
| 52 |
import org.eclipse.swt.graphics.Font; |
|
| 53 |
import org.eclipse.swt.graphics.FontData; |
|
| 54 |
import org.eclipse.swt.graphics.Image; |
|
| 55 |
import org.eclipse.swt.graphics.Point; |
|
| 56 |
import org.eclipse.swt.graphics.Rectangle; |
|
| 57 |
import org.eclipse.swt.layout.FormAttachment; |
|
| 58 |
import org.eclipse.swt.layout.FormData; |
|
| 59 |
import org.eclipse.swt.layout.FormLayout; |
|
| 60 |
import org.eclipse.swt.layout.GridData; |
|
| 61 |
import org.eclipse.swt.layout.GridLayout; |
|
| 62 |
import org.eclipse.swt.widgets.Button; |
|
| 63 |
import org.eclipse.swt.widgets.Composite; |
|
| 64 |
import org.eclipse.swt.widgets.Display; |
|
| 65 |
import org.eclipse.swt.widgets.FileDialog; |
|
| 66 |
import org.eclipse.swt.widgets.Label; |
|
| 67 |
import org.eclipse.swt.widgets.Menu; |
|
| 68 |
import org.eclipse.swt.widgets.Spinner; |
|
| 69 |
import org.eclipse.swt.widgets.TableColumn; |
|
| 70 |
import org.eclipse.ui.IEditorInput; |
|
| 71 |
import org.eclipse.ui.IEditorSite; |
|
| 72 |
import org.eclipse.ui.PartInitException; |
|
| 73 |
import org.eclipse.ui.part.EditorPart; |
|
| 74 |
import org.txm.functions.queryindex.QueryIndex; |
|
| 75 |
import org.txm.functions.queryindex.QueryIndexLine; |
|
Formats disponibles : Unified diff