Révision 3189
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/AjouterDesSujetsAuCorpusOkapiMacro.groovy (revision 3189) | ||
---|---|---|
12 | 12 |
|
13 | 13 |
import org.txm.backtomedia.preferences.BackToMediaPreferences |
14 | 14 |
|
15 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
16 |
println "Erreur: la sélection n'est pas un corpus." |
|
17 |
return false |
|
18 |
} |
|
15 |
@Field @Option(name="liste_identifiants_sujets", usage="Listes des identifiants sujets à ajouter", widget="String", required=false, def="") |
|
16 |
def liste_identifiants_sujets |
|
19 | 17 |
|
20 |
@Field @Option(name="liste_des_identifiants", usage="Listes des identifiants sujets à ajouter", widget="String", required=false, def="")
|
|
21 |
def liste_des_identifiants
|
|
18 |
@Field @Option(name="identifiant_corpus_okapi", usage="Identifiant Okapi du corpus à modifier", widget="String", required=false, def="")
|
|
19 |
def identifiant_corpus_okapi
|
|
22 | 20 |
|
23 |
@Field @Option(name="identifiant_du_corpus_okapi_a_modifier", usage="Identifiant Okapi du corpus à modifier", widget="String", required=false, def="") |
|
24 |
def identifiant_du_corpus_okapi_a_modifier |
|
25 |
|
|
26 | 21 |
if (!ParametersDialog.open(this)) return; |
27 | 22 |
|
28 | 23 |
CQPCorpus corpus = corpusViewSelection |
... | ... | |
34 | 29 |
def struct_prop = null |
35 | 30 |
def finalValues = [] |
36 | 31 |
|
37 |
// set Okapi user&password |
|
38 |
if (OkapiSaphirAPI.initializeCredentials(BackToMediaPreferences.MEDIA_AUTH_LOGIN, BackToMediaPreferences.MEDIA_AUTH_PASSWORD, |
|
39 |
"OKAPI - Antract", "You must authenticate to access the okapi corpus API", "OKAPI - Antract", monitor)) { |
|
40 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, dialog.getUser()); |
|
41 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, dialog.getPassword()); |
|
42 |
} |
|
43 |
else { |
|
44 |
println "Cancel corpus update" |
|
45 |
return null; |
|
46 |
} |
|
32 |
monitor.syncExec(new Runnable() { |
|
33 |
public void run() { |
|
34 |
if (!OkapiSaphirAPI.initializeCredentials(org.eclipse.swt.widgets.Display.getCurrent().getActiveShell(), BackToMediaPreferences.MEDIA_AUTH_LOGIN, BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "OKAPI - Antract", "S'identifier sur la plateforme Okapi.", "OKAPI - Antract", monitor)) { |
|
35 |
return null; |
|
36 |
} |
|
37 |
} |
|
38 |
}); |
|
47 | 39 |
|
48 | 40 |
String user = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN) |
49 | 41 |
String password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD) |
42 |
if (user == null || user.length() == 0 || password == null || password.length() == 0) { |
|
43 |
println "Annulation." |
|
44 |
} |
|
50 | 45 |
|
51 | 46 |
// start the Okapi session |
52 | 47 |
String sessionID = OkapiSaphirAPI.login(user, password) |
53 | 48 |
if (sessionID.length() > 0) { |
54 |
String corpusID = OkapiSaphirAPI.update_corpus(sessionID, identifiant_du_corpus_okapi_a_modifier, liste_des_identifiants)
|
|
55 |
if (sessionID.length() > 0 && sessionID.startsWith("http")) {
|
|
56 |
println "Okapi corpus $identifiant_du_corpus_okapi_a_modifier updated with "+liste_des_identifiants
|
|
49 |
String corpusID = OkapiSaphirAPI.update_corpus(sessionID, identifiant_corpus_okapi, liste_identifiants_sujets)
|
|
50 |
if (corpusID.length() > 0 && corpusID.startsWith("http") && corpusID.equals(identifiant_corpus_okapi)) {
|
|
51 |
println "Le corpus Okapi $identifiant_corpus_okapi a été mis à jour avec $liste_identifiants_sujets"
|
|
57 | 52 |
} else { |
58 |
println "Error: Okapi corpus not updated: "+sessionID
|
|
53 |
println "Erreur : Le corpus Okapi n'a pas été mis à jour (session=$sessionID, corpus=$identifiant_corpus_okapi et identifiants=$liste_identifiants_sujets)"
|
|
59 | 54 |
} |
60 | 55 |
} else { |
61 |
println "Error: Okapi session not started. Resetting credentials."
|
|
56 |
println "Erreur : la session Okapi n'a pas pu être démarrée."
|
|
62 | 57 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, "") |
63 | 58 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "") |
64 | 59 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ListerIdentifiantsSujetsMacro.groovy (revision 3189) | ||
---|---|---|
10 | 10 |
import org.txm.searchengine.cqp.CQPSearchEngine |
11 | 11 |
|
12 | 12 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
13 |
println "Erreur: la sélection n'est pas un corpus."
|
|
13 |
println "Erreur: la sélection de la vue Corpus n'est pas un corpus ($corpusViewSelection)."
|
|
14 | 14 |
return false |
15 | 15 |
} |
16 | 16 |
|
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/OkapiSaphirAPI.groovy (revision 3189) | ||
---|---|---|
27 | 27 |
public static final String baseUrl = "https://okapi.ina.fr/antract/api/saphir/"; |
28 | 28 |
public static final String okapiUrl = "https://okapi.ina.fr/antract/html/resource_587884135/resource_996999332.html"; |
29 | 29 |
|
30 |
public static boolean debug = true;
|
|
30 |
public static boolean debug = false;
|
|
31 | 31 |
|
32 | 32 |
public static String getDirectAccessURL(String id) { |
33 | 33 |
return OkapiSaphirAPI.okapiUrl+"?linkedObjectUri="+URLEncoder.encode(id, "UTF-8") |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ImporterUnCorpusOkapiMacro.groovy (revision 3189) | ||
---|---|---|
15 | 15 |
|
16 | 16 |
// BEGINNING OF PARAMETERS |
17 | 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
|
|
18 |
@Field @Option(name="nom_sous_corpus", usage="Nom du sous-corpus à créer", widget="String", required=true, def="")
|
|
19 |
def nom_sous_corpus
|
|
20 |
@Field @Option(name="liste_identifiants_sujets", usage="Liste des identifiants de notice séparés par des '|'", widget="Text", required=true, def="")
|
|
21 |
def liste_identifiants_sujets
|
|
22 | 22 |
|
23 | 23 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
24 |
println "Erreur: la sélection n'est pas un corpus."
|
|
24 |
println "Erreur : la sélection de la vue Corpus n'est pas un corpus ($corpusViewSelection)."
|
|
25 | 25 |
return false |
26 | 26 |
} |
27 | 27 |
|
... | ... | |
36 | 36 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
37 | 37 |
|
38 | 38 |
} else { |
39 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE"
|
|
39 |
println "Erreur : le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE."
|
|
40 | 40 |
return false |
41 | 41 |
} |
42 | 42 |
|
43 | 43 |
// Open the parameters input dialog box |
44 | 44 |
if (!ParametersDialog.open(this)) return; |
45 | 45 |
|
46 |
println "Création du sous-corpus avec la liste: $identifiants"
|
|
46 |
println "Création du sous-corpus avec la liste d'identifiants: $liste_identifiants_sujets"
|
|
47 | 47 |
String prop = "div_id" |
48 | 48 |
if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
49 | 49 |
prop = "notice_identifiantdelanotice" |
50 | 50 |
} |
51 | 51 |
|
52 |
String query = "[_.$prop=\"$identifiants\"] expand to $prop"
|
|
53 |
println "Query=$query"
|
|
54 |
Subcorpus sub = parentCorpus.createSubcorpus(new CQLQuery(query), name)
|
|
52 |
String query = "[_.$prop=\"$liste_identifiants_sujets\"] expand to $prop"
|
|
53 |
println "Requête CQL de création du corpus : $query"
|
|
54 |
Subcorpus sub = parentCorpus.createSubcorpus(new CQLQuery(query), nom_sous_corpus)
|
|
55 | 55 |
|
56 | 56 |
int s = sub.getSize() |
57 | 57 |
if (s > 0) { |
58 |
println "$name subcorpus is created."
|
|
58 |
println "Le sous-corpus $nom_sous_corpus a été créé."
|
|
59 | 59 |
monitor.syncExec(new Runnable() { |
60 | 60 |
public void run() { |
61 | 61 |
CorporaView.refresh(); |
... | ... | |
63 | 63 |
} |
64 | 64 |
}); |
65 | 65 |
} else { |
66 |
println "Error: the created corpus is empty!"
|
|
66 |
println "Erreur : Le corpus créé et vide ! >_<'"
|
|
67 | 67 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ExporterSousCorpusSujetsDansOkapiMacro.groovy (revision 3189) | ||
---|---|---|
13 | 13 |
import org.txm.backtomedia.preferences.BackToMediaPreferences |
14 | 14 |
|
15 | 15 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
16 |
println "Erreur: la sélection n'est pas un corpus."
|
|
16 |
println "Erreur : la sélection de la vue Corpus n'est pas un corpus ($corpusViewSelection)."
|
|
17 | 17 |
return false |
18 | 18 |
} |
19 | 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
|
|
20 |
@Field @Option(name="titre_corpus_okapi", usage="Nom du corpus à créer", widget="String", required=false, def="") |
|
21 |
def titre_corpus_okapi |
|
22 | 22 |
|
23 | 23 |
if (!ParametersDialog.open(this)) return; |
24 | 24 |
|
... | ... | |
37 | 37 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
38 | 38 |
ids = gse.run(ListerIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
39 | 39 |
} else { |
40 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
40 |
println "Erreur : le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE"
|
|
41 | 41 |
return false |
42 | 42 |
} |
43 | 43 |
|
44 | 44 |
monitor.syncExec(new Runnable() { |
45 | 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" |
|
46 |
if (!OkapiSaphirAPI.initializeCredentials(org.eclipse.swt.widgets.Display.getCurrent().getActiveShell(), BackToMediaPreferences.MEDIA_AUTH_LOGIN, BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "OKAPI - Antract", "S'identifier sur la plateforme Okapi.", "OKAPI - Antract", monitor)) { |
|
48 | 47 |
return null; |
49 | 48 |
} |
50 | 49 |
} |
51 | 50 |
}); |
52 | 51 |
|
53 |
|
|
54 | 52 |
String user = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN) |
55 | 53 |
String password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD) |
54 |
if (user == null || user.length() == 0 || password == null || password.length() == 0) { |
|
55 |
println "Annulation." |
|
56 |
} |
|
56 | 57 |
|
57 | 58 |
String sessionID = OkapiSaphirAPI.login(user, password) |
58 | 59 |
if (sessionID.length() > 0) { |
59 |
String corpusID = OkapiSaphirAPI.create_corpus(sessionID, titre_du_nouveau_corpus_okapi, ids)
|
|
60 |
String corpusID = OkapiSaphirAPI.create_corpus(sessionID, titre_corpus_okapi, ids) |
|
60 | 61 |
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)
|
|
62 |
println "Le corpus 'titre_corpus_okapi' son identifiant est $corpusID"
|
|
63 |
println "Lien d'accès direct : "+OkapiSaphirAPI.getDirectAccessURL(corpusID)
|
|
63 | 64 |
} else { |
64 |
println "Error: Okapi corpus not created (return value="+corpusID+")"
|
|
65 |
println "Erreur : Le corpus Okapi n'a pas été créé (code d'erreur=$corpusID)"
|
|
65 | 66 |
} |
66 | 67 |
} else { |
67 |
println "Error: Okapi session not started. Resetting credentials."
|
|
68 |
println "Erreur : La session Okapi n'a pu être démarrée."
|
|
68 | 69 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, "") |
69 | 70 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "") |
70 | 71 |
} |
Formats disponibles : Unified diff