Révision 470
tmp/org.txm.dictionary.rcp/src/dictionary/Activator.java (revision 470) | ||
---|---|---|
1 |
package dictionary; |
|
2 |
|
|
3 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
4 |
import org.osgi.framework.BundleContext; |
|
5 |
|
|
6 |
/** |
|
7 |
* The activator class controls the plug-in life cycle |
|
8 |
*/ |
|
9 |
public class Activator extends AbstractUIPlugin { |
|
10 |
|
|
11 |
// The plug-in ID |
|
12 |
public static final String PLUGIN_ID = "Dictionary"; //$NON-NLS-1$ |
|
13 |
|
|
14 |
// The shared instance |
|
15 |
private static Activator plugin; |
|
16 |
|
|
17 |
/** |
|
18 |
* The constructor |
|
19 |
*/ |
|
20 |
public Activator() { |
|
21 |
} |
|
22 |
|
|
23 |
/* |
|
24 |
* (non-Javadoc) |
|
25 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
|
26 |
*/ |
|
27 |
public void start(BundleContext context) throws Exception { |
|
28 |
super.start(context); |
|
29 |
plugin = this; |
|
30 |
} |
|
31 |
|
|
32 |
/* |
|
33 |
* (non-Javadoc) |
|
34 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
|
35 |
*/ |
|
36 |
public void stop(BundleContext context) throws Exception { |
|
37 |
plugin = null; |
|
38 |
super.stop(context); |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* Returns the shared instance |
|
43 |
* |
|
44 |
* @return the shared instance |
|
45 |
*/ |
|
46 |
public static Activator getDefault() { |
|
47 |
return plugin; |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
0 | 51 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/DoInstallStep.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
|
|
4 |
import java.io.File; |
|
5 |
|
|
6 |
import org.eclipse.core.commands.ExecutionEvent; |
|
7 |
import org.osgi.framework.Version; |
|
8 |
import org.txm.PostInstallationStep; |
|
9 |
import org.txm.Toolbox; |
|
10 |
import org.txm.core.preferences.TBXPreferences; |
|
11 |
import org.txm.core.preferences.TXMPreferences; |
|
12 |
import org.txm.dictionary.preferences.DictionaryPreferences; |
|
13 |
import org.txm.rcp.TxmPreferences; |
|
14 |
import org.txm.utils.BundleUtils; |
|
15 |
import org.txm.utils.logger.Log; |
|
16 |
|
|
17 |
/** |
|
18 |
* Copy macros from bundle to TXM macro directory |
|
19 |
* |
|
20 |
* @author mdecorde |
|
21 |
* |
|
22 |
*/ |
|
23 |
public class DoInstallStep extends PostInstallationStep { |
|
24 |
|
|
25 |
public static String ID = "org.txm.dictionary.commands.DoInstallStep"; //$NON-NLS-1$ |
|
26 |
public static final String VERSION = "org.txm.dictionary.version"; |
|
27 |
|
|
28 |
public void install() { |
|
29 |
|
|
30 |
Log.info("Dictionary.DoInstallStep.install()"); |
|
31 |
|
|
32 |
String saved = TXMPreferences.getString(DictionaryPreferences.VERSION, DictionaryPreferences.PREFERENCES_NODE); |
|
33 |
Version currentVersion = BundleUtils.getBundleVersion("Dictionary"); |
|
34 |
|
|
35 |
if (saved != null && saved.length() > 0) { |
|
36 |
Version savedVersion = new Version(saved); |
|
37 |
if (currentVersion.compareTo(savedVersion) <= 0) { |
|
38 |
Log.info("No post-installation of Dictionary to do."); |
|
39 |
//System.out.println("No post-installation of Dictionary to do."); |
|
40 |
return; // nothing to do |
|
41 |
} |
|
42 |
} |
|
43 |
System.out.println("Post-installing Dictionary version="+currentVersion); |
|
44 |
|
|
45 |
File macroDirectory = new File(TXMPreferences.getString(TBXPreferences.USER_TXM_HOME, TBXPreferences.PREFERENCES_NODE), "scripts/macro/org/txm/macro"); |
|
46 |
if (!BundleUtils.copyFiles("Dictionary", "src", "org/txm/macro/", "frolex", macroDirectory)) { |
|
47 |
System.out.println("Error while coping Dictionary org/txm/macro/frolex in "+macroDirectory.getAbsolutePath()); |
|
48 |
return; |
|
49 |
} |
|
50 |
|
|
51 |
Log.warning("Dictionary post-installation done."); |
|
52 |
TXMPreferences.put(DictionaryPreferences.PREFERENCES_NODE, DictionaryPreferences.VERSION, currentVersion.toString()); |
|
53 |
return; |
|
54 |
} |
|
55 |
|
|
56 |
public DoInstallStep() { |
|
57 |
name = "Dictionary"; |
|
58 |
} |
|
59 |
} |
|
0 | 60 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/DeleteDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.AbstractHandler; |
|
4 |
import org.eclipse.core.commands.ExecutionEvent; |
|
5 |
import org.eclipse.core.commands.ExecutionException; |
|
6 |
import org.kohsuke.args4j.Option; |
|
7 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
8 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
9 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
10 |
|
|
11 |
public class DeleteDictionary extends AbstractHandler { |
|
12 |
|
|
13 |
@Option(name="name", usage="dictionary name 1", widget="String", required=true, def="bfmlex") |
|
14 |
public String name = null; |
|
15 |
|
|
16 |
@Override |
|
17 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
18 |
try { |
|
19 |
if (ParametersDialog.open(this)) { |
|
20 |
remove(name); |
|
21 |
} |
|
22 |
} catch (Exception e) { |
|
23 |
// TODO Auto-generated catch block |
|
24 |
e.printStackTrace(); |
|
25 |
} |
|
26 |
return null; |
|
27 |
} |
|
28 |
|
|
29 |
public static void remove(String name) throws Exception { |
|
30 |
DictionaryManager.getInstance().remove(name); |
|
31 |
} |
|
32 |
} |
|
0 | 33 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/QueryDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.AbstractHandler; |
|
4 |
import org.eclipse.core.commands.ExecutionEvent; |
|
5 |
import org.eclipse.core.commands.ExecutionException; |
|
6 |
import org.kohsuke.args4j.Option; |
|
7 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
8 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
9 |
|
|
10 |
public class QueryDictionary extends AbstractHandler { |
|
11 |
|
|
12 |
@Option(name="query", usage="SQL query, can contains $NAME which will be replace with the dictionary SQL name", widget="String", required=true, def="SELECT * FROM $NAME") |
|
13 |
public String query; |
|
14 |
|
|
15 |
@Override |
|
16 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
17 |
try { |
|
18 |
if (ParametersDialog.open(this)) { |
|
19 |
return query(query); |
|
20 |
} |
|
21 |
|
|
22 |
return -1; |
|
23 |
|
|
24 |
} catch (Exception e) { |
|
25 |
e.printStackTrace(); |
|
26 |
} |
|
27 |
return null; |
|
28 |
} |
|
29 |
|
|
30 |
public static int query(String query) throws Exception { |
|
31 |
int n = DictionaryManager.getInstance().queryAndPrint(query); |
|
32 |
System.out.println("Result size="+n); |
|
33 |
return n; |
|
34 |
} |
|
35 |
} |
|
0 | 36 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/AddColumnDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.AbstractHandler; |
|
4 |
import org.eclipse.core.commands.ExecutionEvent; |
|
5 |
import org.eclipse.core.commands.ExecutionException; |
|
6 |
import org.kohsuke.args4j.Option; |
|
7 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
8 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
9 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
10 |
|
|
11 |
public class AddColumnDictionary extends AbstractHandler { |
|
12 |
|
|
13 |
@Option(name="name", usage="dictionary name", widget="String", required=true, def="conv.tsv") |
|
14 |
public String name = null; |
|
15 |
@Option(name="type", usage="type", widget="String", required=true, def="type") |
|
16 |
public String type = null; |
|
17 |
|
|
18 |
@Override |
|
19 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
20 |
try { |
|
21 |
if (ParametersDialog.open(this)) { |
|
22 |
if (DictionaryManager.getInstance().hasDictionary(name)) { |
|
23 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
24 |
add(d, type); |
|
25 |
} |
|
26 |
} |
|
27 |
return null; |
|
28 |
} catch (Exception e) { |
|
29 |
e.printStackTrace(); |
|
30 |
} |
|
31 |
return null; |
|
32 |
} |
|
33 |
|
|
34 |
public static Dictionary add(Dictionary d, String type) throws Exception { |
|
35 |
if (d.getTypes().contains(type)) { |
|
36 |
System.out.println("Column already exists."); |
|
37 |
return d; |
|
38 |
} |
|
39 |
d.addType(type); |
|
40 |
System.out.println("Type="+type+" added to "+d.getName()); |
|
41 |
return null; |
|
42 |
} |
|
43 |
} |
|
0 | 44 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/MergeDictionaries.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import java.util.Arrays; |
|
4 |
import java.util.LinkedHashMap; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import org.eclipse.core.commands.AbstractHandler; |
|
8 |
import org.eclipse.core.commands.ExecutionEvent; |
|
9 |
import org.eclipse.core.commands.ExecutionException; |
|
10 |
import org.kohsuke.args4j.Option; |
|
11 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
12 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
13 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
14 |
|
|
15 |
public class MergeDictionaries extends AbstractHandler { |
|
16 |
|
|
17 |
@Option(name="name", usage="dictionary name 1", widget="String", required=true, def="bfmlex") |
|
18 |
public String name = null; |
|
19 |
@Option(name="name2", usage="dictionary name 2", widget="String", required=true, def="bfmgoldlex") |
|
20 |
public String name2 = null; |
|
21 |
@Option(name="cols", usage="columns", widget="String", required=true, def="word,pos") |
|
22 |
public String cols = null; |
|
23 |
@Option(name="aggregatescols", usage="the other columns", widget="String", required=true, def="F") |
|
24 |
public String aggregatescols = null; |
|
25 |
@Option(name="aggregates", usage="the agregates instruction for each other column.", widget="String", required=true, def="MAX") |
|
26 |
public String aggregates = null; |
|
27 |
|
|
28 |
@Override |
|
29 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
30 |
try { |
|
31 |
if (ParametersDialog.open(this)) { |
|
32 |
if (DictionaryManager.getInstance().hasDictionary(name) && DictionaryManager.getInstance().hasDictionary(name2)) { |
|
33 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
34 |
Dictionary d2 = DictionaryManager.getInstance().getDictionary(name2); |
|
35 |
List<String> colsList = Arrays.asList(cols.split(",")); |
|
36 |
List<String> aggregatescolsList = Arrays.asList(aggregatescols.split(",")); |
|
37 |
List<String> aggregateList = Arrays.asList(aggregates.split(",")); |
|
38 |
return merge(d, d2, colsList, aggregatescolsList, aggregateList); |
|
39 |
} else { |
|
40 |
System.out.println("Error: a dictionary is missing: "+name+" or "+name2); |
|
41 |
} |
|
42 |
} |
|
43 |
|
|
44 |
return null; |
|
45 |
} catch (Exception e) { |
|
46 |
e.printStackTrace(); |
|
47 |
} |
|
48 |
return null; |
|
49 |
} |
|
50 |
|
|
51 |
public static Dictionary merge(Dictionary d, Dictionary d2, List<String> cols, List<String> aggregatescols, List<String> aggregates) throws Exception { |
|
52 |
|
|
53 |
if (aggregatescols.size() != aggregates.size()) { |
|
54 |
System.out.println("other columns and aggregates size differs: others="+aggregatescols.size()+" aggregates="+aggregates.size()); |
|
55 |
return null; |
|
56 |
} |
|
57 |
|
|
58 |
LinkedHashMap<String, String> agregateInstructions = new LinkedHashMap<String, String>(); |
|
59 |
for (int i = 0 ; i < aggregatescols.size() ; i++) { |
|
60 |
agregateInstructions.put(aggregatescols.get(i), aggregates.get(i)); |
|
61 |
} |
|
62 |
int n = d2.mergeWith(d, cols, agregateInstructions); |
|
63 |
|
|
64 |
if (n == 0) System.out.println("No entry added"); |
|
65 |
else if (n == 1) System.out.println("One entry added."); |
|
66 |
else System.out.println(""+n+" entries added"); |
|
67 |
|
|
68 |
return d2; |
|
69 |
} |
|
70 |
} |
|
0 | 71 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/ExportToTreeTagger.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileNotFoundException; |
|
5 |
import java.io.IOException; |
|
6 |
import java.io.PrintWriter; |
|
7 |
import java.io.UnsupportedEncodingException; |
|
8 |
import java.sql.ResultSet; |
|
9 |
import java.sql.SQLException; |
|
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.HashMap; |
|
16 |
import java.util.HashSet; |
|
17 |
import java.util.LinkedHashMap; |
|
18 |
import java.util.LinkedHashSet; |
|
19 |
import java.util.List; |
|
20 |
|
|
21 |
import org.apache.commons.lang.StringUtils; |
|
22 |
import org.eclipse.core.commands.AbstractHandler; |
|
23 |
import org.eclipse.core.commands.ExecutionEvent; |
|
24 |
import org.eclipse.core.commands.ExecutionException; |
|
25 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
26 |
import org.eclipse.core.runtime.IStatus; |
|
27 |
import org.eclipse.core.runtime.Status; |
|
28 |
import org.kohsuke.args4j.Option; |
|
29 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
30 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
31 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
32 |
import org.txm.rcp.utils.JobHandler; |
|
33 |
import org.txm.utils.io.IOUtils; |
|
34 |
import org.txm.utils.logger.Log; |
|
35 |
|
|
36 |
public class ExportToTreeTagger extends AbstractHandler { |
|
37 |
|
|
38 |
@Option(name="name", usage="dictionary name", widget="String", required=true, def="frolex") |
|
39 |
public String name = null; |
|
40 |
@Option(name="pos", usage="pos property", widget="String", required=true, def="msd_cattex_conv") |
|
41 |
public String pos = null; |
|
42 |
@Option(name="lemma", usage="lemma property", widget="String", required=true, def="lemma") |
|
43 |
public String lemma = null; |
|
44 |
@Option(name="ignoredPosValues", usage="types", widget="String", required=true, def="<nopos>,,") |
|
45 |
public String ignoredPosValues = null; |
|
46 |
@Option(name="tsvfile", usage="tsvfile", widget="File", required=true, def="lexicon.txt") |
|
47 |
public File tsvfile = null; |
|
48 |
|
|
49 |
@Override |
|
50 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
51 |
try { |
|
52 |
if (ParametersDialog.open(this)) { |
|
53 |
JobHandler job = new JobHandler("TreeTagger lexicon export "+name) { |
|
54 |
|
|
55 |
@Override |
|
56 |
protected IStatus run(IProgressMonitor monitor) { |
|
57 |
this.runInit(monitor); |
|
58 |
try { |
|
59 |
if (DictionaryManager.getInstance().hasDictionary(name)) { |
|
60 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
61 |
HashSet<String> ignoredPosValuesSet = new HashSet<String>(split(ignoredPosValues)); |
|
62 |
|
|
63 |
export(d, pos, lemma, ignoredPosValuesSet, tsvfile); |
|
64 |
} |
|
65 |
} catch (Exception e) { |
|
66 |
System.out.println("Error: "+e); |
|
67 |
Log.printStackTrace(e); |
|
68 |
} |
|
69 |
return Status.OK_STATUS; |
|
70 |
} |
|
71 |
}; |
|
72 |
job.schedule(); |
|
73 |
} |
|
74 |
return null; |
|
75 |
} catch (Exception e) { |
|
76 |
System.out.println("Error: "+e); |
|
77 |
Log.printStackTrace(e); |
|
78 |
} |
|
79 |
return null; |
|
80 |
} |
|
81 |
|
|
82 |
public static ArrayList<String> split(String s) { |
|
83 |
ArrayList<String> result = new ArrayList<String>(); |
|
84 |
int idx = s.indexOf(","); |
|
85 |
if (idx < 0) return result; |
|
86 |
|
|
87 |
while (idx >= 0) { |
|
88 |
String s1 = s.substring(0, idx); |
|
89 |
result.add(s1); |
|
90 |
s = s.substring(idx+1); |
|
91 |
idx = s.indexOf(","); |
|
92 |
} |
|
93 |
result.add(s); |
|
94 |
return result; |
|
95 |
} |
|
96 |
|
|
97 |
private static StringBuilder b = new StringBuilder(); |
|
98 |
public static String join(Collection<String> values, String sep) { |
|
99 |
b.setLength(0); |
|
100 |
for (String s: values) b.append(s+"\t"); |
|
101 |
|
|
102 |
return b.substring(0, b.length()-1); |
|
103 |
} |
|
104 |
|
|
105 |
public static boolean export(Dictionary d, String pos, String lemma, HashSet<String> ignoredPosValues, File tsvfile) throws UnsupportedEncodingException, FileNotFoundException, SQLException { |
|
106 |
|
|
107 |
System.out.println("Merging lines of "+d+" in "+tsvfile); |
|
108 |
System.out.println(" pos property="+pos); |
|
109 |
System.out.println(" lemma property="+lemma); |
|
110 |
System.out.println(" ignoredvalues="+ignoredPosValues); |
|
111 |
|
|
112 |
List<String> columns = d.getTypes(); |
|
113 |
if (!columns.contains("form")) { |
|
114 |
System.out.println("Type not found in dictionary: "+"form"); |
|
115 |
return false; |
|
116 |
} |
|
117 |
|
|
118 |
if (!columns.contains(pos)) { |
|
119 |
System.out.println(pos+" type not found in dictionary: "+columns); |
|
120 |
return false; |
|
121 |
} |
|
122 |
if (!columns.contains(lemma)) { |
|
123 |
System.out.println(lemma+" type not found in dictionary: "+columns); |
|
124 |
return false; |
|
125 |
} |
|
126 |
String TAB = "\t"; |
|
127 |
|
|
128 |
PrintWriter writer = IOUtils.getWriter(tsvfile, "UTF-8"); |
|
129 |
ResultSet result = d.getSortedLines("form"); |
|
130 |
String currentForm = null; |
|
131 |
HashMap<String, HashSet<String>> posFound = new HashMap<String, HashSet<String>>(); |
|
132 |
|
|
133 |
while (result.next()) { // for each form entry |
|
134 |
String form = result.getString("form"); |
|
135 |
String ignoreValue = result.getString(pos); |
|
136 |
if (ignoredPosValues.size() > 0 && ignoredPosValues.contains(ignoreValue)) { continue; } // ignore "<nopos>" pos values entries |
|
137 |
|
|
138 |
if (!form.equals(currentForm)) { // append to the current merged line |
|
139 |
if (currentForm != null && posFound.size() > 0) { // write the line if the word has pos |
|
140 |
|
|
141 |
writer.print(currentForm); |
|
142 |
|
|
143 |
for (String posValue : posFound.keySet()) { // for each pos, sort the lemmas |
|
144 |
|
|
145 |
ArrayList<String> lemmaValues = new ArrayList<String>(); |
|
146 |
lemmaValues.addAll(posFound.get(posValue)); |
|
147 |
Collections.sort(lemmaValues, new Comparator<String>(){ |
|
148 |
@Override |
|
149 |
public int compare(String o1, String o2) { |
|
150 |
if (o2.contains("no_lemma")) return -1; |
|
151 |
else if (o2.contains("nolem")) {return -1;} |
|
152 |
else if (o1.contains("no_lemma")) return 1; |
|
153 |
else if (o1.contains("nolem")) {return 1;} |
|
154 |
return 0; |
|
155 |
} |
|
156 |
}); |
|
157 |
if (lemmaValues.size() > 1) lemmaValues.remove("<no_lemma>"); // remove <no_lemma> if there are others lemma values |
|
158 |
writer.print("\t"+posValue+" "+StringUtils.join(lemmaValues, "|")); |
|
159 |
} |
|
160 |
writer.println(""); // end of line |
|
161 |
|
|
162 |
} else { |
|
163 |
System.out.println("Form '"+currentForm+"' has no pos-lemme couple."); |
|
164 |
} |
|
165 |
|
|
166 |
|
|
167 |
posFound.clear(); |
|
168 |
currentForm = form; |
|
169 |
} |
|
170 |
String firstValue = result.getString(pos); |
|
171 |
if (!posFound.containsKey(firstValue)) posFound.put(firstValue, new HashSet<String>()); // avoid repeating the first type value |
|
172 |
|
|
173 |
String value = result.getString(lemma).trim(); |
|
174 |
if (value == null) { |
|
175 |
System.out.println("Error: null value for type="+lemma); |
|
176 |
writer.close(); |
|
177 |
return false; |
|
178 |
} |
|
179 |
|
|
180 |
if (value.length() == 0) { |
|
181 |
value = "<no_lemma>"; |
|
182 |
} |
|
183 |
posFound.get(firstValue).add(value); // add the new lemma for this pos value |
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
writer.close(); |
|
188 |
result.getStatement().close(); // :-) |
|
189 |
System.out.println("Result saved in "+tsvfile.getAbsolutePath()); |
|
190 |
return true; |
|
191 |
} |
|
192 |
|
|
193 |
public static void main(String[] args) throws Exception { |
|
194 |
File frolexTSV = new File("/home/mdecorde/TXM/results/lexique BFM/result/frolex.tsv"); |
|
195 |
File frolexTT = new File("/home/mdecorde/TXM/results/lexique BFM/result/frolex-tt.tsv"); |
|
196 |
DictionaryManager.getInstance().remove("bfmlex"); |
|
197 |
Dictionary frolex = DictionaryManager.getInstance().getDictionary("frolex"); |
|
198 |
frolex.loadFromTSVFile(frolexTSV); |
|
199 |
|
|
200 |
ArrayList<String> types = new ArrayList<String>(); |
|
201 |
types.add("msd_cattex_conv"); |
|
202 |
types.add("lemma"); |
|
203 |
String ignoredTestType = "msd_cattex_conv"; |
|
204 |
HashSet<String> ignoredvalues = new HashSet<String>(); |
|
205 |
ignoredvalues.add("<nopos>"); |
|
206 |
ignoredvalues.add(""); |
|
207 |
|
|
208 |
export(frolex,"msd_cattex_conv", "lemma", ignoredvalues, frolexTT); |
|
209 |
} |
|
210 |
} |
|
0 | 211 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/ImportDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.eclipse.core.commands.AbstractHandler; |
|
6 |
import org.eclipse.core.commands.ExecutionEvent; |
|
7 |
import org.eclipse.core.commands.ExecutionException; |
|
8 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
9 |
import org.eclipse.core.runtime.IStatus; |
|
10 |
import org.eclipse.core.runtime.Status; |
|
11 |
import org.kohsuke.args4j.Option; |
|
12 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
13 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
14 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
15 |
import org.txm.rcp.utils.JobHandler; |
|
16 |
import org.txm.utils.logger.Log; |
|
17 |
|
|
18 |
public class ImportDictionary extends AbstractHandler { |
|
19 |
|
|
20 |
@Option(name="name", usage="dictionary name", widget="String", required=true, def="name") |
|
21 |
public String name = null; |
|
22 |
@Option(name="tsvfile", usage="tsvfile", widget="File", required=true, def="lexique.tsv") |
|
23 |
public File tsvfile = null; |
|
24 |
|
|
25 |
@Override |
|
26 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
27 |
try { |
|
28 |
if (ParametersDialog.open(this)) { |
|
29 |
JobHandler job = new JobHandler("UniqSort "+name) { |
|
30 |
|
|
31 |
@Override |
|
32 |
protected IStatus run(IProgressMonitor monitor) { |
|
33 |
this.runInit(monitor); |
|
34 |
try { |
|
35 |
importFromTSVFile(tsvfile, name); |
|
36 |
} catch (Exception e) { |
|
37 |
System.out.println("Error: "+e); |
|
38 |
Log.printStackTrace(e); |
|
39 |
} |
|
40 |
return Status.OK_STATUS; |
|
41 |
} |
|
42 |
}; |
|
43 |
job.schedule(); |
|
44 |
} |
|
45 |
|
|
46 |
return null; |
|
47 |
} catch (Exception e) { |
|
48 |
e.printStackTrace(); |
|
49 |
} |
|
50 |
return null; |
|
51 |
} |
|
52 |
|
|
53 |
public static Dictionary importFromTSVFile(File tsvFile, String name) throws Exception { |
|
54 |
|
|
55 |
DictionaryManager dm = DictionaryManager.getInstance(); |
|
56 |
Dictionary d = dm.getDictionary(name); |
|
57 |
if (d == null) { |
|
58 |
System.out.println("Error: could not create or get dictionary with name="+name); |
|
59 |
} |
|
60 |
if (d.loadFromTSVFile(tsvFile)) { |
|
61 |
return d; |
|
62 |
} |
|
63 |
return null; |
|
64 |
} |
|
65 |
} |
|
0 | 66 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/CreateDictionaryFromIndex.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
|
|
6 |
import org.eclipse.core.commands.AbstractHandler; |
|
7 |
import org.eclipse.core.commands.ExecutionEvent; |
|
8 |
import org.eclipse.core.commands.ExecutionException; |
|
9 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
10 |
import org.eclipse.core.runtime.IStatus; |
|
11 |
import org.eclipse.core.runtime.Status; |
|
12 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
13 |
import org.eclipse.swt.SWT; |
|
14 |
import org.eclipse.swt.widgets.FileDialog; |
|
15 |
import org.eclipse.swt.widgets.Shell; |
|
16 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
17 |
import org.kohsuke.args4j.Option; |
|
18 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
19 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
20 |
import org.txm.index.core.functions.Index; |
|
21 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
22 |
import org.txm.rcp.utils.JobHandler; |
|
23 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
24 |
import org.txm.utils.logger.Log; |
|
25 |
|
|
26 |
public class CreateDictionaryFromIndex extends AbstractHandler { |
|
27 |
|
|
28 |
@Option(name="name", usage="dictionary name", widget="String", required=true, def="conv.tsv") |
|
29 |
public String name = null; |
|
30 |
@Option(name="tsvFile", usage="tsvFile", widget="File", required=true, def="conv.tsv") |
|
31 |
public File tsvFile = null; |
|
32 |
|
|
33 |
@Override |
|
34 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
35 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
36 |
|
|
37 |
Object o = selection.getFirstElement(); |
|
38 |
if (!(o instanceof Index)) return null; |
|
39 |
|
|
40 |
final Index index = (Index)o; |
|
41 |
|
|
42 |
if (ParametersDialog.open(this)) { |
|
43 |
|
|
44 |
JobHandler job = new JobHandler("UniqSort "+name) { |
|
45 |
|
|
46 |
@Override |
|
47 |
protected IStatus run(IProgressMonitor monitor) { |
|
48 |
this.runInit(monitor); |
|
49 |
try { |
|
50 |
fromIndex(index, tsvFile, name); |
|
51 |
} catch (Exception e) { |
|
52 |
System.out.println("Error: "+e); |
|
53 |
Log.printStackTrace(e); |
|
54 |
} |
|
55 |
return Status.OK_STATUS; |
|
56 |
} |
|
57 |
}; |
|
58 |
job.schedule(); |
|
59 |
} |
|
60 |
|
|
61 |
return null; |
|
62 |
} |
|
63 |
|
|
64 |
public static Dictionary fromIndex(Index index, File tsvFile, String name) throws Exception { |
|
65 |
|
|
66 |
index.toTSVDictionnary(tsvFile, "\t", "UTF-8"); |
|
67 |
|
|
68 |
return ImportDictionary.importFromTSVFile(tsvFile, name); |
|
69 |
} |
|
70 |
} |
|
0 | 71 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/RecodeColumnDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.Serializable; |
|
5 |
import java.sql.SQLException; |
|
6 |
import java.util.LinkedHashMap; |
|
7 |
import java.util.regex.Pattern; |
|
8 |
|
|
9 |
import org.eclipse.core.commands.AbstractHandler; |
|
10 |
import org.eclipse.core.commands.ExecutionEvent; |
|
11 |
import org.eclipse.core.commands.ExecutionException; |
|
12 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
13 |
import org.eclipse.core.runtime.IStatus; |
|
14 |
import org.eclipse.core.runtime.Status; |
|
15 |
import org.kohsuke.args4j.Option; |
|
16 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
17 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
18 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
19 |
import org.txm.rcp.utils.JobHandler; |
|
20 |
import org.txm.utils.logger.Log; |
|
21 |
|
|
22 |
public class RecodeColumnDictionary extends AbstractHandler { |
|
23 |
|
|
24 |
@Option(name="name", usage="dictionary name", widget="String", required=true, def="conv.tsv") |
|
25 |
public String name = null; |
|
26 |
@Option(name="conversionFile", usage="conversionFile", widget="File", required=true, def="conv.tsv") |
|
27 |
public File conversionFile = null; |
|
28 |
@Option(name="type", usage="type", widget="String", required=true, def="type") |
|
29 |
public String type = null; |
|
30 |
@Option(name="newType", usage="newType", widget="String", required=true, def="newType") |
|
31 |
public String newType = null; |
|
32 |
@Option(name="mode", usage="'supprimer' to delete entries without rule, 'abandon' to stop if errors and 'copier' to copy value if no rule", widget="String", required=true, def="abandon") |
|
33 |
public String mode = "abandon"; |
|
34 |
@Option(name="oneMatch", usage="stop at first match", widget="String", required=true, def="true") |
|
35 |
public boolean oneMatch = true; |
|
36 |
@Override |
|
37 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
38 |
|
|
39 |
if (ParametersDialog.open(this)) { |
|
40 |
try { |
|
41 |
if (DictionaryManager.getInstance().hasDictionary(name)) { |
|
42 |
JobHandler job = new JobHandler("UniqSort "+name) { |
|
43 |
|
|
44 |
@Override |
|
45 |
protected IStatus run(IProgressMonitor monitor) { |
|
46 |
this.runInit(monitor); |
|
47 |
try { |
|
48 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
49 |
recode(d, conversionFile, type, newType, mode, oneMatch); |
|
50 |
} catch (Exception e) { |
|
51 |
System.out.println("Error: "+e); |
|
52 |
Log.printStackTrace(e); |
|
53 |
return Status.CANCEL_STATUS; |
|
54 |
} |
|
55 |
return Status.OK_STATUS; |
|
56 |
} |
|
57 |
}; |
|
58 |
job.schedule(); |
|
59 |
} |
|
60 |
} catch (SQLException e) { |
|
61 |
// TODO Auto-generated catch block |
|
62 |
e.printStackTrace(); |
|
63 |
} catch (Exception e) { |
|
64 |
// TODO Auto-generated catch block |
|
65 |
e.printStackTrace(); |
|
66 |
} |
|
67 |
} |
|
68 |
return null; |
|
69 |
} |
|
70 |
|
|
71 |
public static Dictionary recode(Dictionary d, File conversionTSVFile, String type, String newType, String mode, boolean oneMatch) throws Exception { |
|
72 |
|
|
73 |
LinkedHashMap<Pattern, Serializable[]> conversionRules = Dictionary.getConversionRulesFromFile(conversionTSVFile); |
|
74 |
if (conversionRules.size() > 0) { |
|
75 |
d.recodeEntryProperties(type, newType, conversionRules, mode, oneMatch); |
|
76 |
} |
|
77 |
return null; |
|
78 |
} |
|
79 |
} |
|
0 | 80 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/ExportDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.eclipse.core.commands.AbstractHandler; |
|
6 |
import org.eclipse.core.commands.ExecutionEvent; |
|
7 |
import org.eclipse.core.commands.ExecutionException; |
|
8 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
9 |
import org.eclipse.core.runtime.IStatus; |
|
10 |
import org.eclipse.core.runtime.Status; |
|
11 |
import org.kohsuke.args4j.Option; |
|
12 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
13 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
14 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
15 |
import org.txm.rcp.utils.JobHandler; |
|
16 |
import org.txm.utils.logger.Log; |
|
17 |
|
|
18 |
public class ExportDictionary extends AbstractHandler { |
|
19 |
|
|
20 |
@Option(name="name", usage="the dictionary name", widget="String", required=true, def="lex") |
|
21 |
public String name = null; |
|
22 |
@Option(name="tsvFile", usage="tsvFile", widget="FileSave", required=true, def="dict.tsv") |
|
23 |
public File tsvFile = null; |
|
24 |
|
|
25 |
@Override |
|
26 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
27 |
|
|
28 |
if (ParametersDialog.open(this)) { |
|
29 |
|
|
30 |
try { |
|
31 |
if (!DictionaryManager.getInstance().hasDictionary(name)) { |
|
32 |
System.out.println("Error: no dictionary named "+name); |
|
33 |
return null; |
|
34 |
} |
|
35 |
} catch (Exception e1) { |
|
36 |
// TODO Auto-generated catch block |
|
37 |
e1.printStackTrace(); |
|
38 |
return null; |
|
39 |
} |
|
40 |
|
|
41 |
JobHandler job = new JobHandler("UniqSort "+name) { |
|
42 |
|
|
43 |
@Override |
|
44 |
protected IStatus run(IProgressMonitor monitor) { |
|
45 |
this.runInit(monitor); |
|
46 |
try { |
|
47 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
48 |
exportToTSVFile(d, tsvFile); |
|
49 |
} catch (Exception e) { |
|
50 |
System.out.println("Error: "+e); |
|
51 |
Log.printStackTrace(e); |
|
52 |
} |
|
53 |
return Status.OK_STATUS; |
|
54 |
} |
|
55 |
}; |
|
56 |
job.schedule(); |
|
57 |
} |
|
58 |
|
|
59 |
return null; |
|
60 |
} |
|
61 |
|
|
62 |
public static Dictionary exportToTSVFile(Dictionary d, File tsvFile) throws Exception { |
|
63 |
|
|
64 |
if (d.print(tsvFile)) { |
|
65 |
return d; |
|
66 |
} |
|
67 |
return null; |
|
68 |
} |
|
69 |
} |
|
0 | 70 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/CopyDictionaries.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.AbstractHandler; |
|
4 |
import org.eclipse.core.commands.ExecutionEvent; |
|
5 |
import org.eclipse.core.commands.ExecutionException; |
|
6 |
import org.kohsuke.args4j.Option; |
|
7 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
8 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
9 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
10 |
|
|
11 |
public class CopyDictionaries extends AbstractHandler { |
|
12 |
|
|
13 |
@Option(name="orig", usage="orig dictionary name", widget="String", required=true, def="orig") |
|
14 |
public String orig = null; |
|
15 |
@Option(name="copy", usage="copy dictionary name", widget="String", required=true, def="copy") |
|
16 |
public String copy = null; |
|
17 |
|
|
18 |
@Override |
|
19 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
20 |
try { |
|
21 |
if (ParametersDialog.open(this)) { |
|
22 |
if (DictionaryManager.getInstance().hasDictionary(orig)) { |
|
23 |
Dictionary d = DictionaryManager.getInstance().getDictionary(orig); |
|
24 |
return copy(d, copy); |
|
25 |
} |
|
26 |
} |
|
27 |
|
|
28 |
return null; |
|
29 |
} catch (Exception e) { |
|
30 |
e.printStackTrace(); |
|
31 |
} |
|
32 |
return null; |
|
33 |
} |
|
34 |
|
|
35 |
public static Dictionary copy(Dictionary d, String d2) throws Exception { |
|
36 |
int n = d.makeCopy(d2); |
|
37 |
|
|
38 |
if (n == 0) System.out.println("No entry copied"); |
|
39 |
else if (n == 1) System.out.println("One entry copied."); |
|
40 |
else System.out.println(""+n+" entries copied"); |
|
41 |
|
|
42 |
return DictionaryManager.getInstance().getDictionary(d2); |
|
43 |
} |
|
44 |
} |
|
0 | 45 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/ListDictionaries.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.AbstractHandler; |
|
4 |
import org.eclipse.core.commands.ExecutionEvent; |
|
5 |
import org.eclipse.core.commands.ExecutionException; |
|
6 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
7 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
8 |
|
|
9 |
public class ListDictionaries extends AbstractHandler { |
|
10 |
|
|
11 |
@Override |
|
12 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
13 |
try { |
|
14 |
list(); |
|
15 |
} catch (Exception e) { |
|
16 |
// TODO Auto-generated catch block |
|
17 |
e.printStackTrace(); |
|
18 |
} |
|
19 |
return null; |
|
20 |
} |
|
21 |
|
|
22 |
public static Dictionary list() throws Exception { |
|
23 |
System.out.println("Tables: "+DictionaryManager.getInstance().getHSQLFunctions().getTables()); |
|
24 |
System.out.println("Dictionaries: "+DictionaryManager.getInstance().getDictionaries()); |
|
25 |
return null; |
|
26 |
} |
|
27 |
} |
|
0 | 28 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/UniqSortDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.sql.SQLException; |
|
5 |
|
|
6 |
import org.eclipse.core.commands.AbstractHandler; |
|
7 |
import org.eclipse.core.commands.ExecutionEvent; |
|
8 |
import org.eclipse.core.commands.ExecutionException; |
|
9 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
10 |
import org.eclipse.core.runtime.IStatus; |
|
11 |
import org.eclipse.core.runtime.Status; |
|
12 |
import org.kohsuke.args4j.Option; |
|
13 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
14 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
15 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
16 |
import org.txm.rcp.utils.JobHandler; |
|
17 |
import org.txm.utils.logger.Log; |
|
18 |
|
|
19 |
public class UniqSortDictionary extends AbstractHandler { |
|
20 |
|
|
21 |
@Option(name="name", usage="the dictionary name", widget="String", required=true, def="lex") |
|
22 |
public String name = null; |
|
23 |
@Option(name="tsvFile", usage="conversionFile", widget="FileSave", required=true, def="conv.tsv") |
|
24 |
public File tsvFile = null; |
|
25 |
@Option(name="col", usage="the clumn to uniqsort", widget="String", required=true, def="form") |
|
26 |
public String col = null; |
|
27 |
|
|
28 |
@Override |
|
29 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
30 |
try { |
|
31 |
if (ParametersDialog.open(this)) { |
|
32 |
if (DictionaryManager.getInstance().hasDictionary(name)) { |
|
33 |
|
|
34 |
|
|
35 |
JobHandler job = new JobHandler("UniqSort "+name) { |
|
36 |
|
|
37 |
@Override |
|
38 |
protected IStatus run(IProgressMonitor monitor) { |
|
39 |
this.runInit(monitor); |
|
40 |
try { |
|
41 |
|
|
42 |
if (!DictionaryManager.getInstance().hasDictionary(name)) { |
|
43 |
System.out.println("Error: the dictionary does exists: "+name); |
|
44 |
return Status.CANCEL_STATUS; |
|
45 |
} |
|
46 |
|
|
47 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
48 |
if (!d.getTypes().contains(col)) { |
|
49 |
System.out.println("Error: the dictionary does nto contains the given column: "+col); |
|
50 |
return Status.CANCEL_STATUS; |
|
51 |
} |
|
52 |
|
|
53 |
if (uniqsort(d, tsvFile, col) == null) { |
|
54 |
System.out.println("Error: the dictionary uniqsort failed."); |
|
55 |
return Status.CANCEL_STATUS; |
|
56 |
} |
|
57 |
|
|
58 |
return Status.OK_STATUS; |
|
59 |
|
|
60 |
} catch (Exception e) { |
|
61 |
System.out.println("Error: "+e); |
|
62 |
Log.printStackTrace(e); |
|
63 |
return Status.CANCEL_STATUS; |
|
64 |
} |
|
65 |
} |
|
66 |
}; |
|
67 |
job.schedule(); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
} catch (Exception e) { |
|
72 |
e.printStackTrace(); |
|
73 |
} |
|
74 |
return null; |
|
75 |
} |
|
76 |
|
|
77 |
public static Dictionary uniqsort(Dictionary d, File tsvFile, String col) throws Exception { |
|
78 |
if (d.uniqsort(tsvFile, col)) { |
|
79 |
return d; |
|
80 |
} |
|
81 |
return null; |
|
82 |
} |
|
83 |
} |
|
0 | 84 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/RenameColumnDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.AbstractHandler; |
|
4 |
import org.eclipse.core.commands.ExecutionEvent; |
|
5 |
import org.eclipse.core.commands.ExecutionException; |
|
6 |
import org.kohsuke.args4j.Option; |
|
7 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
8 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
9 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
10 |
|
|
11 |
public class RenameColumnDictionary extends AbstractHandler { |
|
12 |
|
|
13 |
@Option(name="name", usage="dictionary name", widget="String", required=true, def="conv.tsv") |
|
14 |
public String name = null; |
|
15 |
@Option(name="oldtype", usage="oldtype", widget="String", required=true, def="old") |
|
16 |
public String oldtype = null; |
|
17 |
@Option(name="newtype", usage="the new name", widget="String", required=true, def="new") |
|
18 |
public String newtype = null; |
|
19 |
|
|
20 |
@Override |
|
21 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
22 |
try { |
|
23 |
if (ParametersDialog.open(this)) { |
|
24 |
if (DictionaryManager.getInstance().hasDictionary(name)) { |
|
25 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
26 |
rename(d, oldtype, newtype); |
|
27 |
} |
|
28 |
} |
|
29 |
return null; |
|
30 |
} catch (Exception e) { |
|
31 |
e.printStackTrace(); |
|
32 |
} |
|
33 |
return null; |
|
34 |
} |
|
35 |
|
|
36 |
public static Dictionary rename(Dictionary d, String oldtype, String newtype) throws Exception { |
|
37 |
if (d.getTypes().contains(newtype)) { |
|
38 |
System.out.println("Column already exists: "+d.getTypes()); |
|
39 |
return d; |
|
40 |
} |
|
41 |
if (d.getTypes().contains(oldtype)) { |
|
42 |
System.out.println("The old column does not exists: "+d.getTypes()); |
|
43 |
return d; |
|
44 |
} |
|
45 |
d.renameType(oldtype, newtype); |
|
46 |
System.out.println("Type renamed="+d.getTypes()); |
|
47 |
return null; |
|
48 |
} |
|
49 |
} |
|
0 | 50 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/RemoveEntriesDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.Serializable; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.regex.Pattern; |
|
7 |
|
|
8 |
import org.eclipse.core.commands.AbstractHandler; |
|
9 |
import org.eclipse.core.commands.ExecutionEvent; |
|
10 |
import org.eclipse.core.commands.ExecutionException; |
|
11 |
import org.kohsuke.args4j.Option; |
|
12 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
13 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
14 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
15 |
|
|
16 |
public class RemoveEntriesDictionary extends AbstractHandler { |
|
17 |
|
|
18 |
@Option(name="name", usage="dictionary name", widget="String", required=true, def="conv.tsv") |
|
19 |
public String name = null; |
|
20 |
@Option(name="type", usage="type", widget="String", required=true, def="type") |
|
21 |
public String type = null; |
|
22 |
@Option(name="pattern", usage="newType", widget="String", required=true, def="reg exp pattern") |
|
23 |
public String pattern = null; |
|
24 |
|
|
25 |
@Override |
|
26 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
27 |
try { |
|
28 |
if (ParametersDialog.open(this)) { |
|
29 |
if (DictionaryManager.getInstance().hasDictionary(name)) { |
|
30 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
31 |
|
|
32 |
//Pattern p = Pattern.compile(pattern); |
|
33 |
removeEntries(d, type, pattern); |
|
34 |
} else { |
|
35 |
System.out.println("No dictionary named '"+name+"'."); |
|
36 |
} |
|
37 |
} |
|
38 |
return null; |
|
39 |
} catch (Exception e) { |
|
40 |
e.printStackTrace(); |
|
41 |
} |
|
42 |
return null; |
|
43 |
} |
|
44 |
|
|
45 |
public static Dictionary removeEntries(Dictionary d, String type, String pattern) throws Exception { |
|
46 |
int n = d.removeEntries(type, pattern); |
|
47 |
if (n == 0) System.out.println("No entry removed"); |
|
48 |
else if (n == 1) System.out.println("One entry removed."); |
|
49 |
else System.out.println(""+n+" entries removed"); |
|
50 |
return null; |
|
51 |
} |
|
52 |
} |
|
0 | 53 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/InterDictionaries.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.AbstractHandler; |
|
4 |
import org.eclipse.core.commands.ExecutionEvent; |
|
5 |
import org.eclipse.core.commands.ExecutionException; |
|
6 |
import org.kohsuke.args4j.Option; |
|
7 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
8 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
9 |
import org.txm.dictionary.functions.sql.HSQLFunctions; |
|
10 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
11 |
|
|
12 |
public class InterDictionaries extends AbstractHandler { |
|
13 |
|
|
14 |
@Option(name="first", usage="first dictionary name", widget="String", required=true, def="afrlex") |
|
15 |
public String first = null; |
|
16 |
@Option(name="second", usage="second dictionary name", widget="String", required=true, def="frolex") |
|
17 |
public String second = null; |
|
18 |
|
|
19 |
@Override |
|
20 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
21 |
try { |
|
22 |
if (ParametersDialog.open(this)) { |
|
23 |
if (DictionaryManager.getInstance().hasDictionary(first)) { |
|
24 |
System.out.println("No dictionary named: "+first); |
|
25 |
return null; |
|
26 |
} |
|
27 |
if (DictionaryManager.getInstance().hasDictionary(second)) { |
|
28 |
System.out.println("No dictionary named: "+second); |
|
29 |
return null; |
|
30 |
} |
|
31 |
|
|
32 |
if (DictionaryManager.getInstance().hasDictionary(first)) { |
|
33 |
Dictionary firstDict = DictionaryManager.getInstance().getDictionary(first); |
|
34 |
Dictionary secondDict = DictionaryManager.getInstance().getDictionary(second); |
|
35 |
return inter(firstDict, secondDict); |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
return null; |
|
40 |
} catch (Exception e) { |
|
41 |
e.printStackTrace(); |
|
42 |
} |
|
43 |
return null; |
|
44 |
} |
|
45 |
|
|
46 |
public static Object inter(Dictionary firstDict, Dictionary secondDict) throws Exception { |
|
47 |
HSQLFunctions functions = DictionaryManager.getInstance().getHSQLFunctions(); |
|
48 |
functions.printQuery("SELECT * from \""+firstDict.getName()+"\" WHERE form NOT IN (SELECT \"form\" FROM \""+secondDict+"\")"); |
|
49 |
return null; |
|
50 |
} |
|
51 |
} |
|
0 | 52 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/PrintDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.AbstractHandler; |
|
4 |
import org.eclipse.core.commands.ExecutionEvent; |
|
5 |
import org.eclipse.core.commands.ExecutionException; |
|
6 |
import org.kohsuke.args4j.Option; |
|
7 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
8 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
9 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
10 |
|
|
11 |
public class PrintDictionary extends AbstractHandler { |
|
12 |
|
|
13 |
@Option(name="name", usage="dictionary name", widget="String", required=true, def="conv.tsv") |
|
14 |
public String name = null; |
|
15 |
@Option(name="n", usage="number of line to show", widget="Integer", required=true, def="5") |
|
16 |
public int n; |
|
17 |
|
|
18 |
@Override |
|
19 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
20 |
try { |
|
21 |
if (ParametersDialog.open(this)) { |
|
22 |
if (DictionaryManager.getInstance().hasDictionary(name)) { |
|
23 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
24 |
return print(d, n); |
|
25 |
} else { |
|
26 |
System.out.println("No dictionary named="+name); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
return null; |
|
31 |
|
|
32 |
} catch (Exception e) { |
|
33 |
e.printStackTrace(); |
|
34 |
} |
|
35 |
return null; |
|
36 |
} |
|
37 |
|
|
38 |
public static Dictionary print(Dictionary d, int n) throws Exception { |
|
39 |
d.print(n); |
|
40 |
return d; |
|
41 |
} |
|
42 |
} |
|
0 | 43 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/commands/GrepDictionary.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.commands; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
|
|
5 |
import org.eclipse.core.commands.AbstractHandler; |
|
6 |
import org.eclipse.core.commands.ExecutionEvent; |
|
7 |
import org.eclipse.core.commands.ExecutionException; |
|
8 |
import org.kohsuke.args4j.Option; |
|
9 |
import org.txm.dictionary.functions.sql.Dictionary; |
|
10 |
import org.txm.dictionary.functions.sql.DictionaryManager; |
|
11 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
|
12 |
|
|
13 |
public class GrepDictionary extends AbstractHandler { |
|
14 |
|
|
15 |
@Option(name="name", usage="dictionary name", widget="String", required=true, def="lex") |
|
16 |
public String name = null; |
|
17 |
@Option(name="col", usage="column", widget="String", required=true, def="column") |
|
18 |
public String col; |
|
19 |
@Option(name="pattern", usage="pattern", widget="String", required=true, def=".+") |
|
20 |
public String pattern; |
|
21 |
|
|
22 |
@Override |
|
23 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
24 |
try { |
|
25 |
if (ParametersDialog.open(this)) { |
|
26 |
if (DictionaryManager.getInstance().hasDictionary(name)) { |
|
27 |
Dictionary d = DictionaryManager.getInstance().getDictionary(name); |
|
28 |
return grep(d, col, pattern); |
|
29 |
} else { |
|
30 |
System.out.println("No dictionary named '"+name+"'"); |
|
31 |
return -1; |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
return -1; |
|
36 |
|
|
37 |
} catch (Exception e) { |
|
38 |
e.printStackTrace(); |
|
39 |
} |
|
40 |
return null; |
|
41 |
} |
|
42 |
|
|
43 |
public static int grep(Dictionary d, String col, String pattern) throws Exception { |
|
44 |
HashMap<String, String> hash = new HashMap<String, String>(); |
|
45 |
hash.put(col, pattern); |
|
46 |
return grep(d, hash); |
|
47 |
} |
|
48 |
|
|
49 |
public static int grep(Dictionary d, HashMap<String, String> hash) throws Exception { |
|
50 |
return d.grep(hash); |
|
51 |
} |
|
52 |
} |
|
0 | 53 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/preferences/DictionaryPreferences.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.preferences; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.preferences.DefaultScope; |
|
4 |
import org.osgi.framework.FrameworkUtil; |
|
5 |
import org.osgi.service.prefs.Preferences; |
|
6 |
import org.txm.core.preferences.TXMPreferences; |
|
7 |
|
|
8 |
public class DictionaryPreferences extends TXMPreferences { |
|
9 |
|
|
10 |
public static final String PREFERENCES_NODE = FrameworkUtil.getBundle(DictionaryPreferences.class).getSymbolicName(); |
|
11 |
public static final String VERSION = "dictionary.version"; //$NON-NLS-1$ |
|
12 |
|
|
13 |
@Override |
|
14 |
public void initializeDefaultPreferences() { |
|
15 |
Preferences preferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE); |
|
16 |
preferences.put(VERSION, ""); |
|
17 |
} |
|
18 |
} |
|
0 | 19 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/functions/jpa/EntryPropertyType.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.functions.jpa; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
import javax.persistence.Entity; |
|
6 |
import javax.persistence.Id; |
|
7 |
|
|
8 |
import org.txm.dictionary.functions.jpa.EntryId; |
|
9 |
import org.txm.dictionary.functions.jpa.EntryProperty; |
|
10 |
import org.txm.dictionary.functions.jpa.EntryPropertyType; |
|
11 |
|
|
12 |
@Entity |
|
13 |
public class EntryPropertyType implements Serializable { |
|
14 |
|
|
15 |
private static final long serialVersionUID = 7511725970194453783L; |
|
16 |
|
|
17 |
@Id |
|
18 |
String id; |
|
19 |
|
|
20 |
public EntryPropertyType() { } |
|
21 |
|
|
22 |
public EntryPropertyType(String type) { |
|
23 |
this.id = type; |
|
24 |
} |
|
25 |
|
|
26 |
public String toString(){ return id;} |
|
27 |
|
|
28 |
public static void main(String[] args) { |
|
29 |
|
|
30 |
//EntryType form = new EntryType("form"); |
|
31 |
EntryPropertyType F = new EntryPropertyType("F"); |
|
32 |
EntryPropertyType msd = new EntryPropertyType("msd"); |
|
33 |
EntryPropertyType lemma = new EntryPropertyType("lemma"); |
|
34 |
|
|
35 |
EntryId je = new EntryId(); |
|
36 |
EntryId tu = new EntryId(); |
|
37 |
|
|
38 |
//EntryProperty form_je = new EntryProperty(je.id, form.id, "je"); |
|
39 |
EntryProperty F_je = new EntryProperty(je.id, F.id, 120); |
|
40 |
EntryProperty msd_je = new EntryProperty(je.id, msd.id, "S"); |
|
41 |
// EntryProperty lemma_je = new EntryProperty(je.id, lemma.id, "je"); |
|
42 |
|
|
43 |
//EntryProperty form_tu = new EntryProperty(tu.id, form.id, "tu"); |
|
44 |
EntryProperty F_tu = new EntryProperty(tu.id, F.id, 50); |
|
45 |
EntryProperty msd_tu = new EntryProperty(tu.id, msd.id, "S"); |
|
46 |
EntryProperty lemma_tu = new EntryProperty(tu.id, lemma.id, "tu"); |
|
47 |
} |
|
48 |
} |
|
0 | 49 |
tmp/org.txm.dictionary.rcp/src/org/txm/dictionary/functions/jpa/DictionaryFactory.java (revision 470) | ||
---|---|---|
1 |
package org.txm.dictionary.functions.jpa; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.util.HashMap; |
|
5 |
|
|
6 |
import org.txm.Toolbox; |
|
7 |
import org.txm.core.preferences.TBXPreferences; |
|
8 |
import org.txm.core.preferences.TXMPreferences; |
|
9 |
import org.txm.dictionary.functions.jpa.Dictionary; |
|
10 |
import org.txm.utils.logger.Log; |
|
11 |
|
|
12 |
/** |
|
13 |
* Creates Dictionaries |
|
14 |
* |
|
15 |
* @author mdecorde |
Formats disponibles : Unified diff