Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / commands / mesures / Magnitude.groovy @ 1000

History | View | Annotate | Download (3.6 kB)

1
package org.txm.scripts.functions.mesures;
2

    
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.HashMap;
6
import java.util.List;
7

    
8
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
9
import org.txm.searchengine.cqp.corpus.Corpus;
10
import org.txm.searchengine.cqp.corpus.QueryResult;
11
import org.txm.searchengine.cqp.corpus.query.Match;
12
import org.txm.searchengine.cqp.corpus.query.Query;
13

    
14
/**
15
 * 
16
 * Magnitude synonymes
17
extent        Magnitude, importance, extension, superficie, longueur
18
magnitude        Magnitude, grandeur, magnitude
19
amplitude        amplitude, Magnitude, largeur
20
fullness        plénitude, Magnitude, abondance
21
width        largeur, Magnitude
22
fulness        plénitude, Magnitude, abondance
23
richness        richesse, abondance, Magnitude, luxe, fertilité
24
ampleness        Magnitude
25
thoroughness        minutie, Magnitude
26
roundness        rondeur, circularité, Magnitude, franchise
27

28
 * @author mdecorde
29
 *
30
 */
31
public class Magnitude extends Mesure {
32

    
33
        private static final long serialVersionUID = 3317066047569716511L;
34

    
35
        private static String TMP = "TMP";
36
        
37
        public Magnitude(String domaine, String unit, Synthese[] syntheses) {
38
                this.domaine = domaine;
39
                this.unit= unit;
40
                this.syntheses = syntheses;
41

    
42
                //if (synthese.equals(Synthese.NONE)) this.synthese = Synthese.SUM; // NO synthese will sum the matches size
43
        }
44

    
45
        @Override
46
        public boolean compute(ArrayList<Corpus> corpora) {
47
                this.corpora = corpora;
48

    
49
                //                switch (synthese) {
50
                //                case COUNTMATCHES:
51
                //                        return computeCounts();
52
                //                case MAX:
53
                //                case MIN:
54
                //                case MEAN:
55
                //                case QUARTILE1:
56
                //                case QUARTILE3:
57
                //                case MEDIAN:
58
                //                case NONE:
59
                //                case SUM:
60
                return computeSynthese();
61
                //                default:
62
                //                        System.out.println("UNSUPPORTED SYNTHESIS: "+synthese);
63
                //                        return false;
64
                //                }
65
        }
66

    
67
        //        private boolean computeCounts() {
68
        //                Integer[] rez = new Integer[corpora.size()];
69
        //                for (int i = 0 ; i < corpora.size() ; i++) {
70
        //                        Corpus corpus = corpora.get(i);
71
        //                        try {
72
        //                                rez[i] = computeCount(corpus);
73
        //                        } catch (CqiClientException e) {
74
        //                                e.printStackTrace();
75
        //                                return false;
76
        //                        }
77
        //                }
78
        //                this.add(new MesureResult(this, rez, "Magnitude synt="+synthese+" unit="+unit+" dom="+domaine));
79
        //                return true;
80
        //        }
81

    
82
        //        private int computeCount(Corpus corpus) throws CqiClientException {
83
        //                QueryResult result = corpus.query(new Query(domaine), TMP);
84
        //                return result.getNMatch();
85
        //        }
86
        HashMap<Synthese, Object[]> rezPerSynthese = new HashMap<Synthese, Object[]>();
87
        private boolean computeSynthese() {
88

    
89
                for (Synthese synt : syntheses) {
90
                        rezPerSynthese.put(synt, new Object[corpora.size()]);
91
                }
92

    
93
                for (int i = 0 ; i < corpora.size() ; i++) {
94
                        Corpus corpus = corpora.get(i);
95
                        try {
96
                                computeSynthese(i, corpus);
97
                        } catch (CqiClientException e) {
98
                                e.printStackTrace();
99
                                return false;
100
                        }
101
                }
102
                for ( Synthese synt : syntheses) {
103
                        this.add(new MesureResult(this, rezPerSynthese.get(synt), "Magnitude synt="+synt+" unit="+unit+" dom="+domaine));
104
                }
105
                return true;
106
        }
107

    
108
        private void computeSynthese(int icorpus, Corpus corpus) throws CqiClientException {
109
        QueryResult result = corpus.query(new Query(domaine), TMP, false);                
110
                List<Match> matches = result.getMatches();
111
                Integer[] sizes = new Integer[matches.size()];
112
                for (int i = 0 ; i < matches.size() ; i++) {
113
                        Match m  = matches.get(i);
114
                        sizes[i] = m.getEnd() - m.getStart() + 1;
115
                }
116
                
117
                builder = new SyntheseBuilder(sizes);
118
                for (Synthese synt : syntheses) {
119
                        Object[] rez = rezPerSynthese.get(synt);
120
                        if (synt.equals(Synthese.NONE)) {
121
                                rez[icorpus] = builder.doSynthese(Synthese.SUM);
122
                        } else {
123
                                rez[icorpus] = builder.doSynthese(synt);
124
                        }
125
                }
126
        }
127
}