Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / test / Concordances.groovy @ 345

History | View | Annotate | Download (2.7 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 (Thu, 22 Oct 2015) $
30
// $LastChangedRevision: 3041 $
31
// $LastChangedBy: finnishgazelle $ 
32
//
33

    
34
package org.txm.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.concordances.functions.*
41
import org.txm.concordances.functions.comparators.*
42
import org.txm.functions.ReferencePattern
43

    
44
        // get the DISCOURS corpus
45
        // TODO: Auto-generated Javadoc
46

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

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

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

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

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