Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / export / ExportLT.groovy @ 187

History | View | Annotate | Download (1.3 kB)

1 187 sjacqu01
package org.txm.export
2 187 sjacqu01
import org.txm.Toolbox
3 187 sjacqu01
import org.txm.searchengine.cqp.corpus.*
4 187 sjacqu01
import org.txm.searchengine.cqp.corpus.query.*
5 187 sjacqu01
import org.txm.stat.data.*;
6 187 sjacqu01
import org.txm.functions.cooccurrences.*
7 187 sjacqu01
8 187 sjacqu01
9 187 sjacqu01
def corpus = CorpusManager.getCorpusManager().getCorpus("DISCOURS") // mettre le nom du corpus en Majuscules ici
10 187 sjacqu01
def partition = corpus.getPartition("types");
11 187 sjacqu01
12 187 sjacqu01
int NTable = 1;
13 187 sjacqu01
for (Object o : partition.getResults()) {
14 187 sjacqu01
//        if (o instanceof LexicalTable) {
15 187 sjacqu01
                File outfile = new File("lt${NTable}.txt")
16 187 sjacqu01
                println "export LT of $partition in "+outfile.getAbsolutePath();
17 187 sjacqu01
                NTable++;
18 187 sjacqu01
                outfile.withWriter{writer->
19 187 sjacqu01
                def lt = o;
20 187 sjacqu01
                println "found lexical table: "+lt.getName()
21 187 sjacqu01
                println "n col: "+lt.getNColumns()
22 187 sjacqu01
                println "n line: "+lt.getNRows()
23 187 sjacqu01
                def cols = lt.getColNames().asStringsArray();
24 187 sjacqu01
                String strline = "unit\t";
25 187 sjacqu01
                for (int i = 0 ; i < cols.length ; i++) {
26 187 sjacqu01
                        strline += cols[i]+"\t"
27 187 sjacqu01
28 187 sjacqu01
                }
29 187 sjacqu01
                writer.println(strline.substring(0, strline.length()-1));
30 187 sjacqu01
31 187 sjacqu01
                def rows = lt.getRowNames().asStringsArray();
32 187 sjacqu01
                for (int i = 0 ; i < rows.length ; i++) {
33 187 sjacqu01
                        strline = "";
34 187 sjacqu01
                        strline += rows[i]+"\t";
35 187 sjacqu01
                        def line = lt.getRow(i).asIntArray();
36 187 sjacqu01
                        for (int j = 0 ; j < line.length ; j++)
37 187 sjacqu01
                                strline += line[j]+"\t";
38 187 sjacqu01
                        writer.println(strline.substring(0, strline.length()-1));
39 187 sjacqu01
                }
40 187 sjacqu01
41 187 sjacqu01
                writer.close();
42 187 sjacqu01
                }
43 187 sjacqu01
//        }
44 187 sjacqu01
}