Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / urs / edit / CheckDuplicatesInSchemasMacro.groovy @ 1217

History | View | Annotate | Download (3.1 kB)

1
package org.txm.macro.urs.edit
2

    
3
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
4
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
5
// @author mdecorde
6
// @author sheiden
7
// STANDARD DECLARATIONS
8

    
9
import groovy.transform.Field
10

    
11
import org.jfree.chart.JFreeChart
12
import org.kohsuke.args4j.*
13
import org.txm.Toolbox
14
import org.txm.annotation.urs.*
15
import org.txm.macro.urs.AnalecUtils
16
import org.txm.rcp.Application
17
import org.txm.rcp.IImageKeys
18
import org.txm.rcp.swt.widget.parameters.*
19
import org.txm.searchengine.cqp.corpus.*
20
import org.txm.searchengine.cqp.corpus.query.CQLQuery
21

    
22
import visuAnalec.elements.*
23

    
24
def scriptName = this.class.getSimpleName()
25

    
26
if (!(corpusViewSelection instanceof CQPCorpus)) {
27
        println "** $scriptName please select a Corpus to run the macro"
28
        return;
29
}
30

    
31
// BEGINNING OF PARAMETERS
32
@Field @Option(name="schema_ursql", usage="TYPE@PROP=VALUE", widget="String", required=true, def="CHAINE")
33
                String schema_ursql
34
@Field @Option(name="schema_property_display", usage="PROP", widget="String", required=true, def="REF")
35
                String schema_property_display
36
@Field @Option(name="debug", usage="Show internal variable content", widget="StringArray", metaVar="OFF        ON        ALL        REALLY ALL", required=true, def="OFF")
37
                debug
38
if (!ParametersDialog.open(this)) return
39
        if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3
40

    
41
def CQI = CQPSearchEngine.getCqiClient()
42

    
43
def corpus = corpusViewSelection
44
mainCorpus = corpus.getMainCorpus()
45

    
46
def word = mainCorpus.getWordProperty()
47
def analecCorpus = URSCorpora.getCorpus(mainCorpus.getName())
48

    
49
if (schema_property_display.length() > 0) {
50
        def errors = AnalecUtils.isPropertyDefined(Schema.class, analecCorpus, schema_ursql, schema_property_display).size()
51
        if (errors > 0) {
52
                println "Error: some Schema types don't contain the $schema_property_display property: $errors"
53
                return
54
        }
55
}
56

    
57
def allUnits = [:]
58

    
59
def allSchemas = AnalecUtils.selectSchemas(debug, analecCorpus, corpus, schema_ursql, -1, Integer.MAX_VALUE)
60

    
61
if (allSchemas.size() == 0) {
62
        println "No schema match for '$schema_ursql' selection. Aborting"
63
        return
64
}
65

    
66
allUnits = AnalecUtils.groupAllUnitesInElements(debug, allSchemas)
67

    
68
if (allUnits.size() == 0) {
69
        println "No unit selection. Aborting"
70
        return
71
}
72

    
73
if (debug) println "allUnits=${allUnits.size()}"
74

    
75
def duplicates = [:]
76
for (Schema schema : allSchemas) {
77
        def units = allUnits[schema];
78
        for (def unit : units) {
79
                if (!duplicates.containsKey(unit)) duplicates[unit] = []
80
                duplicates[unit] << schema
81
        }
82
}
83

    
84
def units = []
85
units.addAll(duplicates.keySet()) // remove non duplicates from hash
86
for (def unit : units) {
87
        if (duplicates[unit].size() < 2) duplicates.remove(unit)
88
}
89

    
90
if (duplicates.size() > 0) {
91
        println "Duplicates found"
92
        for (def unit : duplicates.keySet()) {
93
                println AnalecUtils.toString(CQI, word, unit)+" in: "
94
                for (Schema schema : duplicates[unit]) {
95
                        println " '"+schema.getProp(schema_property_display)+"'\t"+schema.getProps()
96
                }
97
        }
98
} else {
99
        println "No duplicates found in $schema_ursql units"
100
}
101

    
102
return duplicates