Révision 2148

tmp/org.txm.analec.rcp/src/org/txm/macro/urs/democrat/BuildSectionsMacro.groovy (revision 2148)
1
package org.txm.macro.urs.democrat
2

  
3
import org.txm.searchengine.cqp.corpus.*
4
import org.txm.rcpapplication.views.*
5
import org.txm.searchengine.cqp.corpus.query.*
6
import org.txm.Toolbox
7

  
8
def scriptName = this.class.getSimpleName()
9
def utils = new org.txm.macro.urs.exploit.CQPUtils()
10

  
11
// Création des 4 sous-corpus de chapitres
12

  
13
[1, 2, 3, 4].each { chapitre ->
14
	res = gse.run(SubCorpusMacro, ["args":[ "corpus":"DIDEROTESSAIS", "name":"Chapitre "+chapitre, "query":"[_.div_n1=\""+chapitre+"\"] expand to div1" ],
15
                                "selection":selection,
16
                                "selections":selections,
17
                                "corpusViewSelection":corpusViewSelection,
18
                                "corpusViewSelections":corpusViewSelections,
19
                                "monitor":monitor])
20
	if (!res) println "** problem calling SubCorpusMacro."
21
}
22

  
23

  
24
// Définition des paragraphes dans les 4 chapitres
25

  
26
def para = [
27
[1, 14, 17, 22],
28
[2, 29, 44, 46],
29
[3, 53, 63, 66],
30
[4, 74, 75, 79]
31
]
32

  
33
// get the CQP corpus
34
if (!(corpusViewSelection instanceof CQPCorpus)) {
35
	println "Corpus view selection is no a corpus: $corpusViewSelection"
36
	return false;
37
}
38
def corpus = corpusViewSelection
39
if (corpus.getName() != "DIDEROTESSAIS") {
40
	println "Warning: this macro was made to work for the DIDEROTESSAIS corpus"
41
}
42
	
43
para.each { chapitre ->
44

  
45
	println chapitre
46

  
47
	def subcorpus = corpus.getSubcorpusByName("Chapitre "+chapitre[0])
48

  
49
	println "chap = "+subcorpus
50

  
51
	[1, 2, 3].each { num ->
52

  
53
		def p = chapitre[num]
54

  
55
		println "p = "+p
56

  
57
		name = "p "+p
58
		query = '[_.p_n=\"'+p+'\"] expand to p'
59

  
60
		res = gse.run(SubCorpusMacro, ["args":[ "name":name, "query":query ],
61
                                "corpusViewSelections":[subcorpus],
62
								"corpusViewSelection":subcorpus,
63
                                "monitor":monitor])
64
		
65

  
66
	} // [1, 2, 3].each
67

  
68
} // para.each
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/democrat/SubCorpusMacro.groovy (revision 2148)
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
	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

  
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/CQPUtils.groovy (revision 2148)
5 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

  
9 10
def getCorpusByName(name) {
10
	def cl = CorpusManager.getCorpusManager().getCorpora()
11
	def cl = CorpusManager.getCorpusManager().getCorpora().values()
11 12
	def rc = cl.find {
12 13
		it.getID() == name
13 14
	}
......
26 27
	return rsc
27 28
}
28 29

  
30
def refreshCorpusViewExpand(monitor, corpus) {
31
	monitor.syncExec(new Runnable() {
32
		public void run() {
33
			CorporaView.refresh()
34
			CorporaView.expand(corpus)
35
		}
36
	})
37
}
38

  
29 39
def getCorpora(def script) {
30 40

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

Formats disponibles : Unified diff