Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macroproto / cqp / SaveSubCorpusMacro.groovy @ 822

History | View | Annotate | Download (1.9 kB)

1
// STANDARD DECLARATIONS
2
package org.txm.macroproto.cqp
3

    
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcpapplication.swt.widget.parameters.*
7
import org.txm.Toolbox
8
import org.txm.searchengine.cqp.*
9
import org.txm.searchengine.cqp.corpus.*
10
import org.txm.utils.*
11

    
12
if (!(corpusViewSelection instanceof Subcorpus)) {
13
        println "Selection is not a Corpus: $corpusViewSelection"
14
        return false
15
}
16

    
17
def CQI = Toolbox.getCqiClient();
18
if ((CQI instanceof NetCqiClient)) {
19
        println "Error: only available in CQP memory mode"
20
        return;
21
}
22

    
23
@Field @Option(name="outputDir", usage="an example file", widget="Folder", required=true, def="")
24
def outputDir
25

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

    
29
// END OF PARAMETERS
30

    
31
println "corpora selection: "+corpusViewSelection
32

    
33
MainCorpus maincorpus = corpusViewSelection.getMainCorpus()
34
File outputFile = new File(outputDir, corpusViewSelection.getQualifiedCqpId())
35
File regFile = new File(maincorpus.getBaseDirectory(), "registry")
36
if (!regFile.exists()) {
37
        println "Could not find corpus registry file $regFile"
38
        return
39
}
40

    
41
def outputStream = new FileOutputStream(outputFile);
42
LittleEndianOutputStream outputStreamBin = new LittleEndianOutputStream(outputStream);
43

    
44
outputStreamBin.writeInt(36193928+1);
45
outputStreamBin.writeBytes(regFile.getAbsolutePath()+"/");
46
outputStreamBin.write(0)
47
outputStreamBin.writeBytes(maincorpus.getName());
48
//outputStreamBin.write(0)
49
l2 = outputStreamBin.size()-3
50

    
51
//for (int i = 0; (i+l2)%4 != 0; i++) 
52
outputStreamBin.writeInt(0);
53

    
54
def matches = corpusViewSelection.getMatches()
55
outputStreamBin.writeInt(matches.size())
56

    
57
for (def match : matches) {
58
        outputStreamBin.writeInt(match.getStart());
59
        outputStreamBin.writeInt(match.getEnd());
60
}
61

    
62
outputStreamBin.writeInt(0) // sortidx
63
outputStreamBin.writeInt(0) // targets
64
outputStreamBin.writeInt(0) // keywords
65
outputStreamBin.close()
66

    
67
println "Subcorpus saved in "+outputFile.getAbsolutePath()