Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / prototypes / commands / PrunePartitionMacro.groovy @ 2246

History | View | Annotate | Download (1.5 kB)

1
// STANDARD DECLARATIONS
2
package org.txm.macro
3

    
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcp.swt.widget.parameters.*
7
import org.txm.searchengine.cqp.corpus.*
8

    
9
// BEGINNING OF PARAMETERS
10

    
11

    
12
@Field @Option(name="min", usage="F min", widget="Float", required=false, def="18")
13
def min
14

    
15
@Field @Option(name="relative", usage="min is a % of the total frequency", widget="Boolean", required=false, def="false")
16
def relative
17

    
18
@Field @Option(name="doIt", usage="delete the selected parts", widget="Boolean", required=false, def="false")
19
def doIt
20

    
21
@Field @Option(name="debug", usage="show debug messages", widget="Boolean", required=false, def="false")
22
def debug
23

    
24
// Open the parameters input dialog box
25
if (!ParametersDialog.open(this)) return;
26

    
27
// END OF PARAMETERS
28

    
29
if (!(corpusViewSelection instanceof Partition)) {
30
        println "Aborting, the selection is not a Partition: $corpusViewSelection"
31
        return
32
}
33

    
34
def partition = corpusViewSelection
35
partition.compute(false) // ensure parts are ready to use
36

    
37
int F = 0;
38
for (def part : partition.getParts()) {
39
        F += part.getSize();
40
}
41
if (debug) println "F=$F"
42
if (relative) {
43
        min = (F*min)/100
44
}
45
if (debug)  println "F min threshold=$min"
46

    
47
def toDelete = []
48
for (def part : partition.getParts()) {
49
        if (part.getSize() < min) {
50
                toDelete << part
51
        }
52
}
53
if (toDelete.size() > 0) {
54
        println (doIt?"Deleting ${toDelete.size()} parts: $toDelete":"Selected parts $toDelete")
55
        for (def part : toDelete) {
56
                if (doIt) part.delete()
57
        }
58
}
59
println "Done"