Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / prototypes / References.groovy @ 2163

History | View | Annotate | Download (3.2 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 479 mdecorde
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun. 06 mai 2013) $
46 321 mdecorde
// $LastChangedRevision: 2386 $
47 321 mdecorde
// $LastChangedBy: mdecorde $
48 321 mdecorde
//
49 1000 mdecorde
package org.txm.scripts.test
50 321 mdecorde
51 321 mdecorde
//we import the packages containing the functions we are going to use
52 479 mdecorde
import org.txm.Toolbox
53 626 sjacqu01
import org.txm.referencer.core.functions.Referencer;
54 479 mdecorde
import org.txm.searchengine.cqp.corpus.*
55 479 mdecorde
import org.txm.searchengine.cqp.corpus.query.*
56 399 mdecorde
import org.txm.functions.referencer.*
57 399 mdecorde
import org.txm.searchengine.cqp.ReferencePattern
58 321 mdecorde
59 321 mdecorde
// TODO: Auto-generated Javadoc
60 321 mdecorde
/* (non-Javadoc)
61 321 mdecorde
 * @see groovy.lang.Script#run()
62 321 mdecorde
 */
63 321 mdecorde
Corpus discours = CorpusManager.getCorpusManager().getCorpus("DISCOURS")
64 321 mdecorde
65 321 mdecorde
// we get some properties
66 321 mdecorde
Property word = discours.getProperty("word")
67 321 mdecorde
StructuralUnit text = discours.getStructuralUnit("text")
68 321 mdecorde
StructuralUnitProperty text_id = text.getProperty("id")
69 321 mdecorde
70 321 mdecorde
// we create a query to find the positions
71 321 mdecorde
Query query = new Query(Query.fixQuery("j.*"))
72 321 mdecorde
73 321 mdecorde
// what the index must show
74 321 mdecorde
ReferencePattern referencePattern = new ReferencePattern().addProperty(text_id)
75 321 mdecorde
76 321 mdecorde
//define the referencer
77 321 mdecorde
// We want the references of the words who matche the query "je" in the discours corpus
78 321 mdecorde
long time = System.currentTimeMillis()
79 321 mdecorde
Referencer ref = new Referencer(discours, query, word, referencePattern.getProperties())
80 321 mdecorde
ref.compute()
81 321 mdecorde
println "time get positions : "+(System.currentTimeMillis()-time)
82 321 mdecorde
83 321 mdecorde
time = System.currentTimeMillis()
84 321 mdecorde
def lines =ref.getLines()
85 321 mdecorde
println "time get "+lines.size()+" lines : "+(System.currentTimeMillis()-time)
86 321 mdecorde
87 321 mdecorde
File file = new File("ref.txt")
88 321 mdecorde
ref.toTxt(file, "UTF-8")
89 321 mdecorde
println "writen in : "+file.getAbsolutePath()