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
/**
2
 * Main.
3
 *
4
 * @param args the args
5
 */
6
// Copyright © 2010-2013 ENS de Lyon.
7
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
8
// Lyon 2, University of Franche-Comté, University of Nice
9
// Sophia Antipolis, University of Paris 3.
10
// 
11
// The TXM platform is free software: you can redistribute it
12
// and/or modify it under the terms of the GNU General Public
13
// License as published by the Free Software Foundation,
14
// either version 2 of the License, or (at your option) any
15
// later version.
16
// 
17
// The TXM platform is distributed in the hope that it will be
18
// useful, but WITHOUT ANY WARRANTY; without even the implied
19
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20
// PURPOSE. See the GNU General Public License for more
21
// details.
22
// 
23
// You should have received a copy of the GNU General
24
// Public License along with the TXM platform. If not, see
25
// http://www.gnu.org/licenses.
26
// 
27
// 
28
// 
29
// $LastChangedDate: 2015-10-22 10:13:24 +0200 (jeu. 22 oct. 2015) $
30
// $LastChangedRevision: 3041 $
31
// $LastChangedBy: finnishgazelle $ 
32
//
33

    
34
package org.txm.scripts.test
35

    
36
// import the packages containing the functions we are going to use
37
import org.txm.Toolbox
38
import org.txm.searchengine.cqp.corpus.*
39
import org.txm.searchengine.cqp.corpus.query.*
40
import org.txm.concordance.core.functions.Concordance
41
import org.txm.concordance.core.functions.comparators.LexicographicLeftContextComparator
42
import org.txm.functions.concordances.*
43
import org.txm.functions.concordances.comparators.*
44
import org.txm.searchengine.cqp.ReferencePattern
45

    
46
        // get the DISCOURS corpus
47
        // TODO: Auto-generated Javadoc
48

    
49
        /* (non-Javadoc)
50
         * @see groovy.lang.Script#run()
51
         */
52
        def discours = CorpusManager.getCorpusManager().getCorpus("VOEUX")
53
        
54
        // get some properties
55
        def pos = discours.getProperty("pos")
56
        def word = discours.getProperty("word")
57
        def text = discours.getStructuralUnit("text")
58
        def text_id = text.getProperty("id")
59

    
60
        // create a query. Here the concordance keyword will be the French word "Je" (the "I" pronoun in English)
61
        def query = new Query(Query.fixQuery("je"))
62
        
63
        // define the references pattern for each concordance line
64
        def referencePattern = new ReferencePattern().addProperty(text_id)
65
        def sortReferencePattern = new ReferencePattern().addProperty(text_id)
66

    
67
        // compute the concordance with contexts of 15 words on each side of the keyword
68
        def concordance = new Concordance(discours, query, word, [word, pos], referencePattern,sortReferencePattern, 15, 15)
69

    
70
        // get a builtin sort function
71
        def comparator = new LexicographicLeftContextComparator()
72
        comparator.initialize(discours)
73

    
74
        
75
        // sort the concordance
76
        concordance.sort(comparator)
77
        
78
        // define which occurrence properties will be displayed
79
        concordance.setViewProperties([word])
80
        
81
        // write all the concordance in a text file
82
        def file = new File("conc.txt")
83
        concordance.toTxt(file, "UTF-8")
84
        
85
        println("Concordance written in file: "+ file.getAbsolutePath())