Statistics
| Revision:

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

History | View | Annotate | Download (3.8 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
// This file is part of the TXM platform.
29
//
30
// The TXM platform is free software: you can redistribute it and/or modif y
31
// it under the terms of the GNU General Public License as published by
32
// the Free Software Foundation, either version 3 of the License, or
33
// (at your option) any later version.
34
//
35
// The TXM platform is distributed in the hope that it will be useful,
36
// but WITHOUT ANY WARRANTY; without even the implied warranty of
37
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38
// GNU General Public License for more details.
39
//
40
// You should have received a copy of the GNU General Public License
41
// along with the TXM platform.  If not, see <http://www.gnu.org/licenses/>.
42
// 
43
// 
44
// 
45
// $LastChangedDate: 2011-05-09 14:58:28 +0200 (lun., 09 mai 2011) $
46
// $LastChangedRevision: 1839 $
47
// $LastChangedBy: mdecorde $ 
48
//
49

    
50
package org.txm.export
51

    
52
// import the packages containing the functions we are going to use
53
import org.txm.Toolbox
54
import org.txm.searchengine.cqp.corpus.*
55
import org.txm.searchengine.cqp.corpus.query.*
56
import org.txm.concordance.core.functions.Concordance
57
import org.txm.concordance.core.functions.comparators.LexicographicLeftContextComparator
58
import org.txm.functions.concordances.*
59
import org.txm.functions.concordances.comparators.*
60
import org.txm.searchengine.cqp.ReferencePattern
61

    
62
//PARAMETRES
63
def corpusname = "VOEUX"
64
def requetes = ["je", "tu", "vous"]
65
// get the DISCOURS corpus
66
// TODO: Auto-generated Javadoc
67

    
68
/* (non-Javadoc)
69
 * @see groovy.lang.Script#run()
70
 */
71
def discours = CorpusManager.getCorpusManager().getCorpus(corpusname)
72

    
73
// get some properties
74
def pos = discours.getProperty("pos")
75
def word = discours.getProperty("word")
76
def text = discours.getStructuralUnit("text")
77

    
78
//get structure text
79
def text_id = text.getProperty("id")
80
// and define the references pattern for each concordance line
81
def referencePattern = new ReferencePattern().addProperty(text_id)
82

    
83
// get a builtin sort function
84
def comparator = new LexicographicLeftContextComparator()
85
comparator.initialize(discours)
86

    
87
def noconc = 0
88
for(String querystring : requetes)
89
{
90
        println "Computing concordance of $querystring ..."
91
        // create a query. Here the concordance keyword will be the French word "Je" (the "I" pronoun in English)
92
        def query = new Query(Query.fixQuery(querystring))
93
        
94
        // compute the concordance with contexts of 15 words on each side of the keyword
95
        def concordance = new Concordance(discours, query, word, [word, pos], referencePattern, 15, 15)
96
                
97
        // sort the concordance
98
        //concordance.sort(comparator)
99
        
100
        // define which occurrence properties will be displayed
101
        concordance.setViewProperties([word])
102
        
103
        // write all the concordance in a text file
104
        def file = new File("conc"+(noconc++)+".txt")
105
        concordance.toTxt(file, "UTF-8")
106
        println("Concordance $querystring written in file: "+file.getAbsolutePath())
107
}