Révision 3322

TXM/trunk/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/CQPUtils.groovy (revision 3322)
2 2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3 3
// @author sheiden
4 4

  
5
package org.txm.macro.cqp
5
package org.txm.macro.urs.exploit
6 6

  
7 7
import org.txm.searchengine.cqp.corpus.*
8
import org.txm.rcp.views.corpora.*
8 9

  
10
def refreshCorpusViewExpand(monitor, corpus) {
11
	monitor.syncExec(new Runnable() {
12
		public void run() {
13
			CorporaView.refresh()
14
			CorporaView.expand(corpus)
15
		}
16
	})
17
}
18

  
9 19
def getCorpusByName(name) {
10 20
	def cl = CorpusManager.getCorpusManager().getCorpora()
11 21
	def rc = cl.find {
TXM/trunk/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/Units2SubCorpusMacro.groovy (revision 3322)
1
package org.txm.macro.urs.exploit
2

  
3
// Copyright © 2021 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 sheiden
6

  
7

  
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.rcpapplication.swt.widget.parameters.*
11
import org.txm.searchengine.cqp.*
12
import org.txm.searchengine.cqp.corpus.*
13
import org.txm.searchengine.cqp.corpus.query.*
14
import org.txm.*
15
import org.txm.rcpapplication.views.*
16
//import org.txm.macro.cqp.CQPUtils
17
import org.txm.annotation.urs.URSCorpora
18
import org.txm.macro.urs.AnalecUtils
19

  
20
// BEGINNING OF PARAMETERS
21

  
22
// Declare each parameter here
23
// (available widget types: Query, File, Folder, String, Text, Boolean, Integer, Float and Date)
24

  
25
@Field @Option(name="subcorpus_name", usage="name of the subcorpus result", widget="String", required=true, def="subcorpus1")
26
def subcorpus_name
27

  
28
@Field @Option(name="unit_ursql", usage="TYPE@PROP=VALUE", widget="String", required=false, def="MENTION")
29
String unit_ursql
30

  
31
@Field @Option(name="debug", usage="Show debug information", widget="StringArray", metaVar="OFF	ON	ALL	REALLY ALL", required=false, def="OFF")
32
debug
33

  
34
// Open the parameters input dialog box
35
if (!ParametersDialog.open(this)) return false
36

  
37
if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3
38

  
39
def CQI = CQPSearchEngine.getCqiClient()
40

  
41
def scriptName = this.class.getSimpleName()
42

  
43
def utils = new CQPUtils()
44

  
45
corpora = utils.getCorpora(this)
46

  
47
if ((corpora == null) || corpora.size() > 1) {
48
	println "** $scriptName: please select a corpus in the Corpus view or provide a corpus name. Aborting."
49
	return false
50
}
51

  
52
corpus = corpora[0].getMainCorpus()
53
corpusName = corpus.getName()
54

  
55
if (!URSCorpora.isAnnotationStructureReady(corpus)) {
56
	println "** URS Annotation Structure of "+corpusName+" is not ready. Aborting."
57
	return
58
}
59

  
60
def analecCorpus = URSCorpora.getCorpus(corpus)
61
	
62
def selectedUnits = AnalecUtils.selectUnitsInSchema(debug, analecCorpus, corpus, null, 0, 1000000, unit_ursql, 0, null, false, 0)
63

  
64
nUnits = selectedUnits.size()
65
query = ""
66

  
67
if (nUnits == 0) {
68
	println "No units selected, no subcorpus created."
69
	return
70
} else {
71
	println nUnits+" units selected."
72
	positionsList = selectedUnits.collect {
73
		[it.getDeb(), it.getFin()]
74
	}
75
	query = utils.positions2cql(utils.positionsList2positions(positionsList, 20, false))
76
}
77

  
78
String resultCqpId = CqpObject.subcorpusNamePrefix + CQPCorpus.getNextSubcorpusCounter()
79
String queryString = "$resultCqpId=$query;"
80

  
81
CQI.query(queryString)
82

  
83
def subcorpus = corpora[0].createSubcorpus(new CQLQuery("$query;"), subcorpus_name)
84

  
85
if (binding.variables["monitor"]) {
86
	utils.refreshCorpusViewExpand(monitor, subcorpus.getParent())
87
}
88

  
89
return true
90

  
91

  
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/cqp/CQPUtils.groovy (revision 3322)
5 5
package org.txm.macro.cqp
6 6

  
7 7
import org.txm.searchengine.cqp.corpus.*
8
import org.txm.rcp.views.corpora.*
8 9

  
10
def refreshCorpusViewExpand(monitor, corpus) {
11
	monitor.syncExec(new Runnable() {
12
		public void run() {
13
			CorporaView.refresh()
14
			CorporaView.expand(corpus)
15
		}
16
	})
17
}
18

  
9 19
def getCorpusByName(name) {
10 20
	def cl = CorpusManager.getCorpusManager().getCorpora()
11 21
	def rc = cl.find {

Formats disponibles : Unified diff