Révision 3187
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ExporterIdentifiantsSujetsMacro.groovy (revision 3187) | ||
---|---|---|
1 |
// Copyright © 2021 ENS-LYON |
|
2 |
// Licensed under the terms of the GNU General Public License version 3 (http://www.gnu.org/licenses/gpl-3.0.html) |
|
3 |
// @author mdecorde |
|
4 |
|
|
5 |
// STANDARD DECLARATIONS |
|
6 |
package org.txm.macro.projects.antract |
|
7 |
|
|
8 |
import org.txm.searchengine.cqp.corpus.CQPCorpus |
|
9 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery |
|
10 |
import org.txm.searchengine.cqp.CQPSearchEngine |
|
11 |
|
|
12 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
13 |
println "Erreur: la sélection n'est pas un corpus." |
|
14 |
return false |
|
15 |
} |
|
16 |
|
|
17 |
CQPCorpus corpus = corpusViewSelection |
|
18 |
corpus.compute() |
|
19 |
CQPCorpus parentCorpus = corpus.getMainCorpus() |
|
20 |
|
|
21 |
String parentCorpusName = parentCorpus.getCqpId() |
|
22 |
|
|
23 |
def struct_prop = null |
|
24 |
def finalValues = [] |
|
25 |
def ids = null |
|
26 |
|
|
27 |
if (parentCorpusName.startsWith("AF-VOIX-OFF-")) { |
|
28 |
|
|
29 |
struct_prop = corpus.getStructuralUnit("div").getProperty("id") |
|
30 |
values = struct_prop.getValues(corpus) |
|
31 |
for (def id : values) { |
|
32 |
if (id.startsWith("AFE")) { |
|
33 |
finalValues << id |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
38 |
|
|
39 |
struct_prop = corpus.getStructuralUnit("notice").getProperty("identifiantdelanotice") |
|
40 |
def values = struct_prop.getValues(corpus) |
|
41 |
|
|
42 |
def struct_prop2 = corpus.getStructuralUnit("notice").getProperty("typedenotice") |
|
43 |
def qr = corpus.query(new CQLQuery("<notice_typedenotice=\"Notice sujet\">[]"), "TMP", false) |
|
44 |
int[] positions = qr.getStarts() |
|
45 |
int[] strucs = CQPSearchEngine.getCqiClient().cpos2Struc(struct_prop2.getQualifiedName(), positions) |
|
46 |
String sujetsIDS = CQPSearchEngine.getCqiClient().struc2Str(struct_prop.getQualifiedName(), strucs) |
|
47 |
for (String id : values) { |
|
48 |
int idx = sujetsIDS.indexOf(id) |
|
49 |
if (idx > 0) { |
|
50 |
finalValues << id // this id is actually in the sujetsIDS |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
} else { |
|
55 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
56 |
return false |
|
57 |
} |
|
58 |
|
|
59 |
ids = finalValues.sort().join("|") |
|
60 |
|
|
61 |
println "Liste des identifiants (${finalValues.size()}) : "+ids |
|
62 |
|
|
63 |
monitor.syncExec(new Runnable() { |
|
64 |
public void run() { |
|
65 |
IOClipboard.write(ids) |
|
66 |
} |
|
67 |
}) |
|
68 |
|
|
69 |
return ids |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ExporterLeCorpusVersOkapiMacro.groovy (revision 3187) | ||
---|---|---|
1 |
// Copyright © 2021 ENS-LYON |
|
2 |
// Licensed under the terms of the GNU General Public License version 3 (http://www.gnu.org/licenses/gpl-3.0.html) |
|
3 |
// @author mdecorde |
|
4 |
|
|
5 |
// STANDARD DECLARATIONS |
|
6 |
package org.txm.macro.projects.antract |
|
7 |
|
|
8 |
import org.txm.searchengine.cqp.corpus.CQPCorpus |
|
9 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery |
|
10 |
import org.txm.macro.projects.antract.OkapiSaphirAPI |
|
11 |
import org.txm.searchengine.cqp.CQPSearchEngine |
|
12 |
|
|
13 |
import org.txm.backtomedia.preferences.BackToMediaPreferences |
|
14 |
|
|
15 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
16 |
println "Erreur: la sélection n'est pas un corpus." |
|
17 |
return false |
|
18 |
} |
|
19 |
|
|
20 |
@Field @Option(name="titre_du_nouveau_corpus_okapi", usage="Nom du corpus à créer", widget="String", required=false, def="") |
|
21 |
def titre_du_nouveau_corpus_okapi |
|
22 |
|
|
23 |
if (!ParametersDialog.open(this)) return; |
|
24 |
|
|
25 |
CQPCorpus corpus = corpusViewSelection |
|
26 |
corpus.compute() |
|
27 |
CQPCorpus parentCorpus = corpus.getMainCorpus() |
|
28 |
|
|
29 |
String parentCorpusName = parentCorpus.getCqpId() |
|
30 |
|
|
31 |
def struct_prop = null |
|
32 |
def finalValues = [] |
|
33 |
def ids = null |
|
34 |
|
|
35 |
if (parentCorpusName.startsWith("AF-VOIX-OFF-")) { |
|
36 |
ids = gse.run(ExporterIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
37 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
38 |
ids = gse.run(ExporterIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
39 |
} else { |
|
40 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
41 |
return false |
|
42 |
} |
|
43 |
|
|
44 |
if (!OkapiSaphirAPI.initializeCredentials(BackToMediaPreferences.MEDIA_AUTH_LOGIN, BackToMediaPreferences.MEDIA_AUTH_PASSWORD, |
|
45 |
"OKAPI - Antract", "You must authenticate to access the okapi corpus API", "OKAPI - Antract", monitor)) { |
|
46 |
println "Cancel corpus export" |
|
47 |
return null; |
|
48 |
} |
|
49 |
|
|
50 |
String user = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN) |
|
51 |
String password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD) |
|
52 |
|
|
53 |
String sessionID = OkapiSaphirAPI.login(user, password) |
|
54 |
if (sessionID.length() > 0) { |
|
55 |
String corpusID = OkapiSaphirAPI.create_corpus(sessionID, titre_du_nouveau_corpus_okapi, ids) |
|
56 |
if (sessionID.length() > 0 && sessionID.startsWith("http")) { |
|
57 |
println "New Okapi corpus $titre_du_nouveau_corpus_okapi created: "+corpusID |
|
58 |
} else { |
|
59 |
println "Error: Okapi corpus not created: "+corpusID |
|
60 |
} |
|
61 |
} else { |
|
62 |
println "Error: Okapi session not started. Resetting credentials." |
|
63 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, "") |
|
64 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "") |
|
65 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ListerIdentifiantsSujetsMacro.groovy (revision 3187) | ||
---|---|---|
1 |
// Copyright © 2021 ENS-LYON |
|
2 |
// Licensed under the terms of the GNU General Public License version 3 (http://www.gnu.org/licenses/gpl-3.0.html) |
|
3 |
// @author mdecorde |
|
4 |
|
|
5 |
// STANDARD DECLARATIONS |
|
6 |
package org.txm.macro.projects.antract |
|
7 |
|
|
8 |
import org.txm.searchengine.cqp.corpus.CQPCorpus |
|
9 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery |
|
10 |
import org.txm.searchengine.cqp.CQPSearchEngine |
|
11 |
|
|
12 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
13 |
println "Erreur: la sélection n'est pas un corpus." |
|
14 |
return false |
|
15 |
} |
|
16 |
|
|
17 |
CQPCorpus corpus = corpusViewSelection |
|
18 |
corpus.compute() |
|
19 |
CQPCorpus parentCorpus = corpus.getMainCorpus() |
|
20 |
|
|
21 |
String parentCorpusName = parentCorpus.getCqpId() |
|
22 |
|
|
23 |
def struct_prop = null |
|
24 |
def finalValues = [] |
|
25 |
def ids = null |
|
26 |
|
|
27 |
if (parentCorpusName.startsWith("AF-VOIX-OFF-")) { |
|
28 |
|
|
29 |
struct_prop = corpus.getStructuralUnit("div").getProperty("id") |
|
30 |
values = struct_prop.getValues(corpus) |
|
31 |
for (def id : values) { |
|
32 |
if (id.startsWith("AFE")) { |
|
33 |
finalValues << id |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
38 |
|
|
39 |
struct_prop = corpus.getStructuralUnit("notice").getProperty("identifiantdelanotice") |
|
40 |
def values = struct_prop.getValues(corpus) |
|
41 |
|
|
42 |
def struct_prop2 = corpus.getStructuralUnit("notice").getProperty("typedenotice") |
|
43 |
def qr = corpus.query(new CQLQuery("<notice_typedenotice=\"Notice sujet\">[]"), "TMP", false) |
|
44 |
int[] positions = qr.getStarts() |
|
45 |
int[] strucs = CQPSearchEngine.getCqiClient().cpos2Struc(struct_prop2.getQualifiedName(), positions) |
|
46 |
String sujetsIDS = CQPSearchEngine.getCqiClient().struc2Str(struct_prop.getQualifiedName(), strucs) |
|
47 |
for (String id : values) { |
|
48 |
int idx = sujetsIDS.indexOf(id) |
|
49 |
if (idx > 0) { |
|
50 |
finalValues << id // this id is actually in the sujetsIDS |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
} else { |
|
55 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
56 |
return false |
|
57 |
} |
|
58 |
|
|
59 |
ids = finalValues.sort().join("|") |
|
60 |
|
|
61 |
println "Liste des identifiants (${finalValues.size()}) : "+ids |
|
62 |
|
|
63 |
monitor.syncExec(new Runnable() { |
|
64 |
public void run() { |
|
65 |
IOClipboard.write(ids) |
|
66 |
} |
|
67 |
}) |
|
68 |
|
|
69 |
return ids |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/OkapiSaphirAPI.groovy (revision 3187) | ||
---|---|---|
11 | 11 |
import java.net.URLEncoder; |
12 | 12 |
import java.util.List; |
13 | 13 |
import java.util.Map; |
14 |
import javax.ws.rs.core.UriBuilder |
|
14 | 15 |
|
15 | 16 |
import org.eclipse.swt.widgets.Display; |
16 | 17 |
import org.eclipse.swt.widgets.Shell; |
... | ... | |
25 | 26 |
|
26 | 27 |
public static final String baseUrl = "https://okapi.ina.fr/antract/api/saphir/"; |
27 | 28 |
public static final String okapiUrl = "https://okapi.ina.fr/antract/html/resource_587884135/resource_996999332.html"; |
29 |
|
|
28 | 30 |
public static boolean debug = true; |
29 | 31 |
|
32 |
public static String getDirectAccessURL(String id) { |
|
33 |
return OkapiSaphirAPI.okapiUrl+"?linkedObjectUri="+URLEncoder.encode(id, "UTF-8") |
|
34 |
} |
|
35 |
|
|
30 | 36 |
public static String login(String user, String password) { |
31 | 37 |
URL url1; |
32 | 38 |
try { |
... | ... | |
46 | 52 |
} |
47 | 53 |
|
48 | 54 |
String sessionID = getOkapiSessionID(conn) |
55 |
String content1 = getContent(conn); |
|
56 |
if (debug) { |
|
57 |
println "content="+content1 |
|
58 |
println "sessionID="+sessionID |
|
59 |
} |
|
60 |
|
|
49 | 61 |
if (sessionID.length() == 0) { |
50 | 62 |
if (debug) System.out.println("Error: not connected no session ID found"); |
51 | 63 |
return ""; |
52 | 64 |
} |
53 | 65 |
|
54 |
String content1 = getContent(conn); |
|
55 | 66 |
if (!content1.contains("Welcome "+user)) { |
56 | 67 |
if (debug) System.out.println("Error: not connected, welcome message not found: "+content1); |
57 | 68 |
return ""; |
... | ... | |
67 | 78 |
} |
68 | 79 |
} |
69 | 80 |
|
81 |
|
|
82 |
|
|
70 | 83 |
public static String update_corpus(String sessionID, String corpusID, String ids) { |
71 | 84 |
return create_or_update_corpus(sessionID, corpusID, null, ids); |
72 | 85 |
} |
... | ... | |
75 | 88 |
return create_or_update_corpus(sessionID, null, title, ids); |
76 | 89 |
} |
77 | 90 |
|
78 |
public static String create_or_update_corpus(String sessionID, String corpusID, String title, String ids) {
|
|
91 |
protected static String create_or_update_corpus(String sessionID, String corpusID, String title, String ids) {
|
|
79 | 92 |
URL url2; |
80 | 93 |
String action = ""; |
81 | 94 |
try { |
... | ... | |
93 | 106 |
return ""; |
94 | 107 |
} |
95 | 108 |
|
96 |
url2 = new URL(baseUrl+"create_corpus"); |
|
109 |
if (action == "create") { |
|
110 |
url2 = new URL(baseUrl+"create_corpus?title="+URLEncoder.encode(title, "UTF-8")); |
|
111 |
} else if (action == "update") { |
|
112 |
url2 = new URL(baseUrl+"create_corpus?uri="+URLEncoder.encode(corpusID, "UTF-8")); |
|
113 |
} |
|
97 | 114 |
|
98 | 115 |
if (debug) System.out.println("Requesting: "+action+" : "+url2); |
99 | 116 |
HttpURLConnection conn2 = (HttpURLConnection) url2.openConnection(); |
100 |
conn2.setRequestMethod("POST");
|
|
117 |
conn2.setRequestProperty("content-type", "text/plain; charset=UTF-8");
|
|
101 | 118 |
conn2.setRequestProperty("session", sessionID); |
102 |
|
|
119 |
conn2.setDoOutput(true); |
|
120 |
|
|
103 | 121 |
if (debug) System.out.println("Writing POST..."); |
104 | 122 |
|
105 |
conn2.setDoOutput(true); |
|
106 | 123 |
DataOutputStream wr = new DataOutputStream(conn2.getOutputStream()); |
107 |
String str = "" |
|
108 |
if (action == "create") { |
|
109 |
str += "title="+title |
|
110 |
} else if (action == "update") { |
|
111 |
str += "uri="+corpusID |
|
112 |
} |
|
113 |
str += "&content="+ids |
|
114 |
if (debug) println "POST="+str |
|
115 |
wr.writeBytes(str); |
|
124 |
|
|
125 |
if (debug) println "POST="+URLEncoder.encode(ids, "UTF-8") |
|
126 |
wr.writeBytes(ids); |
|
116 | 127 |
wr.flush(); |
117 | 128 |
wr.close(); |
118 |
|
|
119 |
conn2.connect() |
|
120 | 129 |
|
121 | 130 |
if (debug) System.out.println("getResponseCode..."); |
122 | 131 |
int code2 = conn2.getResponseCode(); |
123 | 132 |
if (code2 != HttpURLConnection.HTTP_OK) { |
124 |
if (debug) System.out.println("Error: during corpus "+action+" error='"+code2+"' and command="+url2);
|
|
133 |
if (debug) System.out.println("Error: during corpus "+action+" error='"+code2+"', command="+url2+", post="+URLEncoder.encode(ids, "UTF-8"));
|
|
125 | 134 |
return ""; |
126 | 135 |
} |
127 | 136 |
if (debug) System.out.println("getContent..."); |
128 |
String content2 = getContent(conn2); |
|
137 |
String content2 = getContent(conn2).trim(); |
|
138 |
if (content2.startsWith("\"") && content2.endsWith("\"")) { |
|
139 |
content2 = content2.substring(1, content2.length() -1) |
|
140 |
} |
|
129 | 141 |
|
130 | 142 |
conn2.disconnect(); |
131 | 143 |
|
... | ... | |
254 | 266 |
} |
255 | 267 |
|
256 | 268 |
//TODO remove this and call UsernamePasswordDialog.initializeCredentials |
257 |
public static boolean initializeCredentials(String userKey, String passwordKey, String target, String title, String details) { |
|
269 |
public static boolean initializeCredentials(Shell shell, String userKey, String passwordKey, String target, String title, String details) {
|
|
258 | 270 |
|
259 | 271 |
if (System.getProperty(userKey) == null |
260 |
|| System.getProperty(passwordKey) == null) { |
|
272 |
|| System.getProperty(passwordKey) == null |
|
273 |
|| System.getProperty(userKey).length() == 0 |
|
274 |
|| System.getProperty(passwordKey).length() == 0) { |
|
261 | 275 |
|
262 |
Shell shell = Display.getCurrent().getActiveShell(); |
|
263 |
if (shell == null) { |
|
264 |
System.out.println("Error: could not open crendetial dialog on current Thread."); |
|
265 |
return false; |
|
266 |
} |
|
267 |
|
|
268 | 276 |
UsernamePasswordDialog dialog = new UsernamePasswordDialog(shell, [userKey != null, passwordKey != null ] as boolean[], target); |
269 | 277 |
if (userKey != null) dialog.setUsername(System.getProperty(userKey)); |
270 | 278 |
dialog.setTitle(title); |
... | ... | |
283 | 291 |
} |
284 | 292 |
|
285 | 293 |
//TODO remove this and call UsernamePasswordDialog.initializeCredentials |
286 |
public static boolean initializeCredentials(String userKey, String passwordKey, String target, String title, String details, JobHandler monitor) { |
|
294 |
public static boolean initializeCredentials(Shell shell, String userKey, String passwordKey, String target, String title, String details, JobHandler monitor) {
|
|
287 | 295 |
|
288 | 296 |
final def ret = [false] |
289 | 297 |
|
... | ... | |
291 | 299 |
public void run() { |
292 | 300 |
System.out.println("Opening credential dialog..."); |
293 | 301 |
try { |
294 |
ret[0] = initializeCredentials(userKey, passwordKey, target, title, details); |
|
302 |
ret[0] = initializeCredentials(shell, userKey, passwordKey, target, title, details);
|
|
295 | 303 |
} catch(Throwable t) { |
296 | 304 |
t.printStackTrace(); |
297 | 305 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ImporterUnCorpusOkapiMacro.groovy (revision 3187) | ||
---|---|---|
1 |
// Copyright © 2021 MY_INSTITUTION |
|
2 |
// Licensed under the terms of the GNU General Public License version 3 (http://www.gnu.org/licenses/gpl-3.0.html) |
|
3 |
// @author mdecorde |
|
4 |
|
|
5 |
// STANDARD DECLARATIONS |
|
6 |
package org.txm.macro |
|
7 |
|
|
8 |
import org.kohsuke.args4j.* |
|
9 |
import groovy.transform.Field |
|
10 |
import org.txm.rcp.swt.widget.parameters.* |
|
11 |
import org.txm.searchengine.cqp.corpus.CQPCorpus |
|
12 |
import org.txm.searchengine.cqp.corpus.Subcorpus |
|
13 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery |
|
14 |
import org.txm.rcp.views.corpora.CorporaView |
|
15 |
|
|
16 |
// BEGINNING OF PARAMETERS |
|
17 |
|
|
18 |
@Field @Option(name="name", usage="Nom du sous-corpus à créer", widget="String", required=true, def="") |
|
19 |
def name |
|
20 |
@Field @Option(name="identifiants", usage="Liste des identifiants de notice séparés par des '|'", widget="Text", required=true, def="") |
|
21 |
def identifiants |
|
22 |
|
|
23 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
24 |
println "Erreur: la sélection n'est pas un corpus." |
|
25 |
return false |
|
26 |
} |
|
27 |
|
|
28 |
CQPCorpus corpus = corpusViewSelection |
|
29 |
corpus.compute() |
|
30 |
CQPCorpus parentCorpus = corpus.getMainCorpus() |
|
31 |
|
|
32 |
String parentCorpusName = parentCorpus.getCqpId() |
|
33 |
|
|
34 |
if (parentCorpusName.startsWith("AF-VOIX-OFF-")) { |
|
35 |
|
|
36 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
37 |
|
|
38 |
} else { |
|
39 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
40 |
return false |
|
41 |
} |
|
42 |
|
|
43 |
// Open the parameters input dialog box |
|
44 |
if (!ParametersDialog.open(this)) return; |
|
45 |
|
|
46 |
println "Création du sous-corpus avec la liste: $identifiants" |
|
47 |
String prop = "div_id" |
|
48 |
if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
49 |
prop = "notice_identifiantdelanotice" |
|
50 |
} |
|
51 |
|
|
52 |
String query = "[_.$prop=\"$identifiants\"] expand to $prop" |
|
53 |
println "Query=$query" |
|
54 |
Subcorpus sub = parentCorpus.createSubcorpus(new CQLQuery(query), name) |
|
55 |
|
|
56 |
int s = sub.getSize() |
|
57 |
if (s > 0) { |
|
58 |
println "$name subcorpus is created." |
|
59 |
monitor.syncExec(new Runnable() { |
|
60 |
public void run() { |
|
61 |
CorporaView.refresh(); |
|
62 |
CorporaView.expand(parentCorpus); |
|
63 |
} |
|
64 |
}); |
|
65 |
} else { |
|
66 |
println "Error: the created corpus is empty!" |
|
67 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ExporterSousCorpusSujetsDansOkapiMacro.groovy (revision 3187) | ||
---|---|---|
1 |
// Copyright © 2021 ENS-LYON |
|
2 |
// Licensed under the terms of the GNU General Public License version 3 (http://www.gnu.org/licenses/gpl-3.0.html) |
|
3 |
// @author mdecorde |
|
4 |
|
|
5 |
// STANDARD DECLARATIONS |
|
6 |
package org.txm.macro.projects.antract |
|
7 |
|
|
8 |
import org.txm.searchengine.cqp.corpus.CQPCorpus |
|
9 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery |
|
10 |
import org.txm.macro.projects.antract.OkapiSaphirAPI |
|
11 |
import org.txm.searchengine.cqp.CQPSearchEngine |
|
12 |
|
|
13 |
import org.txm.backtomedia.preferences.BackToMediaPreferences |
|
14 |
|
|
15 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
16 |
println "Erreur: la sélection n'est pas un corpus." |
|
17 |
return false |
|
18 |
} |
|
19 |
|
|
20 |
@Field @Option(name="titre_du_nouveau_corpus_okapi", usage="Nom du corpus à créer", widget="String", required=false, def="") |
|
21 |
def titre_du_nouveau_corpus_okapi |
|
22 |
|
|
23 |
if (!ParametersDialog.open(this)) return; |
|
24 |
|
|
25 |
CQPCorpus corpus = corpusViewSelection |
|
26 |
corpus.compute() |
|
27 |
CQPCorpus parentCorpus = corpus.getMainCorpus() |
|
28 |
|
|
29 |
String parentCorpusName = parentCorpus.getCqpId() |
|
30 |
|
|
31 |
def struct_prop = null |
|
32 |
def finalValues = [] |
|
33 |
def ids = null |
|
34 |
|
|
35 |
if (parentCorpusName.startsWith("AF-VOIX-OFF-")) { |
|
36 |
ids = gse.run(ListerIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
37 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
38 |
ids = gse.run(ListerIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
39 |
} else { |
|
40 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
41 |
return false |
|
42 |
} |
|
43 |
|
|
44 |
monitor.syncExec(new Runnable() { |
|
45 |
public void run() { |
|
46 |
if (!OkapiSaphirAPI.initializeCredentials(org.eclipse.swt.widgets.Display.getCurrent().getActiveShell(), BackToMediaPreferences.MEDIA_AUTH_LOGIN, BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "OKAPI - Antract", "You must authenticate to access the okapi corpus API", "OKAPI - Antract", monitor)) { |
|
47 |
println "Cancel corpus export" |
|
48 |
return null; |
|
49 |
} |
|
50 |
} |
|
51 |
}); |
|
52 |
|
|
53 |
|
|
54 |
String user = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN) |
|
55 |
String password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD) |
|
56 |
|
|
57 |
String sessionID = OkapiSaphirAPI.login(user, password) |
|
58 |
if (sessionID.length() > 0) { |
|
59 |
String corpusID = OkapiSaphirAPI.create_corpus(sessionID, titre_du_nouveau_corpus_okapi, ids) |
|
60 |
if (corpusID.length() > 0 && corpusID.startsWith("http")) { |
|
61 |
println "New Okapi corpus $titre_du_nouveau_corpus_okapi created with ID "+corpusID |
|
62 |
println "Direct access link: "+OkapiSaphirAPI.getDirectAccessURL(corpusID) |
|
63 |
} else { |
|
64 |
println "Error: Okapi corpus not created (return value="+corpusID+")" |
|
65 |
} |
|
66 |
} else { |
|
67 |
println "Error: Okapi session not started. Resetting credentials." |
|
68 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, "") |
|
69 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "") |
|
70 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/AjouterDesSujetsAuCorpusOkapiMacro.groovy (revision 3187) | ||
---|---|---|
17 | 17 |
return false |
18 | 18 |
} |
19 | 19 |
|
20 |
@Field @Option(name="liste_des_identifiants", usage="Listes des identifiants sujets à ajouter", widget="String", required=false, def="") |
|
21 |
def liste_des_identifiants |
|
22 |
|
|
20 | 23 |
@Field @Option(name="identifiant_du_corpus_okapi_a_modifier", usage="Identifiant Okapi du corpus à modifier", widget="String", required=false, def="") |
21 | 24 |
def identifiant_du_corpus_okapi_a_modifier |
22 | 25 |
|
... | ... | |
30 | 33 |
|
31 | 34 |
def struct_prop = null |
32 | 35 |
def finalValues = [] |
33 |
def ids = null |
|
34 | 36 |
|
35 |
if (parentCorpusName.startsWith("AF-VOIX-OFF-")) { |
|
36 |
ids = gse.run(ExporterIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
37 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
38 |
ids = gse.run(ExporterIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
39 |
} else { |
|
40 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
41 |
return false |
|
42 |
} |
|
43 |
|
|
44 | 37 |
// set Okapi user&password |
45 | 38 |
if (OkapiSaphirAPI.initializeCredentials(BackToMediaPreferences.MEDIA_AUTH_LOGIN, BackToMediaPreferences.MEDIA_AUTH_PASSWORD, |
46 | 39 |
"OKAPI - Antract", "You must authenticate to access the okapi corpus API", "OKAPI - Antract", monitor)) { |
... | ... | |
58 | 51 |
// start the Okapi session |
59 | 52 |
String sessionID = OkapiSaphirAPI.login(user, password) |
60 | 53 |
if (sessionID.length() > 0) { |
61 |
String corpusID = OkapiSaphirAPI.update_corpus(sessionID, identifiant_du_corpus_okapi_a_modifier, ids)
|
|
54 |
String corpusID = OkapiSaphirAPI.update_corpus(sessionID, identifiant_du_corpus_okapi_a_modifier, liste_des_identifiants)
|
|
62 | 55 |
if (sessionID.length() > 0 && sessionID.startsWith("http")) { |
63 |
println "Okapi corpus $identifiant_du_corpus_okapi_a_modifier updated with "+ids
|
|
56 |
println "Okapi corpus $identifiant_du_corpus_okapi_a_modifier updated with "+liste_des_identifiants
|
|
64 | 57 |
} else { |
65 | 58 |
println "Error: Okapi corpus not updated: "+sessionID |
66 | 59 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/WordProperty2WordMacro.groovy (revision 3187) | ||
---|---|---|
1 |
|
|
2 |
package org.txm.macro.annotation |
|
3 |
|
|
4 |
// STANDARD DECLARATIONS |
|
5 |
import org.txm.rcpapplication.swt.widget.parameters.* |
|
6 |
import org.txm.searchengine.cqp.corpus.* |
|
7 |
import org.txm.xml.DOMIdentityHook |
|
8 |
import org.txm.xml.LocalNameHookActivator |
|
9 |
import org.txm.xml.XMLProcessor |
|
10 |
import org.txm.objects.* |
|
11 |
import org.txm.rcp.utils.JobHandler |
|
12 |
import org.txm.rcp.views.corpora.CorporaView |
|
13 |
import org.eclipse.core.runtime.Status |
|
14 |
import org.txm.annotation.kr.core.KRAnnotationEngine |
|
15 |
import org.txm.annotation.kr.core.repository.* |
|
16 |
import org.txm.annotation.kr.rcp.commands.SaveAnnotations |
|
17 |
import org.txm.annotation.kr.rcp.concordance.WordAnnotationToolbar |
|
18 |
import org.txm.importer.StaxIdentityParser |
|
19 |
|
|
20 |
def scriptName = this.class.getSimpleName() |
|
21 |
|
|
22 |
if (!(corpusViewSelection instanceof MainCorpus)) { |
|
23 |
println "** $scriptName: please select a Corpus in the Corpus view." |
|
24 |
return 0 |
|
25 |
} |
|
26 |
|
|
27 |
MainCorpus mcorpus = corpusViewSelection |
|
28 |
Project project = mcorpus.getProject() |
|
29 |
File txmDir = new File(project.getProjectDirectory(), "txm/"+mcorpus.getName()) |
|
30 |
|
|
31 |
@Field @Option(name="outputDirectory", usage="Directory of resulting XML-TXM files", widget="Folder", required=true, def="result_directory") |
|
32 |
File outputDirectory |
|
33 |
|
|
34 |
@Field @Option(name="word_property", usage="The word property to move", widget="String", required=true, def="type") |
|
35 |
String word_property |
|
36 |
|
|
37 |
//@Field @Option(name="word_property_value_to_ignore", usage="The annotation type", widget="String", required=true, def="__undef__") |
|
38 |
//String word_property_value_to_ignore |
|
39 |
|
|
40 |
// Open the parameters input dialog box |
|
41 |
if (!ParametersDialog.open(this)) return |
|
42 |
|
|
43 |
if (!outputDirectory.exists()) { |
|
44 |
println "Error: output directory not found: "+outputDirectory |
|
45 |
return false |
|
46 |
} |
|
47 |
|
|
48 |
for (Text text : project.getChildren(Text.class)) { |
|
49 |
println "Text: "+text |
|
50 |
|
|
51 |
File orig = text.getXMLTXMFile() |
|
52 |
if (!orig.exists()) { |
|
53 |
println "Warning: no XML-TXM file found for "+text |
|
54 |
continue // next ! |
|
55 |
} |
|
56 |
|
|
57 |
File result = new File(outputDirectory, orig.getName()) |
|
58 |
|
|
59 |
if (false && result.lastModified() > orig.lastModified()) { |
|
60 |
println "Skipping $text: result file is more recent: $result" |
|
61 |
continue // next ! |
|
62 |
} |
|
63 |
|
|
64 |
XMLProcessor xp = new XMLProcessor(orig); |
|
65 |
LocalNameHookActivator activator = new LocalNameHookActivator("w"); |
|
66 |
new DOMIdentityHook("word", activator, xp) { |
|
67 |
@Override |
|
68 |
public void processDom() { |
|
69 |
//println dom |
|
70 |
use(groovy.xml.dom.DOMCategory) { |
|
71 |
def form = dom.form[0] |
|
72 |
def anatype = dom.ana.findAll(){ a -> a['@type'] == "#$word_property"} |
|
73 |
// println form.text()+" -> $anatype" |
|
74 |
if (anatype.size() > 0) { // keep the word |
|
75 |
anatype = anatype[0] |
|
76 |
def s = form.text() |
|
77 |
form.setTextContent(anatype.text()) |
|
78 |
anatype['@type'] = "#form" |
|
79 |
anatype.setTextContent(s) |
|
80 |
} else { |
|
81 |
dom = null; |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
xp.process(result) |
|
87 |
} |
Formats disponibles : Unified diff