Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / macro / cqp / CreateCQPListMacro.groovy @ 187

History | View | Annotate | Download (3.8 kB)

1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
//
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
//
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
//
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21

    
22
package org.txm.macro.cqp
23

    
24
/*
25
This macro allows you to define CQL lists which you can call in CQP queries during the current session.
26
To use this macro for your own lists,
27
1. Find below an example of the type of list you want to create
28
   (case 1 = explicit list, or case 2 = list from file),
29
2. Copy then paste this example (5 lines) after the given examples
30
3. Give the name for your list as a string after list_name=
31
4. Give the content of the list as a string after
32
either list_value= (for case 1, explicit list)
33
or list_path= (for case 2, list from file).
34
5. Save this file (macro code)
35
6. Run the macro by double-clicking on it.
36
The lists are defined only for the current session.
37
To use the same lists in a new session, just run the macro to generate the lists again.
38
*/
39

    
40
import org.txm.Toolbox
41
import org.txm.searchengine.cqp.*
42

    
43
def CQI = Toolbox.getCqiClient();
44
if ((CQI instanceof NetCqiClient)) {
45
        println "Error: only available in CQP memory mode"
46
        return;
47
}
48

    
49
def list_name=""
50
def list_value=""
51
def list_path=""
52
def cqp_value=""
53
File f;
54
try {
55

    
56
// BEGIN CONFIGURATION HERE
57

    
58
// 1st case : explicit lists
59
list_name = "negatif"
60
list_value = "rien non ne pas sans"
61

    
62
cqp_statement = "define \$$list_name = \"$list_value\";"
63
println "CQP executes : $cqp_statement"
64
CQI.query(cqp_statement)
65

    
66
// two other examples of 1st case (explicit list)
67
// 1st explicit list
68
list_name = "evaluation"
69
list_value = "trop assez peu bien très beaucoup vraiment"
70

    
71
cqp_statement = "define \$$list_name = \"$list_value\";"
72
println "CQP executes : $cqp_statement"
73
CQI.query(cqp_statement)
74

    
75
// 2nd explicit list
76
list_name = "categoriesmotsvides"
77
list_value = "ABR ADV DET:ART DET:POS INT KON NUM PRO PRO:DEM PRO:IND PRO:PER PRO:POS PRO:REL PRP PRP:det PUN PUN:cit SENT SYM"
78

    
79
cqp_statement = "define \$$list_name = \"$list_value\";"
80
println "CQP executes : $cqp_statement"
81
CQI.query(cqp_statement)
82

    
83
// one example of regular expression list to be used with RE()
84
list_name = "regexp_categoriesmotsvides"
85
list_value = "ABR ADV DET.* INT KON NUM PRO.* PRP.* PUN.* SENT SYM"
86

    
87
cqp_statement = "define \$$list_name = \"$list_value\";"
88
println "CQP executes : $cqp_statement"
89
CQI.query(cqp_statement)
90

    
91
// 2nd case : list from a file
92

    
93
list_name = "motsvides"
94
list_path = System.getProperty("user.home")+"/TXM/cqp/listes/stopwords_fr_ranknl.txt"
95
// Windows users must replace "/" with "\\". 
96
// for instance : 
97
// list_path = System.getProperty("user.home")+"\\TXM\\cqp\\listes\\stopwords_fr_ranknl.txt"
98
f = new File(list_path);
99
if (f.exists()) {
100
        cqp_statement = "define \$$list_name < \"$list_path\";"
101
        println "CQP executes : $cqp_statement"
102
        CQI.query(cqp_statement)
103
} else {
104
        println "Error: \"$f\" file does not exists"
105
}
106

    
107
/*
108
You can comment a group of several lines of code
109
using stars and slash like this.
110
*/
111

    
112
// END OF CONFIGURATION
113

    
114
} catch (Exception e) {
115
        println "Error during the \"$list_name\" list creation with the \"$list_value\" value"
116
        println "CPQ statement was \"$cqp_statement\""
117
        if (f != null) println "Last CQL file path was \"$f\""
118
}