Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / urs / edit / CheckAnnotationStructureValuesMacro.groovy @ 1973

History | View | Annotate | Download (2 kB)

1
// STANDARD DECLARATIONS
2
package org.txm.macro.urs.edit
3

    
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcp.swt.widget.parameters.*
7
import org.txm.annotation.urs.*
8
import org.txm.searchengine.cqp.corpus.*
9
import visuAnalec.elements.*
10

    
11
if (!(corpusViewSelection instanceof MainCorpus)) {
12
        println "Corpora selection is not a Corpus"
13
        return;
14
}
15

    
16
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="MENTION")
17
String unit_type
18

    
19
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="REF")
20
String unit_property_name
21

    
22
@Field @Option(name="pruneUnusedValues", usage="", widget="Boolean", required=false, def="false")
23
boolean pruneUnusedValues
24

    
25
// Open the parameters input dialog box
26
if (!ParametersDialog.open(this)) return;
27

    
28
// END OF PARAMETERS
29

    
30
MainCorpus corpus = corpusViewSelection
31
def analecCorpus = URSCorpora.getCorpus(corpus);
32
def structure = analecCorpus.getStructure()
33

    
34
def unit_types = structure.getTypes(Unite.class);
35
if (!unit_types.contains(unit_type)) {
36
        println "Missing unit type: $unit_type"
37
        return
38
}
39

    
40
def props = analecCorpus.getStructure().getUniteProperties(unit_type);
41
if (!props.contains(unit_property_name)) {
42
        println "No properties '$unit_property_name' in '$unit_type' unit."
43
        return
44
}
45

    
46
def prop  = unit_property_name
47
        
48
def tmpvalues = new HashSet()
49
tmpvalues.addAll(structure.getValeursProp(Unite.class, unit_type, prop));
50
println "Values stored in the structure: $tmpvalues"
51
        
52
def used_values = new HashSet();
53
def unites = analecCorpus.getUnites(unit_type);
54
for (Unite unite : unites) {
55
        used_values.add(unite.getProp(prop))
56
}
57
        
58
tmpvalues.removeAll(used_values);
59
if (tmpvalues.size() > 0) {
60
        println "The following values ("+tmpvalues.size()+") are not used: "+tmpvalues.join(", ")
61
        if (pruneUnusedValues) {
62
                println "Pruning the values..."
63
                for (String val : tmpvalues) {
64
                        structure.supprimerVal(Unite.class, unit_type, unit_property_name, val);
65
                }
66
        } 
67
} else {
68
        println "All the values are used."
69
}