Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / export / MultipleConcordances.groovy @ 399

History | View | Annotate | Download (3.6 kB)

1 321 mdecorde
/**
2 321 mdecorde
 * Main.
3 321 mdecorde
 *
4 321 mdecorde
 * @param args the args
5 321 mdecorde
 */
6 321 mdecorde
// Copyright © 2010-2013 ENS de Lyon.
7 321 mdecorde
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
8 321 mdecorde
// Lyon 2, University of Franche-Comté, University of Nice
9 321 mdecorde
// Sophia Antipolis, University of Paris 3.
10 321 mdecorde
//
11 321 mdecorde
// The TXM platform is free software: you can redistribute it
12 321 mdecorde
// and/or modify it under the terms of the GNU General Public
13 321 mdecorde
// License as published by the Free Software Foundation,
14 321 mdecorde
// either version 2 of the License, or (at your option) any
15 321 mdecorde
// later version.
16 321 mdecorde
//
17 321 mdecorde
// The TXM platform is distributed in the hope that it will be
18 321 mdecorde
// useful, but WITHOUT ANY WARRANTY; without even the implied
19 321 mdecorde
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 321 mdecorde
// PURPOSE. See the GNU General Public License for more
21 321 mdecorde
// details.
22 321 mdecorde
//
23 321 mdecorde
// You should have received a copy of the GNU General
24 321 mdecorde
// Public License along with the TXM platform. If not, see
25 321 mdecorde
// http://www.gnu.org/licenses.
26 321 mdecorde
27 321 mdecorde
//
28 321 mdecorde
// This file is part of the TXM platform.
29 321 mdecorde
//
30 321 mdecorde
// The TXM platform is free software: you can redistribute it and/or modif y
31 321 mdecorde
// it under the terms of the GNU General Public License as published by
32 321 mdecorde
// the Free Software Foundation, either version 3 of the License, or
33 321 mdecorde
// (at your option) any later version.
34 321 mdecorde
//
35 321 mdecorde
// The TXM platform is distributed in the hope that it will be useful,
36 321 mdecorde
// but WITHOUT ANY WARRANTY; without even the implied warranty of
37 321 mdecorde
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38 321 mdecorde
// GNU General Public License for more details.
39 321 mdecorde
//
40 321 mdecorde
// You should have received a copy of the GNU General Public License
41 321 mdecorde
// along with the TXM platform.  If not, see <http://www.gnu.org/licenses/>.
42 321 mdecorde
//
43 321 mdecorde
//
44 321 mdecorde
//
45 321 mdecorde
// $LastChangedDate: 2011-05-09 14:58:28 +0200 (lun., 09 mai 2011) $
46 321 mdecorde
// $LastChangedRevision: 1839 $
47 321 mdecorde
// $LastChangedBy: mdecorde $
48 321 mdecorde
//
49 321 mdecorde
50 321 mdecorde
package org.txm.export
51 321 mdecorde
52 321 mdecorde
// import the packages containing the functions we are going to use
53 393 mdecorde
import org.txm.concordance.core.functions.*
54 393 mdecorde
import org.txm.concordance.core.functions.comparators.*
55 399 mdecorde
import org.txm.searchengine.cqp.ReferencePattern
56 399 mdecorde
import org.txm.searchengine.cqp.corpus.*
57 399 mdecorde
import org.txm.searchengine.cqp.corpus.query.*
58 321 mdecorde
59 321 mdecorde
//PARAMETRES
60 321 mdecorde
def corpusname = "DISCOURS"
61 321 mdecorde
def requetes = ["je", "tu", "vous"]
62 321 mdecorde
// get the DISCOURS corpus
63 321 mdecorde
// TODO: Auto-generated Javadoc
64 321 mdecorde
65 321 mdecorde
/* (non-Javadoc)
66 321 mdecorde
 * @see groovy.lang.Script#run()
67 321 mdecorde
 */
68 321 mdecorde
def discours = CorpusManager.getCorpusManager().getCorpus(corpusname)
69 321 mdecorde
70 321 mdecorde
// get some properties
71 321 mdecorde
def pos = discours.getProperty("pos")
72 321 mdecorde
def word = discours.getProperty("word")
73 321 mdecorde
def text = discours.getStructuralUnit("text")
74 321 mdecorde
75 321 mdecorde
//get structure text
76 321 mdecorde
def text_id = text.getProperty("id")
77 321 mdecorde
// and define the references pattern for each concordance line
78 321 mdecorde
def referencePattern = new ReferencePattern().addProperty(text_id)
79 321 mdecorde
80 321 mdecorde
// get a builtin sort function
81 321 mdecorde
def comparator = new LexicographicLeftContextComparator()
82 321 mdecorde
comparator.initialize(discours)
83 321 mdecorde
84 321 mdecorde
def noconc = 0
85 321 mdecorde
for(String querystring : requetes)
86 321 mdecorde
{
87 321 mdecorde
        println "Computing concordance of $querystring ..."
88 321 mdecorde
        // create a query. Here the concordance keyword will be the French word "Je" (the "I" pronoun in English)
89 321 mdecorde
        def query = new Query(Query.fixQuery(querystring))
90 321 mdecorde
91 321 mdecorde
        // compute the concordance with contexts of 15 words on each side of the keyword
92 321 mdecorde
        def concordance = new Concordance(discours, query, word, [word, pos], referencePattern, 15, 15)
93 321 mdecorde
94 321 mdecorde
        // sort the concordance
95 321 mdecorde
        //concordance.sort(comparator)
96 321 mdecorde
97 321 mdecorde
        // define which occurrence properties will be displayed
98 321 mdecorde
        concordance.setViewProperties([word])
99 321 mdecorde
100 321 mdecorde
        // write all the concordance in a text file
101 321 mdecorde
        def file = new File("conc"+(noconc++)+".txt")
102 321 mdecorde
        concordance.toTxt(file, "UTF-8")
103 321 mdecorde
        println("Concordance $querystring written in file: "+file.getAbsolutePath())
104 321 mdecorde
}