Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / prototypes / Concordances.groovy @ 1000

History | View | Annotate | Download (2.9 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
//
29 479 mdecorde
// $LastChangedDate: 2015-10-22 10:13:24 +0200 (jeu. 22 oct. 2015) $
30 321 mdecorde
// $LastChangedRevision: 3041 $
31 321 mdecorde
// $LastChangedBy: finnishgazelle $
32 321 mdecorde
//
33 321 mdecorde
34 1000 mdecorde
package org.txm.scripts.test
35 321 mdecorde
36 321 mdecorde
// import the packages containing the functions we are going to use
37 479 mdecorde
import org.txm.Toolbox
38 399 mdecorde
import org.txm.searchengine.cqp.corpus.*
39 399 mdecorde
import org.txm.searchengine.cqp.corpus.query.*
40 479 mdecorde
import org.txm.concordance.core.functions.Concordance
41 479 mdecorde
import org.txm.concordance.core.functions.comparators.LexicographicLeftContextComparator
42 479 mdecorde
import org.txm.functions.concordances.*
43 479 mdecorde
import org.txm.functions.concordances.comparators.*
44 479 mdecorde
import org.txm.searchengine.cqp.ReferencePattern
45 321 mdecorde
46 321 mdecorde
        // get the DISCOURS corpus
47 321 mdecorde
        // TODO: Auto-generated Javadoc
48 321 mdecorde
49 321 mdecorde
        /* (non-Javadoc)
50 321 mdecorde
         * @see groovy.lang.Script#run()
51 321 mdecorde
         */
52 321 mdecorde
        def discours = CorpusManager.getCorpusManager().getCorpus("VOEUX")
53 321 mdecorde
54 321 mdecorde
        // get some properties
55 321 mdecorde
        def pos = discours.getProperty("pos")
56 321 mdecorde
        def word = discours.getProperty("word")
57 321 mdecorde
        def text = discours.getStructuralUnit("text")
58 321 mdecorde
        def text_id = text.getProperty("id")
59 321 mdecorde
60 321 mdecorde
        // create a query. Here the concordance keyword will be the French word "Je" (the "I" pronoun in English)
61 321 mdecorde
        def query = new Query(Query.fixQuery("je"))
62 321 mdecorde
63 321 mdecorde
        // define the references pattern for each concordance line
64 321 mdecorde
        def referencePattern = new ReferencePattern().addProperty(text_id)
65 321 mdecorde
        def sortReferencePattern = new ReferencePattern().addProperty(text_id)
66 321 mdecorde
67 321 mdecorde
        // compute the concordance with contexts of 15 words on each side of the keyword
68 321 mdecorde
        def concordance = new Concordance(discours, query, word, [word, pos], referencePattern,sortReferencePattern, 15, 15)
69 321 mdecorde
70 321 mdecorde
        // get a builtin sort function
71 321 mdecorde
        def comparator = new LexicographicLeftContextComparator()
72 321 mdecorde
        comparator.initialize(discours)
73 321 mdecorde
74 321 mdecorde
75 321 mdecorde
        // sort the concordance
76 321 mdecorde
        concordance.sort(comparator)
77 321 mdecorde
78 321 mdecorde
        // define which occurrence properties will be displayed
79 321 mdecorde
        concordance.setViewProperties([word])
80 321 mdecorde
81 321 mdecorde
        // write all the concordance in a text file
82 321 mdecorde
        def file = new File("conc.txt")
83 321 mdecorde
        concordance.toTxt(file, "UTF-8")
84 321 mdecorde
85 321 mdecorde
        println("Concordance written in file: "+ file.getAbsolutePath())