root / tmp / org.txm.analec.rcp / src / org / txm / macro / urs / democrat / AccessibiliteMacro.groovy @ 2144
History | View | Annotate | Download (3.4 kB)
1 |
package org.txm.macro.urs.democrat
|
---|---|
2 |
|
3 |
import org.apache.commons.lang.* |
4 |
import org.kohsuke.args4j.* |
5 |
import groovy.transform.* |
6 |
import org.txm.* |
7 |
import org.txm.rcp.swt.widget.parameters.* |
8 |
import org.txm.annotation.urs.* |
9 |
import org.txm.searchengine.cqp.* |
10 |
import org.txm.searchengine.cqp.corpus.* |
11 |
import visuAnalec.Message.* |
12 |
import visuAnalec.donnees.* |
13 |
import visuAnalec.elements.* |
14 |
import visuAnalec.vue.* |
15 |
|
16 |
/*
|
17 |
Calcule l'accessibilité (faible ou forte) d'une mention à partir de sa CATEGORIE
|
18 |
La macro fonctionne à partir de 2 listes de catégories : accessibilité forte, accessibilité nulle.
|
19 |
L'accessibilité faible sera le cas par défaut.
|
20 |
|
21 |
La macro crée une nouvelle propriété pour les MENTION : ACCESSIBILITE
|
22 |
Les valeurs autorisées sont : "Faible", "Forte" et "N/A"
|
23 |
Voir si la dénomination de cette dernière valeur convient.
|
24 |
|
25 |
Auteur : Matthieu Quignard
|
26 |
Date : 19/12/2017
|
27 |
*/
|
28 |
|
29 |
def listeAccessibiliteForte=["PRO.PERA", "PRO.REL", "SUJ.ZERO", "DET.POS"] |
30 |
def listeAccessibiliteNulle=[] |
31 |
|
32 |
|
33 |
// CORPS DU SCRIPT
|
34 |
|
35 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
36 |
println "Corpora selection is not a Corpus: "+corpusViewSelection
|
37 |
return
|
38 |
} |
39 |
|
40 |
// BEGINNING OF PARAMETERS
|
41 |
@Field @Option(name="unit_type", usage="", widget="String", required=true, def="MENTION") |
42 |
def unit_type
|
43 |
if (!ParametersDialog.open(this)) return |
44 |
|
45 |
corpus = corpusViewSelection |
46 |
CQI = CQPSearchEngine.getCqiClient() |
47 |
|
48 |
analecCorpus = URSCorpora.getCorpus(corpus) |
49 |
vue = URSCorpora.getVue(corpus) |
50 |
structure = analecCorpus.getStructure() |
51 |
if (!structure.getUnites().contains(unit_type)) { // check if the structure contains the unit_type units |
52 |
println "Error: corpus structure does not contains unit with name=$unit_type"
|
53 |
return
|
54 |
} |
55 |
|
56 |
ACCESSIBILITE = "ACCESSIBILITE"
|
57 |
// Si la structure d'annotation ne contient pas ACCESSIBILITE, on la crée avec ses valeurs
|
58 |
if (!structure.getUniteProperties(unit_type).contains(ACCESSIBILITE)) {
|
59 |
// la propriété
|
60 |
analecCorpus.ajouterProp(Unite.class, unit_type, ACCESSIBILITE) |
61 |
// les valeurs
|
62 |
|
63 |
structure.ajouterVal(Unite.class, unit_type, ACCESSIBILITE, "Faible")
|
64 |
structure.ajouterVal(Unite.class, unit_type, ACCESSIBILITE, "Forte")
|
65 |
structure.ajouterVal(Unite.class, unit_type, ACCESSIBILITE, "N/A")
|
66 |
} |
67 |
|
68 |
def nModified = 0 |
69 |
def nIgnored = 0 |
70 |
def nNulle = 0 |
71 |
def nForte = 0 |
72 |
def nFaible = 0 |
73 |
|
74 |
errors = new HashMap() |
75 |
def units = analecCorpus.getUnites(unit_type)
|
76 |
units.sort() { a, b -> a.getDeb() <=> b.getDeb() ?: a.getFin() <=> b.getFin() } |
77 |
for (Unite unit : units) { // process all units |
78 |
|
79 |
def prop = unit.getProp("CATEGORIE") |
80 |
|
81 |
if (prop== null) { |
82 |
// On ignore les cas où la catégorie n'est pas renseignée.
|
83 |
nIgnored++ |
84 |
} else {
|
85 |
nModified++ |
86 |
if (listeAccessibiliteNulle.contains(prop)) {
|
87 |
// Cas d'accessibilité nulle
|
88 |
vue.setValeurChamp(unit, ACCESSIBILITE, "N/A")
|
89 |
nNulle++ |
90 |
} else if (listeAccessibiliteForte.contains(prop)) { |
91 |
// Cas d'accessibilité forte
|
92 |
vue.setValeurChamp(unit, ACCESSIBILITE, "Forte")
|
93 |
nForte++ |
94 |
} else {
|
95 |
// Sinon, on est dans le cas d'accessibilité faible
|
96 |
vue.setValeurChamp(unit, ACCESSIBILITE, "Faible")
|
97 |
nFaible++ |
98 |
} |
99 |
} |
100 |
|
101 |
} |
102 |
|
103 |
println "Result:"
|
104 |
println "- $nModified mentions ont été modifiées."
|
105 |
println "- $nIgnored mentions ont été ignorées (leur catégorie est vide).\n"
|
106 |
|
107 |
println "- $nForte mentions d'accessibilité forte."
|
108 |
println "- $nFaible mentions d'accessibilité faible."
|
109 |
println "- $nNulle mentions de type 'N/A' (déictiques).\n"
|
110 |
|