Statistics
| Revision:

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

History | View | Annotate | Download (3.8 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 479 mdecorde
import org.txm.Toolbox
54 399 mdecorde
import org.txm.searchengine.cqp.corpus.*
55 399 mdecorde
import org.txm.searchengine.cqp.corpus.query.*
56 479 mdecorde
import org.txm.concordance.core.functions.Concordance
57 479 mdecorde
import org.txm.concordance.core.functions.comparators.LexicographicLeftContextComparator
58 479 mdecorde
import org.txm.functions.concordances.*
59 479 mdecorde
import org.txm.functions.concordances.comparators.*
60 479 mdecorde
import org.txm.searchengine.cqp.ReferencePattern
61 321 mdecorde
62 321 mdecorde
//PARAMETRES
63 479 mdecorde
def corpusname = "VOEUX"
64 321 mdecorde
def requetes = ["je", "tu", "vous"]
65 321 mdecorde
// get the DISCOURS corpus
66 321 mdecorde
// TODO: Auto-generated Javadoc
67 321 mdecorde
68 321 mdecorde
/* (non-Javadoc)
69 321 mdecorde
 * @see groovy.lang.Script#run()
70 321 mdecorde
 */
71 321 mdecorde
def discours = CorpusManager.getCorpusManager().getCorpus(corpusname)
72 321 mdecorde
73 321 mdecorde
// get some properties
74 321 mdecorde
def pos = discours.getProperty("pos")
75 321 mdecorde
def word = discours.getProperty("word")
76 321 mdecorde
def text = discours.getStructuralUnit("text")
77 321 mdecorde
78 321 mdecorde
//get structure text
79 321 mdecorde
def text_id = text.getProperty("id")
80 321 mdecorde
// and define the references pattern for each concordance line
81 321 mdecorde
def referencePattern = new ReferencePattern().addProperty(text_id)
82 321 mdecorde
83 321 mdecorde
// get a builtin sort function
84 321 mdecorde
def comparator = new LexicographicLeftContextComparator()
85 321 mdecorde
comparator.initialize(discours)
86 321 mdecorde
87 321 mdecorde
def noconc = 0
88 321 mdecorde
for(String querystring : requetes)
89 321 mdecorde
{
90 321 mdecorde
        println "Computing concordance of $querystring ..."
91 321 mdecorde
        // create a query. Here the concordance keyword will be the French word "Je" (the "I" pronoun in English)
92 321 mdecorde
        def query = new Query(Query.fixQuery(querystring))
93 321 mdecorde
94 321 mdecorde
        // compute the concordance with contexts of 15 words on each side of the keyword
95 321 mdecorde
        def concordance = new Concordance(discours, query, word, [word, pos], referencePattern, 15, 15)
96 321 mdecorde
97 321 mdecorde
        // sort the concordance
98 321 mdecorde
        //concordance.sort(comparator)
99 321 mdecorde
100 321 mdecorde
        // define which occurrence properties will be displayed
101 321 mdecorde
        concordance.setViewProperties([word])
102 321 mdecorde
103 321 mdecorde
        // write all the concordance in a text file
104 321 mdecorde
        def file = new File("conc"+(noconc++)+".txt")
105 321 mdecorde
        concordance.toTxt(file, "UTF-8")
106 321 mdecorde
        println("Concordance $querystring written in file: "+file.getAbsolutePath())
107 321 mdecorde
}