Statistics
| Revision:

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

History | View | Annotate | Download (3.3 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
// STANDARD DECLARATIONS
6
package org.txm.macro.analec
7

    
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.rcp.swt.widget.parameters.*
11
import org.txm.analec.*
12
import org.txm.searchengine.cqp.corpus.*
13

    
14

    
15
// BEGINNING OF PARAMETERS
16
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="Coréférence")
17
String schema_type
18

    
19
@Field @Option(name="minimum_schema_size",usage="", widget="Integer", required=true, def="3")
20
int minimum_schema_size
21

    
22
@Field @Option(name="schema_property_name",usage="", widget="String", required=false, def="")
23
String schema_property_name
24

    
25
@Field @Option(name="schema_property_value",usage="", widget="String", required=false, def=".*")
26
String schema_property_value
27

    
28
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="Maillon")
29
String unit_type
30

    
31
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="")
32
String unit_property_name
33

    
34
@Field @Option(name="unit_property_value", usage="", widget="String", required=false, def=".*")
35
String unit_property_value
36

    
37
if (!(corpusViewSelection instanceof MainCorpus)) {
38
        println "Corpora selection is not a Corpus"
39
        return;
40
}
41

    
42
// Open the parameters input dialog box
43
if (!ParametersDialog.open(this)) return;
44
// END OF PARAMETERS
45

    
46
MainCorpus corpus = corpusViewSelection
47
def analecCorpus = AnalecCorpora.getCorpus(corpus)
48

    
49
// check Schema parameters
50
if (!analecCorpus.getStructure().getSchemas().contains(schema_type)) {
51
        println "No schema with name=$schema_type"
52
        return;
53
} else {
54
        if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
55
                // test property existance
56
                def props = analecCorpus.getStructure().getSchemaProperties(schema_type);
57
                if (!props.contains(schema_property_name)) {
58
                        println "Schema $schema_type has no property named $schema_property_name"
59
                        return;
60
                }
61
        }
62
}
63

    
64
// check unit parameters
65
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
66
        println "No unit with name=$unit_type"
67
        return;
68
} else {
69
        if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
70
                // test property existance
71
                def props = analecCorpus.getStructure().getUniteProperties(unit_type);
72
                if (!props.contains(unit_property_name)) {
73
                        println "Unit $unit_type has no property named $unit_property_name"
74
                        return;
75
                }
76
        }
77
}
78

    
79
def schemas = analecCorpus.getSchemas(schema_type)
80

    
81
int nSchemas = 0;
82
for (def schema : schemas) {
83

    
84
        if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
85
                if (!schema.getProp(schema_property_name).matches(schema_property_value)) {
86
                        // ignoring this schema
87
                        continue
88
                }
89
        }
90
        
91
        int nUnites = 0;
92
        for (def unit : schema.getUnitesSousjacentesNonTriees()) {
93
        if (unit_type.length() > 0) {
94
                        if (!unit.getType().equals(unit_type)) {
95
                                continue
96
                        }
97
                }
98
                
99
                if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
100
                        if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
101
                                // ignoring this schema
102
                                continue
103
                        }
104
                }
105
        
106
                nUnites++
107
        }
108
        
109
        if (nUnites < minimum_schema_size) continue;
110

    
111
        nSchemas++;
112
}
113

    
114
println "nombre de chaînes de référence d'un texte : $nSchemas"
115

    
116
["result":nSchemas, "data":schemas]