Revision 2105 tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/SchemasProgressionMacro.groovy

SchemasProgressionMacro.groovy (revision 2105)
12 12
import org.kohsuke.args4j.*
13 13
import org.txm.Toolbox
14 14
import org.txm.annotation.urs.*
15
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences
15 16
import org.txm.chartsengine.r.core.RChartsEngine
16 17
import org.txm.macro.urs.AnalecUtils
17 18
import org.txm.progression.core.chartsengine.jfreechart.themes.highcharts.renderers.ProgressionItemSelectionRenderer
......
26 27
import visuAnalec.elements.*
27 28

  
28 29
def scriptName = this.class.getSimpleName()
29
def parent
30

  
30 31
def selection = []
31
if (!(corpusViewSelection instanceof CQPCorpus)) {
32
	println "** $scriptName please select a Corpus to run the macro"
33
	return;
32
for (def s : corpusViewSelections) {
33
	if (s instanceof CQPCorpus) selection << s
34
	else if (s instanceof Partition) selection.addAll(s.getParts())
34 35
}
35
selection << corpusViewSelection // only one corpus for progression
36
parent = corpusViewSelection
37 36

  
37
if (selection.size() == 0) {
38
	println "** $scriptName: please select a Corpus or a Partition in the Corpus view: "+corpusViewSelections
39
	return false
40
} else {
41
	for (def c : selection) c.compute(false)
42
}
43

  
38 44
// BEGINNING OF PARAMETERS
39
@Field @Option(name="sep", usage="Schemas and units selection part", widget="Separator", required=true, def="Selection")
45
@Field @Option(name="sep", usage="Schemas and units selection part", widget="Separator", required=false, def="Selection")
40 46
String sep
41 47
@Field @Option(name="schema_ursql", usage="TYPE@PROP=VALUE", widget="String", required=true, def="CHAINE")
42 48
		String schema_ursql
......
56 62
		boolean strict_inclusion
57 63
@Field @Option(name="position_in_matches", usage="Unit distance to structure limit (0 = no selection, 1 = first after limit, -1 = last before limit, etc.)", widget="Integer", required=true, def="0")
58 64
		int position_in_matches
59
@Field @Option(name="sep2", usage="Progression command parameters", widget="Separator", required=true, def="Progression")
65
@Field @Option(name="sep2", usage="Progression command parameters", widget="Separator", required=false, def="Progression")
60 66
		String sep2
61 67
@Field @Option(name="struct_name", usage="Structure to display", widget="String", required=true, def="div")
62 68
		String struct_name
......
81 87

  
82 88
def CQI = CQPSearchEngine.getCqiClient()
83 89

  
84
def cql_limit_matches = null;
85
if (cql_limit != null && !cql_limit.getQueryString().equals("\"\"")) {
86
	def limitssubcorpus = parent.createSubcorpus(cql_limit, parent.getName().toUpperCase())
87
	cql_limit_matches = limitssubcorpus.getMatches();
88
	limitssubcorpus.delete();
89
} else {
90
	cql_limit_matches = parent.getMatches()
91
}
92 90

  
91

  
93 92
def queries = []
94 93
def queryResults = []
95 94
def informations = []
96 95
def styles = []
97 96
for (def corpus : selection) {
98 97

  
98
	def cql_limit_matches = null;
99
	if (cql_limit != null && !cql_limit.getQueryString().equals("\"\"")) {
100
		def limitssubcorpus = corpus.createSubcorpus(cql_limit, corpus.getName().toUpperCase())
101
		cql_limit_matches = limitssubcorpus.getMatches();
102
		limitssubcorpus.delete();
103
	} else {
104
		cql_limit_matches = corpus.getMatches()
105
	}
106
	
99 107
	mainCorpus = corpus.getMainCorpus()
100 108

  
101 109
	def word = mainCorpus.getWordProperty()
......
155 163
		if (allHighlightedUnits != null && allHighlightedUnits.containsKey(schema)) selectedAndHighlightedUnits.addAll(allHighlightedUnits[schema])
156 164

  
157 165
		if (cql_limit_matches != null) {
158
			if (debug) println "corpus matches: "+parent.getMatches()
166
			if (debug) println "corpus matches: "+corpus.getMatches()
159 167
			if (debug) println "filter cql_limit_matches=${cql_limit_matches} with "+selectedAndHighlightedUnits.size()+" units."
160 168
			selectedAndHighlightedUnits = AnalecUtils.filterUniteByInclusion(debug, selectedAndHighlightedUnits, cql_limit_matches, strict_inclusion, position_in_matches)
161 169
			if (debug) println "selectedAndHighlightedUnits=${selectedAndHighlightedUnits.size()}"
......
192 200
		informations << unitsinformations
193 201
		styles << unitsstyles
194 202
	}
203
	
204
	try {
205
		def struct = corpus.getStructuralUnit(struct_name);
206
		def struct_p = null;
207
		if (struct != null) {
208
			struct_p = struct.getProperty(struct_prop)
209
		}
210
		
211
		Progression progression = new Progression(corpus);
212
		progression.setParameters(queries,
213
				struct, struct_p,	".*",
214
				cummulative, line_width, false, bande_width)
215
	
216
		progression.setQueryResults(queryResults); // new
217
		progression.setParameter(ChartsEnginePreferences.SHOW_LEGEND, show_legend);
218
		progression.setParameter(ChartsEnginePreferences.SHOW_TITLE, show_title);
219
		
220
		progression.compute()
221
		if (!progression.stepStructuralUnits() || monitor.isCanceled())	return
222
			monitor.worked(20)
223
		if (!progression.stepFinalize() || monitor.isCanceled()) return
224
			monitor.worked(20)
225
	
226
		monitor.syncExec(new Runnable() {
227
					@Override
228
					public void run() {
229
						try {
230
							//def charteditorpart = org.txm.chartsengine.rcp.SWTChartsComponentsProvider.openEditor(Application.swtComponentProvider.createProgressionChartEditorPart(IImageKeys.getImage(IImageKeys.ACTION_PROGRESSION), progression, progression.isMonochrome(), progression.isMonostyle(), progression.isDoCumulative()))
231
							def charteditorpart = org.txm.chartsengine.rcp.editors.ChartEditor.openEditor(progression);
232
//							JFreeChart chart = charteditorpart.getChart()
233
//							def plot = chart.getXYPlot()
234
//	
235
//							ProgressionItemSelectionRenderer renderer = plot.getRenderer();
236
//							//renderer.setBaseItemLabelsVisible(true)
237
//							//renderer.setBaseLinesVisible(false)
238
//							//renderer.setBaseSeriesVisible(SchemasProgressionMacro.this.show_lines, true);
239
//							//renderer.setItemLabelsVisible(true)
240
//							//renderer.setLinesVisible(false)
241
//							renderer.setAdditionalLabelInformation(informations)
242
//							renderer.setAdditionalShapeScales(styles)
243
//							chart.getLegend().setVisible(SchemasProgressionMacro.this.show_legend)
244
//							chart.getTitle().setVisible(SchemasProgressionMacro.this.show_title)
245
	
246
						} catch(Exception e) {e.printStackTrace()}
247
					}
248
				})
249
	
250
	} catch(Exception e) {
251
		e.printStackTrace()
252
		return false
253
	}
195 254
}
196 255

  
197 256
//println ""+queries.size()+" selected schemas: "+queries
198 257

  
199
def corpus = parent
200
try {
201
	def struct = corpus.getStructuralUnit(struct_name);
202
	def struct_p = null;
203
	if (struct != null) {
204
		struct_p = struct.getProperty(struct_prop)
205
	}
206
	
207
	Progression progression = new Progression(corpus);
208
	progression.setParameters(queries,
209
			struct, struct_p,	".*",
210
			cummulative, line_width, false, bande_width)
211

  
212
	progression.setQueryResults(queryResults); // new
213
	progression.compute()
214
	if (!progression.stepStructuralUnits() || monitor.isCanceled())	return
215
		monitor.worked(20)
216
	if (!progression.stepFinalize() || monitor.isCanceled()) return
217
		monitor.worked(20)
218

  
219
	monitor.syncExec(new Runnable() {
220
				@Override
221
				public void run() {
222
					try {
223
						def charteditorpart = SWTChartsComponentProvider.openEditor(Application.swtComponentProvider.createProgressionChartEditorPart(IImageKeys.getImage(IImageKeys.ACTION_PROGRESSION), progression, progression.isMonochrome(), progression.isMonostyle(), progression.isDoCumulative()))
224
						JFreeChart chart = charteditorpart.getChart()
225
						def plot = chart.getXYPlot()
226

  
227
						ProgressionItemSelectionRenderer renderer = plot.getRenderer();
228
						//renderer.setBaseItemLabelsVisible(true)
229
						//renderer.setBaseLinesVisible(false)
230
						//renderer.setBaseSeriesVisible(SchemasProgressionMacro.this.show_lines, true);
231
						//renderer.setItemLabelsVisible(true)
232
						//renderer.setLinesVisible(false)
233
						renderer.setAdditionalLabelInformation(informations)
234
						renderer.setAdditionalShapeScales(styles)
235
						chart.getLegend().setVisible(SchemasProgressionMacro.this.show_legend)
236
						chart.getTitle().setVisible(SchemasProgressionMacro.this.show_title)
237

  
238
					} catch(Exception e) {e.printStackTrace()}
239
				}
240
			})
241

  
242
} catch(Exception e) {
243
	e.printStackTrace()
244
	return false
245
}

Also available in: Unified diff