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 671 mdecorde
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2 671 mdecorde
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3 671 mdecorde
// @author mdecorde
4 671 mdecorde
// @author sheiden
5 671 mdecorde
// STANDARD DECLARATIONS
6 1217 mdecorde
package org.txm.macro.urs.exploit.mesures1
7 671 mdecorde
8 671 mdecorde
import org.kohsuke.args4j.*
9 671 mdecorde
import groovy.transform.Field
10 671 mdecorde
import org.txm.rcp.swt.widget.parameters.*
11 1217 mdecorde
import org.txm.annotation.urs.*
12 671 mdecorde
import org.txm.searchengine.cqp.corpus.*
13 671 mdecorde
14 1962 mdecorde
if (!(corpusViewSelection instanceof CQPCorpus)) {
15 671 mdecorde
        println "Corpora selection is not a Corpus"
16 671 mdecorde
        return;
17 671 mdecorde
}
18 671 mdecorde
19 1962 mdecorde
@Field @Option(name="unit_ursql", usage="TYPE@PROP=VALUE", widget="String", required=false, def="MENTION")
20 1962 mdecorde
String unit_ursql
21 1962 mdecorde
@Field @Option(name="limit_cql", usage="CQL to build structure limits", widget="Query", required=true, def="<div> [] expand to div")
22 1962 mdecorde
limit_cql
23 1962 mdecorde
@Field @Option(name="strict_inclusion", usage="Units must be strictly included into corpus matches", widget="Boolean", required=true, def="true")
24 1962 mdecorde
strict_inclusion
25 1962 mdecorde
@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 1962 mdecorde
limit_distance
27 671 mdecorde
if (!ParametersDialog.open(this)) return;
28 671 mdecorde
// END OF PARAMETERS
29 671 mdecorde
30 1962 mdecorde
CQPCorpus corpus = corpusViewSelection
31 1217 mdecorde
def analecCorpus = URSCorpora.getCorpus(corpus);
32 671 mdecorde
33 671 mdecorde
int nMots = corpus.getSize();
34 671 mdecorde
35 1962 mdecorde
def units = AnalecUtils.selectUnitsInSchema(debug, analecCorpus, corpus, "", 0, 0,
36 1962 mdecorde
        unit_ursql, 0, limit_cql, strict_inclusion, limit_distance);
37 671 mdecorde
38 1962 mdecorde
int nUnites = units.size();
39 1962 mdecorde
40 671 mdecorde
coef = (nUnites /nMots)
41 1962 mdecorde
println "Densité référentielle : nUnites/nMots = $nUnites/$nMots = $coef = ${coef*100}%"
42 671 mdecorde
if (nUnites >= nMots) {
43 671 mdecorde
        println "WARNING: possible encoding error. Number of units ($nUnites) is greater than number of words ($nMots)"
44 671 mdecorde
}
45 671 mdecorde
return ["result":coef, "data":["nUnites":nUnites, "nMots":nMots]]