Révision 1488
tmp/org.txm.core/src/java/org/txm/utils/BundleUtils.java (revision 1488) | ||
---|---|---|
3 | 3 |
import java.io.File; |
4 | 4 |
import java.io.IOException; |
5 | 5 |
|
6 |
import org.eclipse.core.runtime.FileLocator; |
|
6 | 7 |
import org.eclipse.core.runtime.Platform; |
7 | 8 |
import org.osgi.framework.Bundle; |
8 | 9 |
import org.osgi.framework.Version; |
... | ... | |
41 | 42 |
if (bundle == null) { |
42 | 43 |
return null; |
43 | 44 |
} |
44 |
return bundle.getLocation(); |
|
45 |
try { |
|
46 |
return FileLocator.getBundleFile(bundle).getAbsolutePath(); |
|
47 |
} catch (IOException e) { |
|
48 |
// TODO Auto-generated catch block |
|
49 |
e.printStackTrace(); |
|
50 |
return "error path "+bundle_id; |
|
51 |
} |
|
52 |
//return bundle.getLocation(); |
|
45 | 53 |
} |
46 | 54 |
|
47 | 55 |
/** |
48 | 56 |
* |
49 | 57 |
* @param bundle_id the Bundle ID |
50 |
* @return the absolute File to the bundle directory. The File is a directory or a file.
|
|
58 |
* @return the relative path to the bundle directory
|
|
51 | 59 |
*/ |
52 | 60 |
public static File getBundleFile(String bundle_id) { |
53 |
Log.info("Retrieving file_path from "+bundle_id+" plugin."); |
|
54 | 61 |
Bundle bundle = Platform.getBundle(bundle_id); |
55 | 62 |
if (bundle == null) { |
56 |
System.out.println("Error while initializing '"+bundle_id+"' plugin: bundle not found."); |
|
57 | 63 |
return null; |
58 | 64 |
} |
59 |
String bundleLocation = bundle.getLocation(); |
|
60 |
String eclipseHomeLocation = System.getProperty("eclipse.home.location"); |
|
61 |
|
|
62 |
int idx = bundleLocation.lastIndexOf(":"); |
|
63 |
if (idx > 0) bundleLocation = bundleLocation.substring(idx + 1); |
|
64 |
|
|
65 |
idx = eclipseHomeLocation.indexOf("file:"); |
|
66 |
if (idx == 0) eclipseHomeLocation = eclipseHomeLocation.substring(5); |
|
67 |
|
|
68 |
File bundleDir = new File(bundleLocation); |
|
69 |
if (bundleLocation.startsWith("/")) { |
|
70 |
bundleDir = new File(bundleLocation); |
|
71 |
} else { |
|
72 |
bundleDir = new File(eclipseHomeLocation, bundleLocation); |
|
65 |
try { |
|
66 |
return FileLocator.getBundleFile(bundle).getAbsoluteFile(); |
|
67 |
} catch (IOException e) { |
|
68 |
// TODO Auto-generated catch block |
|
69 |
e.printStackTrace(); |
|
70 |
return null; |
|
73 | 71 |
} |
74 |
|
|
75 |
return bundleDir; |
|
72 |
//return bundle.getLocation(); |
|
76 | 73 |
} |
77 | 74 |
|
75 |
// /** |
|
76 |
// * |
|
77 |
// * @param bundle_id the Bundle ID |
|
78 |
// * @return the absolute File to the bundle directory. The File is a directory or a file. |
|
79 |
// */ |
|
80 |
// public static File getBundleFile(String bundle_id) { |
|
81 |
// Log.info("Retrieving file_path from "+bundle_id+" plugin."); |
|
82 |
// Bundle bundle = Platform.getBundle(bundle_id); |
|
83 |
// if (bundle == null) { |
|
84 |
// System.out.println("Error while initializing '"+bundle_id+"' plugin: bundle not found."); |
|
85 |
// return null; |
|
86 |
// } |
|
87 |
// String bundleLocation = bundle.getLocation(); |
|
88 |
// String eclipseHomeLocation = System.getProperty("eclipse.home.location"); |
|
89 |
// |
|
90 |
// int idx = bundleLocation.lastIndexOf(":"); |
|
91 |
// if (idx > 0) bundleLocation = bundleLocation.substring(idx + 1); |
|
92 |
// |
|
93 |
// idx = eclipseHomeLocation.indexOf("file:"); |
|
94 |
// if (idx == 0) eclipseHomeLocation = eclipseHomeLocation.substring(5); |
|
95 |
// |
|
96 |
// File bundleDir = new File(bundleLocation); |
|
97 |
// if (bundleLocation.startsWith("/")) { |
|
98 |
// bundleDir = new File(bundleLocation); |
|
99 |
// } else { |
|
100 |
// bundleDir = new File(eclipseHomeLocation, bundleLocation); |
|
101 |
// } |
|
102 |
// |
|
103 |
// return bundleDir; |
|
104 |
// } |
|
105 |
|
|
78 | 106 |
/** |
79 | 107 |
* Copy a file from the bundle directory or Jar to @outputDirectory |
80 | 108 |
* |
... | ... | |
93 | 121 |
if (file_path.length() > 0 && !file_path.endsWith("/")) file_path += "/"; |
94 | 122 |
|
95 | 123 |
File bundleDir = getBundleFile(bundle_id); |
96 |
String bundleLocation = getBundleLocation(bundle_id); |
|
97 | 124 |
File outfile = new File(outputDirectory, file_name); |
98 | 125 |
|
99 | 126 |
if (bundleDir.isDirectory()) { // TXM is run from Eclipse or we've decided to ship the Toolbox plugin in a directory |
... | ... | |
129 | 156 |
if (!file_path.endsWith("/")) file_path += "/"; |
130 | 157 |
|
131 | 158 |
File bundleDir = getBundleFile(bundle_id); |
132 |
String bundleLocation = getBundleLocation(bundle_id); |
|
159 |
// String bundleLocation = getBundleLocation(bundle_id);
|
|
133 | 160 |
|
134 | 161 |
if (bundleDir.isDirectory()) { // TXM is run from Eclipse or we've decided to ship the Toolbox plugin in a directory |
135 | 162 |
File fileInToolbox = new File(bundleDir, file_path+file_name); |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/bfm/bfmLoader.groovy (revision 1488) | ||
---|---|---|
132 | 132 |
|
133 | 133 |
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); } |
134 | 134 |
if (MONITOR != null) MONITOR.worked(20, "ANNOTATE") |
135 |
println "-- ANNOTATE - Running NLP tools - $model model" |
|
135 |
|
|
136 | 136 |
boolean annotate_status = true; |
137 | 137 |
if (annotate) { |
138 |
println "-- ANNOTATE - Running NLP tools - $model model" |
|
138 | 139 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
139 | 140 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
140 | 141 |
annotate_status = true; |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/doc/docLoader.groovy (revision 1488) | ||
---|---|---|
253 | 253 |
|
254 | 254 |
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); } |
255 | 255 |
if (MONITOR != null) MONITOR.worked(20, "ANNOTATE") |
256 |
println "-- ANNOTATE - Running NLP tools" |
|
256 |
|
|
257 | 257 |
boolean annotationSuccess = false; |
258 | 258 |
if (annotate) { |
259 |
println "-- ANNOTATE - Running NLP tools" |
|
259 | 260 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
260 | 261 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
261 | 262 |
annotationSuccess = true; |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/tmx/tmxLoader.groovy (revision 1488) | ||
---|---|---|
83 | 83 |
def imp = new importer() |
84 | 84 |
imp.run(srcDir, binDir, txmDir, textLangs, langGroups); |
85 | 85 |
def corpusIDS = imp.getCorpusIDS() |
86 |
println "-- ANNOTATE - Running NLP tools" |
|
86 |
|
|
87 | 87 |
if (MONITOR != null) MONITOR.worked(20, "ANNOTATE - Running NLP tools"); |
88 | 88 |
if (annotate) { |
89 |
println "-- ANNOTATE - Running NLP tools" |
|
89 | 90 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
90 | 91 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
91 | 92 |
annotationSuccess = true; |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/factiva/factivaLoader.groovy (revision 1488) | ||
---|---|---|
210 | 210 |
|
211 | 211 |
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); } |
212 | 212 |
if (MONITOR != null) MONITOR.worked(10, "ANNOTATE") |
213 |
println "-- ANNOTATE - Running NLP tools" |
|
213 |
|
|
214 | 214 |
boolean annotationSuccess = false; |
215 | 215 |
if (annotate) { |
216 |
println "-- ANNOTATE - Running NLP tools" |
|
216 | 217 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
217 | 218 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
218 | 219 |
annotationSuccess = true; |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/factiva/factivamailLoader.groovy (revision 1488) | ||
---|---|---|
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
if (MONITOR != null) MONITOR.worked(20, "ANNOTATE") |
95 |
println "-- ANNOTATE - Running NLP tools" |
|
95 |
|
|
96 | 96 |
boolean annotationSuccess = false; |
97 | 97 |
if (annotate) { |
98 |
println "-- ANNOTATE - Running NLP tools" |
|
98 | 99 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
99 | 100 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
100 | 101 |
annotationSuccess = true; |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/transcriber/transcriberLoader.groovy (revision 1488) | ||
---|---|---|
220 | 220 |
|
221 | 221 |
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); } |
222 | 222 |
if (MONITOR != null) MONITOR.worked(20, "ANNOTATE") |
223 |
println "-- ANNOTATE - Running NLP tools" |
|
223 |
|
|
224 | 224 |
boolean annotationSuccess = false; |
225 | 225 |
if (annotate) { |
226 |
println "-- ANNOTATE - Running NLP tools" |
|
226 | 227 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
227 | 228 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
228 | 229 |
annotationSuccess = true; |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/txt/txtLoader.groovy (revision 1488) | ||
---|---|---|
124 | 124 |
println "" |
125 | 125 |
} |
126 | 126 |
|
127 |
println "-- ANNOTATE - Running NLP tools" |
|
127 |
|
|
128 | 128 |
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); } |
129 | 129 |
if (MONITOR != null) MONITOR.worked(20, "ANNOTATE - Running NLP tools") |
130 | 130 |
boolean annotationSuccess = true; |
131 | 131 |
if (annotate) { |
132 |
println "-- ANNOTATE - Running NLP tools" |
|
132 | 133 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
133 | 134 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
134 | 135 |
annotationSuccess = true; |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/alceste/alcesteLoader.groovy (revision 1488) | ||
---|---|---|
85 | 85 |
|
86 | 86 |
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); } |
87 | 87 |
if (MONITOR != null) MONITOR.worked(20, "ANNOTATE") |
88 |
println "-- ANNOTATE - Running NLP tools" |
|
88 |
|
|
89 | 89 |
boolean annotationSuccess = false; |
90 | 90 |
|
91 | 91 |
if (annotate) { |
92 |
println "-- ANNOTATE - Running NLP tools" |
|
92 | 93 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
93 | 94 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
94 | 95 |
annotationSuccess = true; |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/frantext/frantextLoader.groovy (revision 1488) | ||
---|---|---|
152 | 152 |
|
153 | 153 |
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); } |
154 | 154 |
if (MONITOR != null) MONITOR.worked(20, "ANNOTATE") |
155 |
println "-- ANNOTATE - Running NLP tools - $model model" |
|
155 |
|
|
156 | 156 |
boolean annotate_status = true; |
157 | 157 |
if (annotate) { |
158 |
println "-- ANNOTATE - Running NLP tools - $model model" |
|
158 | 159 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
159 | 160 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
160 | 161 |
annotate_status = true; |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xml/xmlLoader.groovy (revision 1488) | ||
---|---|---|
218 | 218 |
|
219 | 219 |
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); } |
220 | 220 |
if (MONITOR != null) MONITOR.worked(20, "ANNOTATE") |
221 |
println "-- ANNOTATE - Running NLP tools" |
|
221 |
|
|
222 | 222 |
boolean annotationSuccess = false; |
223 | 223 |
if (annotate) { |
224 |
println "-- ANNOTATE - Running NLP tools" |
|
224 | 225 |
def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger") |
225 | 226 |
if (engine.processDirectory(txmDir, binDir, ["lang":model])) { |
226 | 227 |
annotationSuccess = true; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/ImportSelectedText.java (revision 1488) | ||
---|---|---|
48 | 48 |
import org.txm.rcp.handlers.scripts.ExecuteImportScript; |
49 | 49 |
import org.txm.rcp.messages.TXMUIMessages; |
50 | 50 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
51 |
import org.txm.treetagger.core.preferences.TreeTaggerPreferences; |
|
51 | 52 |
import org.txm.utils.LangDetector; |
52 | 53 |
|
53 | 54 |
/** |
... | ... | |
153 | 154 |
project.setLang(lang); //$NON-NLS-1$ |
154 | 155 |
System.out.println(TXMCoreMessages.bind(TXMUIMessages.usingLanguage, project.getLang())); |
155 | 156 |
|
157 |
String ttpath = TreeTaggerPreferences.getInstance().getString(TreeTaggerPreferences.INSTALL_PATH); |
|
158 |
|
|
159 |
if (ttpath != null && ttpath.length() > 0 && new File(ttpath, "bin").isDirectory()) { |
|
160 |
project.setAnnotate(true); |
|
161 |
} |
|
162 |
|
|
156 | 163 |
ExecuteImportScript.executeScript(project); |
157 | 164 |
return null; |
158 | 165 |
} |
tmp/org.txm.treetagger.files.feature/feature.xml (revision 1488) | ||
---|---|---|
69 | 69 |
|
70 | 70 |
<requires> |
71 | 71 |
<import plugin="org.txm.treetagger.core" version="1.0.0" match="greaterOrEqual"/> |
72 |
<import feature="org.txm.treetagger.binaries.feature" version="1.0.0.qualifier"/> |
|
72 | 73 |
</requires> |
73 | 74 |
|
74 | 75 |
<plugin |
tmp/org.txm.treetagger.core/src/org/txm/treetagger/core/preferences/TreeTaggerPreferences.java (revision 1488) | ||
---|---|---|
157 | 157 |
Version binariesFragmentVersion = BundleUtils.getBundleVersion(bfragmentid); |
158 | 158 |
if (binariesFragmentVersion != null && binariesFragmentVersion.compareTo(currentBVersion) >= 0) { // udpate binaries path ! |
159 | 159 |
System.out.print("Updating TreeTagger binaries path..."); |
160 |
try { |
|
161 |
URL dir = new URL(BundleUtils.getBundleLocation(bfragmentid)); |
|
162 |
String path = dir.getPath(); |
|
160 |
String path = BundleUtils.getBundleLocation(bfragmentid); |
|
163 | 161 |
if (path.startsWith("file:")) path = path.substring(5); |
164 | 162 |
File binariesDir = new File(path, "res/"+osname); |
165 | 163 |
new File(binariesDir, "bin/separate-punctuation").setExecutable(true); // linux&mac |
... | ... | |
168 | 166 |
preferences.put(INSTALL_PATH, binariesDir.getAbsolutePath()); |
169 | 167 |
TreeTaggerPreferences.getInstance().put(INSTALLED_BINARIES_VERSION, binariesFragmentVersion.toString()); |
170 | 168 |
System.out.println("Done."); |
171 |
} catch (MalformedURLException e) { |
|
172 |
// TODO Auto-generated catch block |
|
173 |
e.printStackTrace(); |
|
174 |
} |
|
175 | 169 |
} |
176 | 170 |
|
177 | 171 |
Version modelsFragmentVersion = BundleUtils.getBundleVersion(mfragmentid); |
178 | 172 |
if (modelsFragmentVersion != null && modelsFragmentVersion.compareTo(currentMVersion) >= 0) { // udpate models path! |
179 | 173 |
System.out.print("Updating TreeTagger models path..."); |
180 |
try { |
|
181 |
URL dir = new URL(BundleUtils.getBundleLocation(mfragmentid)); |
|
182 |
String path = dir.getPath(); |
|
174 |
String path = BundleUtils.getBundleLocation(mfragmentid); |
|
183 | 175 |
if (path.startsWith("file:")) path = path.substring(5); |
184 | 176 |
File modelsDir = new File(path, "res/models"); |
185 | 177 |
preferences.put(MODELS_PATH, modelsDir.getAbsolutePath()); //$NON-NLS-1$ |
186 | 178 |
TreeTaggerPreferences.getInstance().put(INSTALLED_MODELS_VERSION, modelsFragmentVersion.toString()); |
187 | 179 |
System.out.println("Done."); |
188 |
} catch (MalformedURLException e) { |
|
189 |
// TODO Auto-generated catch block |
|
190 |
e.printStackTrace(); |
|
191 |
} |
|
192 | 180 |
} |
193 | 181 |
} |
194 | 182 |
} |
Formats disponibles : Unified diff