Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / urs / exploit / SchemasListMacro.groovy @ 2105

History | View | Annotate | Download (4.4 kB)

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

    
6
// STANDARD DECLARATIONS
7
package org.txm.macro.urs.exploit
8

    
9
import org.kohsuke.args4j.*
10
import groovy.transform.Field
11
import org.txm.rcp.swt.widget.parameters.*
12
import org.txm.annotation.urs.*
13
import visuAnalec.elements.*
14
import org.txm.searchengine.cqp.corpus.*
15
import org.txm.macro.urs.AnalecUtils
16
import org.txm.Toolbox
17
import org.txm.rcp.commands.*
18
import org.apache.commons.lang.StringUtils
19
import org.txm.searchengine.cqp.CQPSearchEngine
20

    
21
def selection = []
22
for (def s : corpusViewSelections) {
23
        if (s instanceof CQPCorpus) selection << s
24
        else if (s instanceof Partition) selection.addAll(s.getParts())
25
}
26

    
27
if (selection.size() == 0) {
28
        println "** $scriptName: please select a Corpus or a Partition in the Corpus view: "+corpusViewSelections
29
        return false
30
} else {
31
        for (def c : selection) c.compute(false)
32
}
33

    
34
// BEGINNING OF PARAMETERS
35
@Field @Option(name="schema_ursql", usage="TYPE@PROP=VALUE", widget="String", required=true, def="CHAINE")
36
String schema_ursql
37

    
38
@Field @Option(name="minimum_schema_size", usage="minimal schema size", widget="Integer", required=true, def="3")
39
int minimum_schema_size
40
@Field @Option(name="maximum_schema_size", usage="Maximum size needed to consider a schema", widget="Integer", required=true, def="9999999")
41
int maximum_schema_size
42
@Field @Option(name="unit_ursql", usage="TYPE@PROP=VALUE", widget="String", required=false, def="MENTION")
43
String unit_ursql
44

    
45
@Field @Option(name="word_property", usage="", widget="StringArray", metaVar="word        lemma        frlemma        frolemma        #forme#        id", required=false, def="word")
46
String word_property
47

    
48
@Field @Option(name="separator", usage="", widget="String", required=true, def=", ")
49
String separator
50

    
51
@Field @Option(name="buildCQL", usage="générer la requête des unités", widget="Boolean", required=true, def='false')
52
def buildCQL
53

    
54
@Field @Option(name="debug", usage="Show internal variable content", widget="StringArray", metaVar="OFF        ON        ALL        REALLY ALL", required=true, def="OFF")
55
debug
56

    
57
if (!ParametersDialog.open(this)) return;
58
if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3
59

    
60

    
61
for (def corpus : selection) {
62
        def analecCorpus = URSCorpora.getCorpus(corpus)
63
        
64
        def errors = AnalecUtils.isPropertyDefined(Schema.class, analecCorpus, schema_ursql)
65
        if (errors.size() > 0) {
66
                println "** The $schema_ursql schema URSQL cannot be computed in the corpus with types: $errors."
67
                return;
68
        }
69
        
70
        errors=AnalecUtils.isPropertyDefined(Unite.class, analecCorpus, unit_ursql)
71
        if (errors.size() > 0) {
72
                println "** $unit_ursql unit URSQL cannot be computed in the corpus with types: $errors."
73
                return;
74
        }
75
        
76
        def CQI = CQPSearchEngine.getCqiClient()
77
        
78
        if (buildCQL) {
79
                word_prop = corpus.getProperty("id")
80
        } else {
81
                word_prop = corpus.getProperty(word_property)
82
        }
83
        
84
        def schemas = AnalecUtils.selectSchemasInCorpus(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, maximum_schema_size);
85
        schemas.sort() {it.getProps()}
86
        def nSchemas = 0
87
        
88
        def lens = [:]
89
        
90
        println "$corpus schemas (${schemas.size()}):"
91
        for (def schema : schemas) {
92
        
93
                def allUnites = schema.getUnitesSousjacentesNonTriees()
94
                def units = AnalecUtils.filterElements(debug, allUnites, unit_ursql)
95
                
96
                print schema.getProps().toString()+ ": "
97
                def first = true
98
                for (def unit : units) {
99
        
100
                        String forme =  null;
101
        
102
                        if (buildCQL) {
103
                                int[] pos = null
104
                                if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
105
                                else pos = (unit.getDeb()..unit.getFin())
106
                                def first2= true
107
                                q = ""
108
                                pos.each {
109
                                        if (first2) { first2 = false } else { q = q+" " }
110
                                        int[] pos2 = [it]
111
                                        q = q+"["+word_prop+"=\""+CQI.cpos2Str(word_prop.getQualifiedName(), pos2)[0]+"\"]"
112
                                }
113
                                if (first) { first = false } else { print "|" }
114
                                print "("+q+")"
115
                        } else {
116
                                if (word_prop == null) { // word_property is the analec unit property to use
117
                                        forme = unit.getProp(word_property)
118
                                } else {
119
                                        int[] pos = null
120
                                        if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
121
                                        else pos = (unit.getDeb()..unit.getFin())
122
                                        
123
                                                forme = StringUtils.join(CQI.cpos2Str(word_prop.getQualifiedName(), pos), " ") // ids is enough
124
                                }
125
        
126
                                if (first) { first = false } else { print separator }
127
                                print forme
128
                        }
129
                }
130
                println ""
131
        
132
                nSchemas++
133
        }
134
}
135