Revision 1336

tmp/org.txm.groovy.core/src/groovy/org/txm/macro/commands/AdvancedPartitionMacro.groovy (revision 1336)
1
// Copyright © 2018 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde, sheiden
4

  
5
package org.txm.macro.commands
6

  
7
// STANDARD DECLARATIONS
8

  
9
import org.txm.rcpapplication.swt.widget.parameters.*
10
import org.txm.searchengine.cqp.corpus.*
11
import org.txm.rcpapplication.views.CorporaView
12

  
13
def scriptName = this.class.getSimpleName()
14

  
15
if (!(corpusViewSelection instanceof Corpus)) {
16
	println "** $scriptName: please select a Corpus in the Corpus view."
17
	return 0
18
}
19

  
20
def corpus = corpusViewSelection
21

  
22
// PARAMETERS ...................................
23
// - NAME: name of the partition to build
24
// - PARTNAMES: list of each partition part name
25
// - QUERIES: list of each partition part building query (must have the same length as PARTNAMES)
26

  
27
def NAME = "decennies"
28

  
29
def PARTNAMES = [
30
"60s", 
31
"70s",
32
"80s",
33
"90s",
34
"2000s",
35
"2010s",
36
]
37

  
38
def QUERIES = [
39
'[_.text_annee="(1959|196.)"] expand to text', 
40
'[_.text_annee="197."] expand to text', 
41
'[_.text_annee="198."] expand to text', 
42
'[_.text_annee="199."] expand to text', 
43
'[_.text_annee="200."] expand to text', 
44
'[_.text_annee="201."] expand to text', 
45
]
46

  
47
// end of PARAMETERS
48

  
49
// BODY
50

  
51
if (QUERIES.size() == PARTNAMES.size()) {
52

  
53
	def partition
54
	
55
	println "Building partition on $corpus (size = "+(corpus.getSize())+")."
56
	
57
	partition = corpus.createPartition(NAME, QUERIES, PARTNAMES)
58
	
59
	def list = Arrays.asList(partition.getPartSizes())
60

  
61
	println "'$NAME' partition created, parts sizes = "+list+", Σ(parts) = "+list.sum()+"."
62

  
63
	// println "Total size: "+list.sum()+" - is equal to (sub)corpus size : "+(list.sum() == partition.getCorpus().getSize())
64
	
65
	monitor.syncExec(new Runnable() {
66
	public void run() {
67
		CorporaView.refresh()
68
		CorporaView.expand(partition.getParent())
69
	}
70
})
71
} else {
72
	println "** $scriptName: PARTNAMES.size() != QUERIES.size(), ("+PARTNAMES.size()+" != "+QUERIES.size()+")."
73
	return 0
74
}
75

  

Also available in: Unified diff