Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / urs / exploit / mesures1 / ReferentialDensityMacro.groovy @ 1962

History | View | Annotate | Download (1.8 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.urs.exploit.mesures1
7

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

    
14
if (!(corpusViewSelection instanceof CQPCorpus)) {
15
        println "Corpora selection is not a Corpus"
16
        return;
17
}
18

    
19
@Field @Option(name="unit_ursql", usage="TYPE@PROP=VALUE", widget="String", required=false, def="MENTION")
20
String unit_ursql
21
@Field @Option(name="limit_cql", usage="CQL to build structure limits", widget="Query", required=true, def="<div> [] expand to div")
22
limit_cql
23
@Field @Option(name="strict_inclusion", usage="Units must be strictly included into corpus matches", widget="Boolean", required=true, def="true")
24
strict_inclusion
25
@Field @Option(name="limit_distance", usage="Unit distance to structure limit (0 = no selection, 1 = first after limit, -1 = last before limit, etc.)", widget="Integer", required=true, def="0")
26
limit_distance
27
if (!ParametersDialog.open(this)) return;
28
// END OF PARAMETERS
29

    
30
CQPCorpus corpus = corpusViewSelection
31
def analecCorpus = URSCorpora.getCorpus(corpus);
32

    
33
int nMots = corpus.getSize();
34

    
35
def units = AnalecUtils.selectUnitsInSchema(debug, analecCorpus, corpus, "", 0, 0,
36
        unit_ursql, 0, limit_cql, strict_inclusion, limit_distance);
37

    
38
int nUnites = units.size();
39

    
40
coef = (nUnites /nMots)
41
println "Densité référentielle : nUnites/nMots = $nUnites/$nMots = $coef = ${coef*100}%"
42
if (nUnites >= nMots) {
43
        println "WARNING: possible encoding error. Number of units ($nUnites) is greater than number of words ($nMots)"
44
}
45
return ["result":coef, "data":["nUnites":nUnites, "nMots":nMots]]