root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / r / PlotSpecifMacro.groovy @ 2541
History | View | Annotate | Download (3.4 kB)
1 |
package org.txm.macro.r;
|
---|---|
2 |
// Copyright © 2013-2016 ENS de Lyon, University of Franche-Comté.
|
3 |
// Copyright © 2010-2013 ENS de Lyon.
|
4 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
|
5 |
// Lyon 2, University of Franche-Comté, University of Nice
|
6 |
// Sophia Antipolis, University of Paris 3.
|
7 |
//
|
8 |
// The TXM platform is free software: you can redistribute it
|
9 |
// and/or modify it under the terms of the GNU General Public
|
10 |
// License as published by the Free Software Foundation,
|
11 |
// either version 2 of the License, or (at your option) any
|
12 |
// later version.
|
13 |
//
|
14 |
// The TXM platform is distributed in the hope that it will be
|
15 |
// useful, but WITHOUT ANY WARRANTY; without even the implied
|
16 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
17 |
// PURPOSE. See the GNU General Public License for more
|
18 |
// details.
|
19 |
//
|
20 |
// You should have received a copy of the GNU General
|
21 |
// Public License along with the TXM platform. If not, see
|
22 |
// http://www.gnu.org/licenses.
|
23 |
//
|
24 |
// $LastChangedDate:$
|
25 |
// $LastChangedRevision:$
|
26 |
// $LastChangedBy:$
|
27 |
//
|
28 |
|
29 |
import org.kohsuke.args4j.* |
30 |
import groovy.transform.Field |
31 |
import org.txm.rcp.swt.widget.parameters.* |
32 |
import org.txm.rcp.commands.* |
33 |
import org.txm.Toolbox |
34 |
import org.txm.statsengine.r.core.RWorkspace |
35 |
|
36 |
/**
|
37 |
*
|
38 |
* @authors Matthieu Decorde, Serge Heiden, Achille Falaise.
|
39 |
*
|
40 |
* Sample default values from:
|
41 |
* Lafon, P. “Sur la variabilité de la fréquence des formes dans un corpus.” Mots, no. 1 (1980):
|
42 |
* Robespierre 'peuple' word in D9 part example (see Figure 1), pp 140-141.
|
43 |
* <http://www.persee.fr/web/revues/home/prescript/article/mots_0243-6450_1980_num_1_1_1008>.
|
44 |
*
|
45 |
**/
|
46 |
|
47 |
@Field @Option(name="f", usage="La fréquence de la forme dans la partie", widget="Integer", required=true, def="11") |
48 |
def f;
|
49 |
|
50 |
@Field @Option(name="F", usage="La fréquence totale de la forme dans le corpus", widget="Integer", required=true, def="296") |
51 |
def F;
|
52 |
|
53 |
@Field @Option(name="t", usage="Le nombre d'occurrences de la partie", widget="Integer", required=true, def="1084") |
54 |
def t;
|
55 |
|
56 |
@Field @Option(name="T", usage="Le nombre total d'occurrences du corpus", widget="Integer", required=true, def="61449") |
57 |
def T;
|
58 |
|
59 |
// Open the parameters input dialog box
|
60 |
if (!ParametersDialog.open(this)) return; |
61 |
|
62 |
// END OF PARAMETERS
|
63 |
|
64 |
def r = RWorkspace.getRWorkspaceInstance()
|
65 |
def resultsDir = new File(Toolbox.getTxmHomePath(), "results") |
66 |
resultsDir.mkdirs() |
67 |
def file = File.createTempFile("txm", ".svg", resultsDir) |
68 |
|
69 |
/// BEGIN SCRIPTS
|
70 |
def script =""" |
71 |
library(textometry)
|
72 |
res <- specificities.distribution.plot($f, $F, $t, $T)
|
73 |
"""
|
74 |
/// END SCRIPTS
|
75 |
r.plot(file, script) |
76 |
|
77 |
def px = r.eval('res$px').asDouble() |
78 |
def mode = r.eval('res$mode').asInteger() |
79 |
def pfsum = r.eval('res$pfsum'+"[$f+1]").asDouble() |
80 |
def isPositiveSpecificity = (f > mode.abs()) // True if S+ |
81 |
def proba = pfsum.abs() // Compute actual probability (should be a positive number, even for negative specificities, where pfsum = -probability) |
82 |
def specifSign = (isPositiveSpecificity ? "+" : "-") |
83 |
def specif = Math.log10(proba).abs() // Compute actual specificity |
84 |
def operatorForDisplay = isPositiveSpecificity ? '>=' : '<=' |
85 |
|
86 |
println """
|
87 |
P(f'=f) et P(f' $operatorForDisplay f)
|
88 |
f F t T
|
89 |
$f $F $t $T
|
90 |
P(f' = $f) = $px
|
91 |
mode = $mode
|
92 |
P(f' $operatorForDisplay $f) = $proba
|
93 |
Specificity S$specifSign = $specif
|
94 |
"""
|
95 |
println "Result saved in: "+file.getAbsolutePath()
|
96 |
|
97 |
//display the graphic
|
98 |
monitor.syncExec(new Runnable() { |
99 |
@Override
|
100 |
public void run() { OpenSVGGraph.OpenSVGFile(file.getAbsolutePath(), "Specificity distribution") } |
101 |
}); |