Révision 3349
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/cqp/Positions2SubCorpusMacro.groovy (revision 3349) | ||
---|---|---|
1 |
package org.txm.macro.urs.democrat; |
|
2 |
|
|
3 |
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté |
|
4 |
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses) |
|
5 |
// @author mdecorde |
|
6 |
// @author sheiden |
|
7 |
|
|
8 |
|
|
9 |
import org.kohsuke.args4j.* |
|
10 |
import groovy.transform.Field |
|
11 |
import org.txm.rcpapplication.swt.widget.parameters.* |
|
12 |
import org.txm.searchengine.cqp.* |
|
13 |
import org.txm.searchengine.cqp.corpus.* |
|
14 |
import org.txm.searchengine.cqp.corpus.query.* |
|
15 |
import org.txm.* |
|
16 |
import org.txm.rcpapplication.views.* |
|
17 |
|
|
18 |
// BEGINNING OF PARAMETERS |
|
19 |
|
|
20 |
// Declare each parameter here |
|
21 |
// (available widget types: Query, File, Folder, String, Text, Boolean, Integer, Float and Date) |
|
22 |
|
|
23 |
@Field @Option(name="name", usage="name of the subcorpus result", widget="String", required=true, def="subcorpus1") |
|
24 |
|
|
25 |
def name |
|
26 |
|
|
27 |
@Field @Option(name="positions", usage="literal corpus position intervals list (aka 'matches list') to build subcorpus (eg '0,1,2-3,4-5,6')", widget="String", required=true, def="0,1,2-3,4-5,6") |
|
28 |
def positions |
|
29 |
|
|
30 |
// Open the parameters input dialog box |
|
31 |
if (!ParametersDialog.open(this)) return false |
|
32 |
|
|
33 |
def CQI = CQPSearchEngine.getCqiClient() |
|
34 |
|
|
35 |
def scriptName = this.class.getSimpleName() |
|
36 |
|
|
37 |
def utils = new org.txm.macro.urs.exploit.CQPUtils() |
|
38 |
|
|
39 |
if ((positions == null) || positions.length() == 0) { |
|
40 |
println "** $scriptName: please provide a 'positions' interval list. Aborting." |
|
41 |
return false |
|
42 |
} |
|
43 |
|
|
44 |
query = utils.positions2cql(positions) |
|
45 |
|
|
46 |
if (query.length() == 0) { |
|
47 |
println "** $scriptName: impossible to interpret the 'positions' value. Incorrect syntax? Aborting." |
|
48 |
return false |
|
49 |
} |
|
50 |
|
|
51 |
def corpora = utils.getCorpora(this) |
|
52 |
|
|
53 |
if ((corpora == null) || corpora.size() == 0) { |
|
54 |
println "** $scriptName: please select a corpus in the Corpus view or provide a corpus name. Aborting." |
|
55 |
return false |
|
56 |
} |
|
57 |
|
|
58 |
/* |
|
59 |
CorpusManager.getCorpusManager().getCorpora().each { |
|
60 |
if (it.getSubcorpusByName(name)) { |
|
61 |
println "** Subcorpus: sub-corpus name already used. Please use another sub-corpus name. Aborting." |
|
62 |
return false |
|
63 |
} |
|
64 |
// it.getSubcorpora().each { sub -> println it.getName()+" subcorpora: "+sub.getName() } |
|
65 |
} |
|
66 |
*/ |
|
67 |
|
|
68 |
String resultCqpId = CqpObject.subcorpusNamePrefix + CQPCorpus.getNextSubcorpusCounter() |
|
69 |
String queryString = "$resultCqpId=$query;" |
|
70 |
|
|
71 |
CQI.query(queryString) |
|
72 |
|
|
73 |
def subcorpus = corpora[0].createSubcorpus(new CQLQuery("$query;"), name) |
|
74 |
|
|
75 |
if (binding.variables["monitor"]) { |
|
76 |
utils.refreshCorpusViewExpand(monitor, subcorpus.getParent()) |
|
77 |
} |
|
78 |
|
|
79 |
return true |
|
80 |
|
|
81 |
|
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/cqp/ListMatchesMacro.groovy (revision 3349) | ||
---|---|---|
1 |
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté |
|
2 |
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses) |
|
3 |
// @author mdecorde |
|
4 |
// @author sheiden |
|
5 |
|
|
1 | 6 |
// STANDARD DECLARATIONS |
2 |
package org.txm.macroproto.cqp
|
|
7 |
package org.txm.macro.cqp |
|
3 | 8 |
|
4 | 9 |
import org.kohsuke.args4j.* |
5 | 10 |
import groovy.transform.Field |
... | ... | |
9 | 14 |
import org.txm.searchengine.cqp.corpus.* |
10 | 15 |
import org.txm.utils.* |
11 | 16 |
|
12 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
13 |
println "Selection is not a Corpus: $corpusViewSelection" |
|
17 |
|
|
18 |
@Field @Option(name="maxMatches", usage="maximum number of intervals to list", widget="Integer", required=true, def="1000") |
|
19 |
def maxMatches |
|
20 |
|
|
21 |
@Field @Option(name="pretty", usage="pretty print intervals list", widget="Boolean", required=true, def="true") |
|
22 |
def pretty |
|
23 |
|
|
24 |
// Open the parameters input dialog box |
|
25 |
if (!ParametersDialog.open(this)) return false |
|
26 |
|
|
27 |
def CQI = CQPSearchEngine.getCqiClient() |
|
28 |
|
|
29 |
def scriptName = this.class.getSimpleName() |
|
30 |
|
|
31 |
def utils = new org.txm.macro.urs.exploit.CQPUtils() |
|
32 |
|
|
33 |
def corpora = utils.getCorpora(this) |
|
34 |
|
|
35 |
if ((corpora == null) || corpora.size() == 0) { |
|
36 |
println "** $scriptName: please select a corpus in the Corpus view or provide a corpus name. Aborting." |
|
14 | 37 |
return false |
15 | 38 |
} |
16 |
corpusViewSelection.compute(false) |
|
17 |
println corpusViewSelection.getMatches() |
|
39 |
|
|
40 |
corpora.each { corpus -> |
|
41 |
|
|
42 |
corpus.compute(false) |
|
43 |
println corpus.getName()+" ("+corpus.getMatches().size()+") : "+utils.corpus2positions(corpus, maxMatches, pretty) |
|
44 |
} |
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/cqp/CQL2SubCorpusMacro.groovy (revision 3349) | ||
---|---|---|
1 |
package org.txm.macro.cqp; |
|
2 |
|
|
3 |
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté |
|
4 |
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses) |
|
5 |
// @author mdecorde |
|
6 |
// @author sheiden |
|
7 |
|
|
8 |
|
|
9 |
import org.kohsuke.args4j.* |
|
10 |
import groovy.transform.Field |
|
11 |
import org.txm.rcpapplication.swt.widget.parameters.* |
|
12 |
import org.txm.searchengine.cqp.* |
|
13 |
import org.txm.searchengine.cqp.corpus.* |
|
14 |
import org.txm.searchengine.cqp.corpus.query.* |
|
15 |
import org.txm.* |
|
16 |
import org.txm.rcpapplication.views.* |
|
17 |
|
|
18 |
// BEGINNING OF PARAMETERS |
|
19 |
|
|
20 |
// Declare each parameter here |
|
21 |
// (available widget types: Query, File, Folder, String, Text, Boolean, Integer, Float and Date) |
|
22 |
|
|
23 |
@Field @Option(name="name", usage="name of the subcorpus result", widget="String", required=true, def="subcorpus1") |
|
24 |
def name |
|
25 |
|
|
26 |
@Field @Option(name="query", usage="query to build subcorpus", widget="String", required=true, def="n:[] :: n = 0 expand to 10") |
|
27 |
def query |
|
28 |
/* |
|
29 |
|
|
30 |
n:[] [] [] [] [] [] [] [] [] [] :: n = 0 |
|
31 |
n:[] :: n = 0 expand to 10 |
|
32 |
|
|
33 |
*/ |
|
34 |
|
|
35 |
// Open the parameters input dialog box |
|
36 |
if (!ParametersDialog.open(this)) return false |
|
37 |
|
|
38 |
def CQI = CQPSearchEngine.getCqiClient() |
|
39 |
|
|
40 |
def scriptName = this.class.getSimpleName() |
|
41 |
|
|
42 |
def utils = new org.txm.macro.urs.exploit.CQPUtils() |
|
43 |
|
|
44 |
def corpora = utils.getCorpora(this) |
|
45 |
|
|
46 |
if ((corpora == null) || corpora.size() == 0) { |
|
47 |
println "** $scriptName: please select a corpus in the Corpus view or provide a corpus name. Aborting." |
|
48 |
return false |
|
49 |
} |
|
50 |
|
|
51 |
/* |
|
52 |
CorpusManager.getCorpusManager().getCorpora().each { |
|
53 |
if (it.getSubcorpusByName(name)) { |
|
54 |
println "** Subcorpus: sub-corpus name already used. Please use another sub-corpus name. Aborting." |
|
55 |
return false |
|
56 |
} |
|
57 |
// it.getSubcorpora().each { sub -> println it.getName()+" subcorpora: "+sub.getName() } |
|
58 |
} |
|
59 |
*/ |
|
60 |
|
|
61 |
String resultCqpId = CqpObject.subcorpusNamePrefix + CQPCorpus.getNextSubcorpusCounter() |
|
62 |
String queryString = "$resultCqpId=$query;" |
|
63 |
|
|
64 |
CQI.query(queryString) |
|
65 |
|
|
66 |
def subcorpus = corpora[0].createSubcorpus(new CQLQuery("$query;"), name) |
|
67 |
|
|
68 |
if (binding.variables["monitor"]) { |
|
69 |
utils.refreshCorpusViewExpand(monitor, subcorpus.getParent()) |
|
70 |
} |
|
71 |
|
|
72 |
return true |
|
73 |
|
|
74 |
|
Formats disponibles : Unified diff