Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / commands / AdvancedPartitionMacro.groovy @ 1336

History | View | Annotate | Download (1.9 kB)

1 1336 mdecorde
// Copyright © 2018 ENS de Lyon, CNRS, University of Franche-Comté
2 1336 mdecorde
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3 1336 mdecorde
// @author mdecorde, sheiden
4 1336 mdecorde
5 1336 mdecorde
package org.txm.macro.commands
6 1336 mdecorde
7 1336 mdecorde
// STANDARD DECLARATIONS
8 1336 mdecorde
9 1336 mdecorde
import org.txm.rcpapplication.swt.widget.parameters.*
10 1336 mdecorde
import org.txm.searchengine.cqp.corpus.*
11 1336 mdecorde
import org.txm.rcpapplication.views.CorporaView
12 1336 mdecorde
13 1336 mdecorde
def scriptName = this.class.getSimpleName()
14 1336 mdecorde
15 1336 mdecorde
if (!(corpusViewSelection instanceof Corpus)) {
16 1336 mdecorde
        println "** $scriptName: please select a Corpus in the Corpus view."
17 1336 mdecorde
        return 0
18 1336 mdecorde
}
19 1336 mdecorde
20 1336 mdecorde
def corpus = corpusViewSelection
21 1336 mdecorde
22 1336 mdecorde
// PARAMETERS ...................................
23 1336 mdecorde
// - NAME: name of the partition to build
24 1336 mdecorde
// - PARTNAMES: list of each partition part name
25 1336 mdecorde
// - QUERIES: list of each partition part building query (must have the same length as PARTNAMES)
26 1336 mdecorde
27 1336 mdecorde
def NAME = "decennies"
28 1336 mdecorde
29 1336 mdecorde
def PARTNAMES = [
30 1336 mdecorde
"60s",
31 1336 mdecorde
"70s",
32 1336 mdecorde
"80s",
33 1336 mdecorde
"90s",
34 1336 mdecorde
"2000s",
35 1336 mdecorde
"2010s",
36 1336 mdecorde
]
37 1336 mdecorde
38 1336 mdecorde
def QUERIES = [
39 1336 mdecorde
'[_.text_annee="(1959|196.)"] expand to text',
40 1336 mdecorde
'[_.text_annee="197."] expand to text',
41 1336 mdecorde
'[_.text_annee="198."] expand to text',
42 1336 mdecorde
'[_.text_annee="199."] expand to text',
43 1336 mdecorde
'[_.text_annee="200."] expand to text',
44 1336 mdecorde
'[_.text_annee="201."] expand to text',
45 1336 mdecorde
]
46 1336 mdecorde
47 1336 mdecorde
// end of PARAMETERS
48 1336 mdecorde
49 1336 mdecorde
// BODY
50 1336 mdecorde
51 1336 mdecorde
if (QUERIES.size() == PARTNAMES.size()) {
52 1336 mdecorde
53 1336 mdecorde
        def partition
54 1336 mdecorde
55 1336 mdecorde
        println "Building partition on $corpus (size = "+(corpus.getSize())+")."
56 1336 mdecorde
57 1336 mdecorde
        partition = corpus.createPartition(NAME, QUERIES, PARTNAMES)
58 1336 mdecorde
59 1336 mdecorde
        def list = Arrays.asList(partition.getPartSizes())
60 1336 mdecorde
61 1336 mdecorde
        println "'$NAME' partition created, parts sizes = "+list+", Σ(parts) = "+list.sum()+"."
62 1336 mdecorde
63 1336 mdecorde
        // println "Total size: "+list.sum()+" - is equal to (sub)corpus size : "+(list.sum() == partition.getCorpus().getSize())
64 1336 mdecorde
65 1336 mdecorde
        monitor.syncExec(new Runnable() {
66 1336 mdecorde
        public void run() {
67 1336 mdecorde
                CorporaView.refresh()
68 1336 mdecorde
                CorporaView.expand(partition.getParent())
69 1336 mdecorde
        }
70 1336 mdecorde
})
71 1336 mdecorde
} else {
72 1336 mdecorde
        println "** $scriptName: PARTNAMES.size() != QUERIES.size(), ("+PARTNAMES.size()+" != "+QUERIES.size()+")."
73 1336 mdecorde
        return 0
74 1336 mdecorde
}