Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / macro / r / PlotSpecifMacro.groovy @ 306

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 groovy.transform.Field
30

    
31
import java.lang.invoke.MethodHandleImpl.BindCaller.T
32

    
33
import org.kohsuke.args4j.*
34
import org.txm.Toolbox
35
import org.txm.rcpapplication.commands.*
36
import org.txm.rcpapplication.swt.widget.parameters.*
37

    
38
/**
39
 * 
40
 * @authors Matthieu Decorde, Serge Heiden, Achille Falaise.
41
 * 
42
 * Sample default values from:
43
 *  Lafon, P. “Sur la variabilité de la fréquence des formes dans un corpus.” Mots, no. 1 (1980):
44
 *  Robespierre 'peuple' word in D9 part example (see Figure 1), pp 140-141.
45
 *  <http://www.persee.fr/web/revues/home/prescript/article/mots_0243-6450_1980_num_1_1_1008>.
46
 *  
47
**/
48

    
49
@Field @Option(name="f", usage="La fréquence de la forme dans la partie", widget="Integer", required=true, def="11")
50
def f;
51

    
52
@Field @Option(name="F", usage="La fréquence totale de la forme dans le corpus", widget="Integer", required=true, def="296")
53
def F;
54

    
55
@Field @Option(name="t", usage="Le nombre d'occurrences de la partie", widget="Integer", required=true, def="1084")
56
def t;
57

    
58
@Field @Option(name="T", usage="Le nombre total d'occurrences du corpus", widget="Integer", required=true, def="61449")
59
def T;
60

    
61
// Open the parameters input dialog box
62
if (!ParametersDialog.open(this)) return;
63

    
64
// END OF PARAMETERS
65

    
66
def r = RWorkspace.getRWorkspaceInstance()
67
def file = File.createTempFile("txm", ".svg", new File(Toolbox.getParam(Toolbox.USER_TXM_HOME), "results"))
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
});