Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / analec / edit / Si2SingletonMacro.groovy @ 1166

History | View | Annotate | Download (2.5 kB)

1
// @author Bruno Oberlé
2
// v1.0.0 20170711
3

    
4
// Cette macro individualise tous les noms de référents "SI" en leur attribuant un numéro unique (SI_1, SI_2, etc.).
5

    
6
package org.txm.macro.analec.edit
7

    
8
import org.apache.commons.lang.*
9
import org.kohsuke.args4j.*
10
import groovy.transform.*
11
import org.txm.*
12
import org.txm.rcp.swt.widget.parameters.*
13
import org.txm.analec.*
14
import org.txm.searchengine.cqp.*
15
import org.txm.searchengine.cqp.corpus.*
16
import visuAnalec.Message.*
17
import visuAnalec.donnees.*
18
import visuAnalec.elements.*
19
import visuAnalec.vue.*
20

    
21
// CORPS DU SCRIPT
22

    
23
if (!(corpusViewSelection instanceof MainCorpus)) {
24
        println "Corpora selection is not a Corpus"
25
        return
26
}
27

    
28
// BEGINNING OF PARAMETERS
29
@Field @Option(name="unitType", usage="", widget="String", required=true, def="MENTION")
30
def unitType
31
@Field @Option(name="refPropertyName", usage="", widget="String", required=true, def="REF")
32
def refPropertyName
33
if (!ParametersDialog.open(this)) return
34

    
35
corpus = corpusViewSelection
36
CQI = CQPSearchEngine.getCqiClient()
37
word = corpus.getWordProperty()
38
analecCorpus = AnalecCorpora.getCorpus(corpus)
39
vue = AnalecCorpora.getVue(corpus)
40
structure = analecCorpus.getStructure()
41
if (!structure.getUnites().contains(unitType)) { // check if the structure contains the unitType units
42
        println "Error: corpus structure does not contains unit with name=$unitType"
43
        return
44
}
45

    
46
if (!structure.getUniteProperties(unitType).contains(refPropertyName)) {
47
        println "Error: corpus structure does not contains property name=$unitType"
48
        return
49
} 
50

    
51
def nModified = 0
52
def nIgnored = 0
53

    
54
def units = analecCorpus.getUnites(unitType)
55
//units.sort() { a, b -> a.getDeb() <=> b.getDeb() ?: a.getFin() <=> b.getFin() }
56

    
57
def refSet = new HashSet()
58
for (Unite unit : units) { // process all units
59
        def prop = unit.getProp(refPropertyName)
60
        refSet.add(prop)
61
}
62

    
63
def counter = 1
64
for (Unite unit : units) { // process all units
65
        
66
        def prop = unit.getProp(refPropertyName)
67
        if (prop && prop == "SI") {
68
                def name = "SI_" + counter
69
                while (refSet.contains(name)) {
70
                        counter++
71
                        name = "SI_" + counter
72
                }
73
                counter++
74
                //println "old prop"+ prop
75
                unit.getProps().put(refPropertyName, name)
76
                //println "new prop"+ name
77
                nModified++
78
        } else {
79
                nIgnored++
80
        }
81
}
82

    
83
println "Result:"
84
println "- $nModified units of type $unitType have been modified."
85
println "- $nIgnored units of type $unitType have not been modified.\n"
86

    
87
// udpate the view (also see also
88
// http://forge.cbp.ens-lyon.fr/redmine/issues/2065)
89
AnalecCorpora.getVue(analecCorpus).retablirVueParDefaut()