Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / tests / tests_cql.groovy @ 399

History | View | Annotate | Download (8.7 kB)

1
package tests
2
import org.txm.Toolbox
3
import org.txm.rcp.views.*
4
import org.txm.rcp.views.corpora.CorporaView
5
import org.txm.searchengine.cqp.MemCqiServer
6
import org.txm.searchengine.cqp.corpus.*
7

    
8
// Debug
9
println "******************************** Starting ********************************************";
10

    
11

    
12
// Tests suite de requêtes directement sur le serveur et création manuelle du sous-corpus
13

    
14
// parameters
15
def CORPUS = "LIVRETOPERA10TEXTES"
16
//def SUBCORPUS = "NOMDUSOUSCORPUS"
17
// def SUBCORPUS = null // si partition sur corpus
18
//def SUBCORPUSQUERY = '"je" expand to s'
19
//def SUBCORPUSQUERY = null // si sous-corpus par nom
20

    
21

    
22
def discours = CorpusManager.getCorpusManager().getCorpus(CORPUS)
23
def subcorpusCqpId = 'S' + UUID.randomUUID().toString();
24

    
25
try {
26
        def server = (MemCqiServer)Toolbox.getCqiServer();
27
        
28
//        server.query('show corpora;');
29
//        server.query("info " + CORPUS + ";");
30
        
31
        server.query(CORPUS + ";");
32
        
33
        //client.query(SUBCORPUSQUERY);
34

    
35
        // Suppression de variable de résultats
36
//        server.query("discard A;");
37
//        server.query("discard B;");
38
//        server.query("discard C;");
39
        
40
//        server.query('C = /region[sp,a]::a.sp_who="IPHIS";');
41

    
42
        
43
// Test mono ligne : ne fonctionne pas en mode server
44
//        server.query('A = /region[sp]; B = /region[speaker]; C = difference B A;');
45
                
46
        
47
                
48
//        server.query('A = /region[sp];');
49
//        server.query('B = /region[speaker];');
50
//        server.query('C = difference A B;');
51

    
52
        // Tests options d'affichage
53
        server.query('show cd;');
54
        server.query('show +div1 +div2 +sp +lg +l +speaker;'); // Affichage des balises XML dans les listes de résultats
55
        //server.query('set ShowTagAttributes on;');
56
        
57
        // Tests
58
//        server.query('A = /region[sp,a]::a.sp_who="THALIE";');
59
//        server.query('B = /region[speaker];');
60
//        server.query(subcorpusCqpId + ' = diff A B;');
61

    
62
        
63
        //server.query(subcorpusCqpId + ' = B;');
64
        
65
        
66
        
67
//        server.query(subcorpusCqpId + ' = <sp>[(_.) != "speaker"]+</sp>;');
68
        //server.query(subcorpusCqpId + ' = <div1>[]*<sp>[]+</sp>[]*</div1>;');
69

    
70
        //server.query(subcorpusCqpId + ' = <div1>[!speaker]*</div1>;');
71
        
72
// server.query(subcorpusCqpId + ' = <lg>[_.div1_n=".*" & _.sp_who="THALIE"]+</lg>;');        
73
//        server.query(subcorpusCqpId + ' = /region[i];');
74
        
75

    
76
        // Tests de requête sur le sous-corpus créé
77
        //server.query('set MatchingStrategy shortest;'); // standard, shortest, longest, traditional
78
        //server.query(subcorpusCqpId + ' = [div1 & _.sp_who="THALIE" & !speaker];');
79
        //server.query(subcorpusCqpId + ' = [_.div1_name=".*" & !speaker];');
80
        //server.query(subcorpusCqpId + ' = [_.div1_name=".*" & !speaker] expand to lg;');
81
        server.query(subcorpusCqpId + ' = [div1 & !speaker] expand to lg;');
82
        
83
        
84
        //server.query('group ' + subcorpusCqpId + ' match word;');
85

    
86
        server.query(subcorpusCqpId + ';');
87
        
88
                
89
        //server.query(subcorpusCqpId + ' = [] !;');
90
        //server.query(subcorpusCqpId + ';');
91
        //server.query(subcorpusCqpId + ' = [] !;');
92
//        server.query(subcorpusCqpId + ' = [] expand to div1 & !speaker;');
93
        
94
        
95
        
96
        //server.query(subcorpusCqpId + ' = [div1 & !speaker];');
97
        //server.query(subcorpusCqpId + ' = [div1 & !speaker] expand to lg;');
98
        //server.query(subcorpusCqpId + ' = [div1 & !speaker] expand to lg;');
99
        
100
        //server.query(subcorpusCqpId + ' = [div1 & !speaker];');
101
        
102
        //server.query(subcorpusCqpId + ' = [div1 &_.sp_who="THALIE" & !speaker];');
103
        
104
        //server.query(subcorpusCqpId + ' = [div1 &_.sp_who="THALIE" & !speaker];');
105
        //server.query(subcorpusCqpId + ' = "fin" [];');
106
        //server.query(subcorpusCqpId + ' = [div1 & _.sp_who="THALIE" & !speaker];');
107
        
108
        // Affichage du sous-corpus
109
        //server.query("cat " + subcorpusCqpId + " 0 10;")
110
        server.query("cat " + subcorpusCqpId + ";")
111
        
112
        //server.cqpQuery(discours.getCqpId(), 'subcorpusid', SUBCORPUSQUERY);
113

    
114
                
115
        
116
        // Affichage des erreurs
117
        try {
118
                System.out.println("client.getLastCqiError() : "+server.getLastCqiError());
119
        } catch(Exception e) { System.out.println("Exception : "+e);}
120
        try {
121
                System.out.println("client.getLastCQPError() : "+server.getLastCQPError());
122
        } catch(Exception e) { System.out.println("Exception : "+e);}
123

    
124
        
125
        
126
        // Création manuelle du sous-corpus
127
//        Subcorpus subcorpus = new Subcorpus(subcorpusCqpId, "subcorpus" + subcorpusCqpId.toString().substring(0, 5), discours, new Query()); // FIXME : est-ce que cela pose un problème de passer une Query() vide ici ?
128
//        discours.subcorpora.add(subcorpus);
129
//        subcorpus.registerToParent();
130
        
131
        // Création manuelle d'une partition
132
//        subcorpus.createPartition(NAME, QUERIES, PARTNAMES)
133
        
134
        
135
}
136
 catch(Exception e) {
137
          System.out.println("Exception : "+e);
138
  }
139

    
140

    
141

    
142
// Refresh de l'interface
143
monitor.syncExec(new Runnable() {
144
        public void run() {
145
                CorporaView.refresh();
146
                //CorporaView.expand(partition.getParent());
147
        }
148
});
149

    
150

    
151

    
152

    
153

    
154

    
155
//// parameters
156
//def CORPUS = "LIVRETOPERA10TEXTES"
157
////def SUBCORPUS = "NOMDUSOUSCORPUS"
158
//def SUBCORPUS = null // si partition sur corpus
159
////def SUBCORPUSQUERY = '"je" expand to s'
160
//def SUBCORPUSQUERY = null // si sous-corpus par nom
161
//
162
//
163
//
164
//// Liste des unités strcuturelles
165
////def HIERARCHY = ['text_id', 'div1_n', 'sp_who', 'lg'];
166
//def STRUCTURAL_UNITS = ['text', 'div1', 'sp'];
167
//def STRUCTURAL_UNITS_PROPERTIES = ['id', 'n', 'who'];
168
////def TARGET = 'lg';
169
//
170
//String NAME = '';
171

    
172

    
173

    
174

    
175
//def TEXT = "01_ACHILLE ET POLYXENE"
176
// def TEXT = "02_ZEPHIRE ET FLORE"
177
/*def QUERIES = [
178
'<lg>[_.text_id="' + TEXT + '" & _.div1_n="1" & _.sp_who=".*"]+</lg>',
179
'<lg>[_.text_id="' + TEXT + '" & _.div1_n="2" & _.sp_who=".*"]+</lg>',
180
'<lg>[_.text_id="' + TEXT + '" & _.div1_n="3" & _.sp_who=".*"]+</lg>',
181
'<lg>[_.text_id="' + TEXT + '" & _.div1_n="4" & _.sp_who=".*"]+</lg>',
182
'<lg>[_.text_id="' + TEXT + '" & _.div1_n="5" & _.sp_who=".*"]+</lg>',
183
]
184
def PARTNAMES = [
185
"acte_1",
186
"acte_2",
187
"acte_3",
188
"acte_4",
189
"acte_5",
190
]*/
191

    
192

    
193
//def discours = CorpusManager.getCorpusManager().getCorpus(CORPUS)
194
//
195
//
196
//// Récupération des unités structurelles
197
//def i = 0;
198
//def supName;
199
//def QUERIES;
200
//def query;
201
//
202
//for (suName in STRUCTURAL_UNITS) {
203
//
204
//
205
//        // Définition auto du nom de partition
206
//        NAME += suName + '_';
207
//
208
//        //query = '';
209
//        
210
//        
211
//        println "Structural Unit Name: $suName"
212
//        
213
//        // Récupération des valeurs des propriétés d'unités structurelles
214
//        for (sup in discours.getStructuralUnitProperties(suName.asType(String)))        {
215
//                
216
//                supName = STRUCTURAL_UNITS_PROPERTIES[i];
217
//                
218
//                if(supName != '' && sup.getName() == supName)        {
219
//                        
220
//                        // Définition auto du nom de partition
221
//                        NAME += supName + ".";
222
//                        
223
//                        println "Structural Unit Property: $supName";
224
//                        
225
//                        for (supValue in sup.getOrderedValues()) {
226
//                        
227
//                                //query += '<' + TARGET + '>' + supName;
228
//                                
229
//                                
230
//                                print "$supValue "
231
//                        }
232
//                }
233
//        }
234
//        i++;
235
//}
236
//
237
//// Suppression du dernier underscore ou point
238
//NAME = NAME.substring(0, NAME.length() - 1);
239
//// Debug
240
//println "NAME: " + NAME;
241

    
242

    
243

    
244

    
245

    
246

    
247

    
248

    
249
// start
250
/*if (QUERIES.size() == PARTNAMES.size()) {
251

252
        def partition;
253

254
        
255
        // Test unités structurelles
256
        for (t in discours.getStructuralUnits()) {
257
                println "Structural Unit: $t"
258
                
259
                // Test propriétés d'unités structurelles
260
                for (g in discours.getStructuralUnitProperties(t.asType(String))) {
261
                        
262
                        println "\tStructural Unit Property: $g"
263
                        
264
                        // Test valeurs des propriétés d'unités structurelles
265
                        for (h in g.getOrderedValues()) {
266
                                
267
                                print "$h, "
268
                                
269
                        }
270
                        
271
                }
272
                
273
        }
274
        
275
                
276
        // Test propriétés
277
        for (t in discours.getProperties()) {
278
                println "Property: $t"
279
        }
280
        
281
        
282
        if (SUBCORPUS == null) {
283
                println "partition build with $discours"
284
                partition = discours.createPartition(NAME, QUERIES, PARTNAMES)
285
        } else {
286
                def subcorpus
287
                if (SUBCORPUSQUERY == null) {
288
                        println "partition build with subcorpus by name $SUBCORPUS"
289
                        subcorpus = discours.getSubcorpusByName(SUBCORPUS)
290
                        if (subcorpus == null) {
291
                                println "Error: SUBCORPUS NOT FOUND with name : $SUBCORPUS"
292
                        }
293
                } else {
294
                        println "partition build with subcorpus with query $SUBCORPUSQUERY"
295
                        subcorpus = discours.createSubcorpus(new Query(SUBCORPUSQUERY), SUBCORPUS)
296
                }
297
                partition = subcorpus.createPartition(NAME, QUERIES, PARTNAMES)
298
        }
299
        
300
        def list = Arrays.asList(partition.getPartSizes())
301
        println "Partition created $NAME: "+list+" parts"
302
        // println "Total size: "+list.sum()+" - is equal to (sub)corpus size : "+(list.sum() == partition.getCorpus().getSize())
303
    println "Total size: "+list.sum()+" - (sub)corpus size : "+(partition.getCorpus().getSize())
304
        
305
        monitor.syncExec(new Runnable() {
306
        public void run() {
307
                CorporaView.refresh();
308
                CorporaView.expand(partition.getParent());
309
        }
310
});
311
} else {
312
        println "QUERIES.size() != PARTNAMES.size() = "+QUERIES.size()+" != "+PARTNAMES.size()
313
}*/
314